Translate

vineri, 29 decembrie 2023

how build a assembly compiler for atmega328 in javascript

 I build here an assembly compiler for atmega328 in javascript https://www.costycnc.it/avr-hex-uploader/

Buid an html document with a textarea box and a js script to read textarea box :

<html>

<body>

<textarea id="code" cols="50" rows="20"> </textarea>

<button onclick="compile();">Compile</button>

<script>

         // for verify https://regex101.com/

var regex=/^[\t ]*(?:\.def\s+(\w+),(\w+)|\.org\s+(\d+)|(\w+):)?/;

                  //this regex if  ".def PINB1,1" return [1]="PINB1",  [2]="1"
                  //this regex if  ".org 00" return [3]="00"
                  //this regex if  ":abc" return [4]="abc"

function compile(){

         var input=document.getElementById("code").value;

         var lines = input.split('\n'); 

          for (var i = 0, l = lines.length; i < l; i++) {  

                       var match = regex.exec(lines[i]); 

  console.log("param1:", match[1]);

 console.log("param2:",match[2]);   

 console.log("param3:",match[3]);   

  console.log("param4:", match[4]);   

}

                 }

 

</script>

</body>

</html>

marți, 31 octombrie 2023

RC car toy TX2/RX2 with arduino | costycnc tx rx




https://forum.arduino.cc/index.php?topic=171238.0

rc_car1 I put D2 signal to ground and working good

               upload to arduino rc_car1.ino
               welding wire from arduino to rc car (ground,power and D2) same as rc_car1.jpg photo
               send command letter under serial ... the car need to rispond with moving
               
               a Forward 
               b Forward Turbo 
               c Forward & Left 
               d Forward & Right
               e Backward
               f Backward & Right
               g Backward & Left
               h Left
               i Right

 


Source https://github.com/costycnc/costycnc-toy-rc-car-arduino-ide/

 /*Data Format

W2 W2 W2 W2 (n) x W1 W2 W2 W2 W2 (n) x W1 W2 W2 W2 W2

Number of Function Codes (n) W1 Function Key Decode Result

4 End Code

10 Forward Forward

16 Forward & Turbo Forward

22 Turbo Turbo

28 Turbo & Forward & Left Forward & Left

34 Turbo & Forward & Right Forward & Right

40 Backward Backward

46 Backward & Right Backward & Right

52 Backward & Left Backward & Left

58 Left Left

64 Right Right

*/


void setup()

{

 pinMode(2, OUTPUT);

}


void loop()

{

   delay(1000); 

    for(int i=0; i<=30; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle 

 {

 for(int i=0; i<=3; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle 

 {

   digitalWrite(2, HIGH);

   delayMicroseconds(1500);


   digitalWrite(2, LOW);

   delayMicroseconds(500);

 }

 for(int i=0; i<=9; i++) // This makes the car go "forward" 10 W1 pulses 500Mhz 50% duty cycle

 {

   digitalWrite(2, HIGH);

   delayMicroseconds(500);


   digitalWrite(2, LOW);

   delayMicroseconds(500);

 }

}


 delay(1000); 

    for(int i=0; i<=30; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle 

 {

 for(int i=0; i<=3; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle 

 {

   digitalWrite(2, HIGH);

   delayMicroseconds(1500);


   digitalWrite(2, LOW);

   delayMicroseconds(500);

 }

 for(int i=0; i<=39; i++) // This makes the car go "forward" 10 W1 pulses 500Mhz 50% duty cycle

 {

   digitalWrite(2, HIGH);

   delayMicroseconds(500);


   digitalWrite(2, LOW);

   delayMicroseconds(500);

 }

}

 delay(1000); 

    for(int i=0; i<=30; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle 

 {

 for(int i=0; i<=3; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle 

 {

   digitalWrite(2, HIGH);

   delayMicroseconds(1500);


   digitalWrite(2, LOW);

   delayMicroseconds(500);

 }

 for(int i=0; i<=45; i++) // This makes the car go "forward" 10 W1 pulses 500Mhz 50% duty cycle

 {

   digitalWrite(2, HIGH);

   delayMicroseconds(500);


   digitalWrite(2, LOW);

   delayMicroseconds(500);

 }

}

 delay(1000); 

    for(int i=0; i<=30; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle 

 {

 for(int i=0; i<=3; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle 

 {

   digitalWrite(2, HIGH);

   delayMicroseconds(1500);


   digitalWrite(2, LOW);

   delayMicroseconds(500);

 }

 for(int i=0; i<=63; i++) // This makes the car go "forward" 10 W1 pulses 500Mhz 50% duty cycle

 {

   digitalWrite(2, HIGH);

   delayMicroseconds(500);


   digitalWrite(2, LOW);

   delayMicroseconds(500);

 }

}

}

duminică, 29 octombrie 2023

PROGRAMMING AN ATMEGA328P WITHOUT THE ARDUINO IDE

This site https://www.costycnc.it/avr-hex-uploader is make manually by me and not have yet implemented all asm code ... so if want to help me are welcome!

This page was created for upload hex code to arduino nano ( for upload grbl firmware to arduino nano used in my costycnc foam cutter costycnc https://www.costycnc.it) ... but i added some functions (after tons of hours and google search and tests) that permit you not only upload your firmware to arduino but also create your small code in asm , compile it and upload to arduino!

So you can watch this first video tutorial https://youtu.be/0i8CgucF1Bg?si=npn7C0CtkzRj3GIi (is in italian but translated in english too) you will understand purpose of this site. 

In few words ... you can compile asm code and upload to arduino nano only with this page. 

In this mode you have many advantages :

-You can learn the base of microcontroller in generally and specially atmega328 architecture.

-You can learn the base of asm language (many are unknown now even to me!!!)

-You can create in this mode very small code.

-You can see in my tutorials practice example without download hudge programs.

And many other advantages  which do not come to my mind now!







See my channels for anothers videos!

https://www.youtube.com/@bobyca2003





duminică, 10 octombrie 2021

costycnc how inkscape create svg in mm

 My page is www.costycnc.it ... and my id is costycnc ... so ... try on internet costycnc .

I create this page www.costycnc.it/cm8 for transform a image to gcode , i modified potrace https://kilobtye.github.io/potrace/ for transform coordonate to gcode ... practicall all lines that compound svg i transform to gcode ... for example L 10 10 to G01 X10 Y10 (at line 1249)... C 10 10 to G01 X10 X10  (at line 1239)  see here https://www.costycnc.it/potrace/potrace.js.highlight.html#1236

Inkscape create document svg with height and with in mm ... my old transformed potrace to gcode ... create a gcode in mm but svg in pixels ... so now i try to  produce also the svg file in mm not in pixel.

The dpi of my system is 96 (also the inkscape use 96 dpi ) so the old svg produce 378 for 10 mm ... so I did not understand because this 378  ... but here explain better 

https://stackoverflow.com/questions/35517230/lines-look-irregular-in-thickness-when-using-texturebrush

Since the convention is that all monitors have 96 pixels per inch, and by definition 1 inch == 25.4 mm, we have that 0.1 mm == 0.1 mm * 96 (px / inch) * (1 inch / 25.4 mm) == 0.378 pixels (approximately).

so ...here   https://www.costycnc.it/potrace/potrace.highlight.html#155 at line 155 i put 100/378 for result values in mm ... first was 1 and svg measure result was in pixels...

now need to understand better to finished program!