I'm sorry, let me start again.
I have a Perl script sending integers to the Arduino at half-second intervals:
use Device::SerialPort;
my $port = Device::SerialPort->new("/dev/ttyUSB0");
$port->databits(8);
$port->baudrate(9600);
$port->parity("none");
$port->stopbits(1);
while (1) {
@array = ( 4, 8, 16, 32, 64, 128 );
for $n (0..$#array) {
$port->write("$array[$n]");
print "Sent: $array[$n] \n";
select(undef, undef, undef, .5);
}
}
Then I have the Arduino taking the serial input an assigning it to the PORTD register (with RX and TX masked, of course):
void setup()
{
DDRD = DDRD | B11111100;
Serial.begin(9600);
}
void loop()
{
while (Serial.available() > 0) {
PORTD = Serial.read();
}
}
...but this isn't working.
I'm still new with Arduino, and very new at serial communication. I was trying to get a clue, and several examples seem typical of the "Physical Pixel" example that comes with Arduino:
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
The variable that receives the return value of the Serial.read() function is initialized as an int...
int incomingByte; // a variable to read incoming serial data into
...and seems to be handled like a char...
if (incomingByte == 'H') {
if (incomingByte == 'L') {
(I used the above Perl script to send a capital 'H' or 'L' to the Arduino, and it works fine.)
Anyway, there appears to be a type mismatch in the code.
I looked at the documentation and a dozen other pages to try to get an answer before coming here, but I'm snagged on this point.
What is the paradigm with the Arduino serial?