I am trying to write to Arduino using Perl on MacOSX. It is some really simple stuff, just writing a character to Arduino and it will display what it received on Serial Monitor. Below is the code:
#!/usr/bin/perl
use Device::SerialPort;
my $port = Device::SerialPort->new("/dev/tty.usbmodem621");
$port->databits(8);
$port->baudrate(57600);
$port->parity("none");
$port->stopbits(1);
sleep(1) ;
$port->write("a");
Arduino Code:
int incomingByte;
void setup ()
{
Serial.begin (57600);
}
void loop ()
{
if (Serial.available() > 0)
{
incomingByte = Serial.read();
Serial.println (incomingByte, BIN);
}
}
Every time I run this Perl code I will get some random garbage data first then the character "a" like this:
11111110 (Random)
1100001 ("a")
If I add more characters to be sent out below $port->write("a");, for example sending "b", I only get garbage data in the beginning once.
11111110 (Random)
1100001 ("a")
1100010 ("b")
Even if I comment out $port->write("a"); so nothing is sent over, I still get random garbage data when object was created.
If I change baudrate to 9600, it seems to work. Did I do something wrong? Thank you