Arduino USB 2.2 (nkc) and Microsoft Vista
I changed the com port for the Arduino in Vista to Com2
The Diecimila User LED on pin 13 blinks on for 2 seconds when a character is received.
Arduino Code:
void setup() {
Serial.begin(9600); // open serial
pinMode(13, OUTPUT);
}
void loop() {
if( Serial.available()) {
delay(100);
char foo = Serial.read();
delay (2000);
Serial.println("Got Serial: ");
Serial.println(foo, BYTE);
digitalWrite(13, HIGH);
delay (2000);
digitalWrite(13, LOW);
}
}
Perl Code:
# read/write serial port win32
use strict;
use warnings;
$| = 1;
my $count;
my $result;
use Win32::SerialPort;
my $port = Win32::SerialPort->new('COM2');
if( ! defined($port) ) {
die("Can't open COM2: $^E\n");
}
$port->initialize();
$port->baudrate(9600);
$port->parity('none');
$port->databits(
;$port->stopbits(1);
$port->write_settings();
# send the char "Z"
$count = $port->write("Z");
print "count = $count\n";
# receive
($count, $result) = $port->read(15);
print "count = $count\n";
print "$result\n";
$port->close();
exit(0);
I run the perl code in an Administrator window to bypass UAC on Vista.
(addendum) The above works great until you take the power off the Arduino by unplugging the USB cable. When you plug it back up, the perl shows sending a character, but returns 0 (no echo). Using the Putty serial terminal program the Arduino code works properly. The Arduino code also works properly with the serial monitor in the Arduino editor. What is different about accessing the serial port with perl from the command line?
