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(){
if(Serial.available()==4){
byte b1,b2,b3,b4;
b1=Serial.read();
b2=Serial.read();
b3=Serial.read();
b4=Serial.read();
if(b1=='s'){
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////////////////////////
Serial.begin(9600);
}
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
1 Answer 1
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.
-
1This 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– Chris Stratton2015年01月06日 16:08:52 +00:00Commented Jan 6, 2015 at 16:08
stty -F /dev/ttyACM0 -a
after your own stty command? That could help see some potential config issues.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.