Problems in serial communication

Hi!

I've hacked togehter a application to turn on/off a LED (pin 13) on a Arduino Duelmilanove, by sending it serial commands from the host. On the machine i used to develop it on (debian gnu/linux sid) it works great. Moving it to one of my other hosts (i've tried two, both running lenny) the LED only flashes, regardless of what I send. Same client program.

int in;

void setup()
{
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);
}

void loop()
{
  if(Serial.available()) {
    in = Serial.read();
    if(in) {
      digitalWrite(13, HIGH);
    } else {
      digitalWrite(13, LOW);
    }
  }
}

This trivial Perl script works on my laptop (sid), but not on lenny:

#!/usr/bin/perl
use Device::SerialPort;

my $port = Device::SerialPort->new("/dev/ttyUSB0");
$port->baudrate(9600);
$port->write("\x1");

I've also tried a simple C program with same results --- working on the laptop, failing on the servers.

Needless to say, I'm really new to this :-), so probably some basic err. Didn't find anything in the troubleshooting documents though.

Is /dev/ttyUSB0 being used on the server for some other purpose?

No... And the arduino board does respond when sending data, but not in the indented way (just a short flash).

So, why don't use use SoftSerial to create another serial connection, and echo the data read in to the Serial Monitor window, to see what you're reading.

I'm guessing that you're receiving more than you think you are, and that's causing the LED to turned on and right back off.

You could add a delay after the digitalWrites to see if that's what's happening, too.

Knowing what is being read will go a long ways towards explaining why you have a problem, and what it is.

Thanks for your suggestions. I haven't got to reading from the serial device on the host, but tried the delay() --- on the laptop it works, on the server it still only flashes. I'll try reading also..