Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an arduino setup that turns on a light when it receives a 1, and turns off a light when it receives a 0. I don't think there is anything wrong with the code. I can send the Arduino a 1 with echo 1 > /dev/ttyACM0 and the light blinks, which confused me. Then I sent it 'h' and it did the same thing. I even opened a screen with screen /dev/ttyACM0 and typed in 1, and it blinked. I would think echoing 1 would echo 1. I have also used the following command stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts Am I doing anything wrong here? If you need any more information at all, just ask.

Arduino code (I don't think this is flawed):

void setup() {
Serial.begin(9600);
//set the LED pin to OUTPUT
pinMode(13, OUTPUT);
}

void loop() {
//wait until the serial connection is open
while (Serial.available() ==0);

//read from the serial connection; the - '0' is to cast the values as the int and not the ASCII code
int val = Serial.read() - '0';

//print to the console for testing
Serial.println(val);

//if we've recieved a '1', turn on the LED and print a message
if(val==1){
Serial.println("Received a 1");
digitalWrite(13, HIGH);
}
//if we've recieved a '0', turn off the LED and print a message
if(val==0){
Serial.println("Received a 0");
digitalWrite(13, LOW);
}
}
share|improve this question
2  
This might fall outside of the scope of Superuser so please be aware that this might not be answered. I know the Ardunio beta was closed due to inactivity so I would consider getting this moved to Stack Overflow and reviewing How to Ask –  50-3 Sep 8 '13 at 20:36
    
Its not really a coding question. Its more of a commands question, which I might not have asked clearly. The only reason I posted the arduino code was for someone that was interested in what the arduino was doing when I sent it the 1. I fixed it anyway, I'm going to post an answer here in a second. –  Derp Sep 8 '13 at 23:56
    
If you run it within the Arduino program and interact at the built-in serial console, does it work, and print out your "Received a 1" messages? I would be suspicious first of the method of sending the serial signal. (I've also seen the Serial.available test written as <= 0 instead of == 0) –  beroe Sep 9 '13 at 18:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.