Weird behavior on changing pin and serial comm

Hi,

I have had problems with my Arduino Duemilanove; on my devel machine (running Debian sid) the sketch does exactly what it should do, i.e. continuously flash LEDs when a byte with value one is read from serial, and then stop flashing when a byte with a value other than one is read. But when I deploy this at my server (running Debian Lenny (i confirmed with another Lenny machine)), the device starts to behave badly --- when a byte, any byte, is read, the LEDs either a) just do a quick flash and then turn off again, or b) lights up (not flashing, not turning off), until another byte is read. I also tested on another Sid machine, and that too worked as expected. That is, it worked, until I recently rebooted (new kernel (2.6.32) etc). However, the devel machine still works, running the same kernel as the other Sid machine. I use the Perl module Device::SerialPort for serial communication, but I have also tried applications written in C etc.

A basic case that triggers this problem (note that this is just a simple program lighting one LED up on a byte with value one, and turning it off with a byte with another value):

int on;

void setup() {
      Serial.begin(9600);
      pinMode(13, OUTPUT);
      on = 1;
}

void loop() {
      byte in;
      
      if(Serial.available()) {
            in = Serial.read();
            if(on == (in &= 1)) {
                  on = in;
                  digitalWrite(13, on ? HIGH : LOW);
            }
      }
}

My question is: does anybody recognize this problem? And if so, does anybody have a workaround or fix for it?

if(hl = (in &= 1))

Where is hl declared? Shouldn't hl be followed by ==?

Huh, embarassing! The code is copied by hand, since the devel machine didn't have network when i wrote the post... The variable "hl" should be "on" is the same and, hl is followed by ==. (i.e the code is correct in the sketch). I appologize! Editing original post....

I'd add some Serial.print statements to echo the input. May be a matter of not getting the input that is expected. Why? I don't know.

Does it behave strangely if the serial data comes from the Serial Monitor window?

I'd add some Serial.print statements to echo the input. May be a matter of not getting the input that is expected. Why? I don't know.

I could try this, but some symptoms I have (the constant light in the described sketch) shouldn't happen if it was just a problem in bad input data...

Does it behave strangely if the serial data comes from the Serial Monitor window?

I don't have the arduino environment installed on any host i experience problems with, so I don't know. Could be worth a try, though...

but some symptoms I have (the constant light in the described sketch) shouldn't happen if it was just a problem in bad input data

You want the LED on when there is a one on the serial port and off otherwise. If you don't know what is on the serial port, I don't see how you can tell if the program is working correctly, or not.

Hum, interesting development. I installed the ardunio environment on the other Sid host, and compiled and uploaded the same sketch. Then it worked on that host and not the development machine. Then i started the Arduino environment on the dev machine, and opened the serial monitor. Now it works on the dev machine as well! Anybody have any explanation for this? :slight_smile: It doesn't feel like it should be necessary to start the Arduino IDE everytime you reboot the machine (and not to mention the servers were it would be impossible to run it).

You want the LED on when there is a one on the serial port and off otherwise. If you don't know what is on the serial port, I don't see how you can tell if the program is working correctly, or not.

Well, in the sketch i described (not the one I posted the code for) I knew that a constant light on all LEDs were never a valid state, thus the bad input data would be irrelevant.