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
stty -F /dev/ttyACM0 -a
after your own stty command? That could help see some potential config issues. – jfpoilpret Jan 5 '15 at 16:43if(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