Thanks for the reply. I tested the Arduino sketch on the Uno and the Leonardo using the serial monitor tool in the Arduino IDE, using a simple Processing sketch, and using a terminal emulator I have (I am using Windows 7).
With the Arduino, all works as expected. Receive an 'n', turn on the LED, receive an 'f', turn off the LED. Add one to whatever was received and send back. The Arduino serial monitor works, Processing works, and the terminal emulator works.
With the Leonardo, the Leonardo receives the serial data just fine and controls the LED. However, only the serial monitor of the Arduino IDE receives the data sent back from the Leonardo. Processing and the terminal emulator do not.
Here is the full code for the simple Arduino test sketch:
byte bytSerialReceived = 0; // Byte received from the serial port
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Set the LED pin as output
digitalWrite(ledPin, LOW); // Initialize the LED to off
}
void loop() {
// Using serial port bytes to control the mouse
if (Serial.available() > 0)
{
bytSerialReceived = Serial.read(); // Get the byte from the serial port
if(bytSerialReceived == 'n') digitalWrite(ledPin, HIGH); // If the byte received is an n, turn on the led
if(bytSerialReceived == 'f') digitalWrite(ledPin, LOW); // If the byte received is an f, turn off the led
Serial.write(bytSerialReceived + 1); // Echo back the byte + 1
}
}
Here's the Processing sketch:
import processing.serial.*; // Import the serial library
Serial myPort; // The serial port
int intvalue = 0; // The fill value for the rectangle on screen
char chSerial = 'f'; // The character to send via serial
byte bytReceiveByte = 0; // Holds byte received from serial
void setup()
{
size(300,300);
println(Serial.list()); // List all the available serial ports
myPort = new Serial(this, Serial.list()[0], 9600); // Define the serial port we are using
}
void draw()
{
fill(intvalue); // Set the fill value for the rect
rect(25, 25, 50, 50); // Draw the rect
if (myPort.available() > 0) // If there serial data is available
{
bytReceiveByte = byte(myPort.read()); // Read the byte
println(char(bytReceiveByte)); // Print the byte
}
}
// Process mouse click--toggle the fill value and the character to send
void mouseClicked()
{
if(intvalue == 0)
{
intvalue = 255; // Set the fill to white (on)
chSerial = 'n'; // Set the character to the on value
}
else
{
intvalue = 0; // Set the fill to black (off)
chSerial = 'f'; // Set the character to the off value
}
myPort.write(chSerial); // Send the character
}
Any assistance in understanding why the Leonardo's sent data isn't received would be greatly appreciated.
Thanks!