I'm attempting to write data over a serial line to the arduino, however I don't want to use the arduino IDE but rather use the command line.

In order to do this I have the following commands:

$stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
$echo s123 > /dev/ttyACM0

The code on the receiving end checks whatever or not the input is s123 and if it is starts blinking. I have tested this using the arduino IDE and it worked, however this did not work.

The sketch looks like this:

    void loop(){
       byte b1,b2,b3,b4; 
               digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
               delay(1000);               // wait for a second
               digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
               delay(1000);               // wait for a second
               digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
               Serial.println("the cow has landed");

    void setup(){ //////////////SETUP////////////////////////

the output of

stty -F /dev/ttyACM0 -a

was :

speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 0; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
ignbrk -brkint -ignpar -parmrk inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl noflsh -xcase -tostop -echoprt -echoctl -echoke

Thank you

  • can you post the sketch? – nkint Jan 5 '15 at 16:31
  • I have added the sketch – Thijser Jan 5 '15 at 16:39
  • Could you post the output of stty -F /dev/ttyACM0 -a after your own stty command? That could help see some potential config issues. – jfpoilpret Jan 5 '15 at 16:43
  • 1
    Your code doesn't seem to have any way of getting back in sync if that is ever lost. And it may be that you inadvertently reset the arduino when you configure/open the serial port. If you start talking too soon thereafter, (as echo would) the first character(s) might be lost while in reset, leaving your sketch and host program out of sync. Try putting a "Hello World" in your setup() – Chris Stratton Jan 5 '15 at 17:34
  • 1
    if(Serial.available()==4) is bad code. Unless there are exactly 4 characters it will do nothing. At the least it should be >=4 but you really need to work out what you want it to do. Even if it worked it would print 1 line then do nothing. – Milliways Jan 5 '15 at 22:45

This was fixed this morning after a reboot and upgrade command, still don't know which one of these fixed it but it seems to work now.

Ah figured it out we were using the 0 and 1 rx gates to communicate over serial rather then usb and as the used power supply turned out to be only 5V rather then 9-12V it didn't quite work as intended.

  • 1
    This is not a solution, as your program remains faulty. At best you are momentarily lucking out - which is actually bad luck, because when a system is faulty, it's more helpful when it will cooperate by failing while you are paying attention to fixing it, and not some other time. – Chris Stratton Jan 6 '15 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.