Hi, folks!
I've been searching and reading and racking my brain, but this is just eating my lunch! It's vitally important that I learn this. It seems like one of those things you easily over-think, then it comes to you in a flash of insight.
I need to communicate with my Arduino microcontroller board via the USB serial connection. I have gotten things to work, kinda, but it's acting weird.
This is the Perl side:
use Win32::SerialPort;
$|=1;
my $port = Win32::SerialPort->new("COM4");
$port->databits(8);
$port->baudrate(19200);
$port->parity("none");
$port->stopbits(1);
$port->lookclear();
while (1) {
for $r (0..9) {
print $r . "\n";
$port->write($r."\n");
for (0..1000000){}
}
}
I know the second 'for' is vulgar, but I didn't want to mess with one second intervals.
This is the Arduino side:
int incomingByte;
void
setup ()
{
beginSerial (19200);
}
void
loop ()
{
if (Serial.available () > 0) {
incomingByte = Serial.read ();
analogWrite(9,int(incomingByte));
}
}
An LED on pin 9 just flickers, where is should get steadily bright, suddenly dark, then steadily bright, over and over.
I got this example to work:
...but when I tried to modify it, I only got gobbledygook back out. It's almost like the data types are getting confused, or something. I think the two might be related, but it defies my current understanding.
Another problem, is how do you poll the serial port in Perl without getting locked down until the buffer fills up?
Anybody have any experience with this? I can't do this part on my own without a good book in front of me.
I've been searching and reading and racking my brain, but this is just eating my lunch! It's vitally important that I learn this. It seems like one of those things you easily over-think, then it comes to you in a flash of insight.
I need to communicate with my Arduino microcontroller board via the USB serial connection. I have gotten things to work, kinda, but it's acting weird.
This is the Perl side:
use Win32::SerialPort;
$|=1;
my $port = Win32::SerialPort->new("COM4");
$port->databits(8);
$port->baudrate(19200);
$port->parity("none");
$port->stopbits(1);
$port->lookclear();
while (1) {
for $r (0..9) {
print $r . "\n";
$port->write($r."\n");
for (0..1000000){}
}
}
I know the second 'for' is vulgar, but I didn't want to mess with one second intervals.
This is the Arduino side:
int incomingByte;
void
setup ()
{
beginSerial (19200);
}
void
loop ()
{
if (Serial.available () > 0) {
incomingByte = Serial.read ();
analogWrite(9,int(incomingByte));
}
}
An LED on pin 9 just flickers, where is should get steadily bright, suddenly dark, then steadily bright, over and over.
I got this example to work:
...but when I tried to modify it, I only got gobbledygook back out. It's almost like the data types are getting confused, or something. I think the two might be related, but it defies my current understanding.
Another problem, is how do you poll the serial port in Perl without getting locked down until the buffer fills up?
Anybody have any experience with this? I can't do this part on my own without a good book in front of me.