I've started work with Arduino Leonardo last week. I realy happy with getting fast results form the Board with out knowing anything about Microcontrollers before. In my first projects i read some measured from a photo sensor and a LED. Its works realy fine ... if i put the data via Keyboard-Simulator (Keyboard.begin) on my Computer. As I want to do it more professional via Serial it fails.
There are two serial ports on the Leonardo, Serial and Serial1. The Serial instance is via the onboard USB-to-serial conversion process. Serial1 is via the RX and TX pins.
If you don't have anything connected to the RX and TX pins, using Serial1 is not going to accomplish anything.
Using Serial.available(), Serial.print(), or Serial.read() without using Serial.begin() is silly.
You should have started with the common Arduino Uno.
The Arduino Leonardo is very specific for USB emulation, and this makes it sometimes not so easy to use.
You are mixing Serial and Serial1. Are you sure you want to do that ? How did you connect everything ?
The default Serial on the Leonardo board is a software simulation for the serial monitor via the USB connector.
The extra Serial1 is the hardware serial port inside the microcontroller (RX,TX) and can be used for anything.
In the sketch you wait for something to be available, but you don't read it.
And if the Leonardo is always sending, I'm having troubles connecting it for the sketch upload.
Your settings are okay, and it should be no problem to use any serial monitor program.
I used the most simple one : http://qst.sourceforge.net/
While I was writing this, PaulS already wrote the same.
In my opinion, the Leonardo is specifically for USB emulation. The Uno is still the most common board to start with.
You test if something is available (in the buffer), but you don't read it. So if some data is in the buffer, it is always available.
You must read the data from the buffer, so the avaible function will return zero if the buffer is empty.
Read about the functions and look at the examples:
The Leonardo requires that DtrEnable be set when opening the serial connection (on the PC end). The Serial Monitor does that. Most PC applications do not. There was a discussion on why GoBetwino failed to work with a Leonardo, and this missing attribute was determined to be the culprit.
I'm guessing that your C# application doesn't use DtrEnable, and that the other terminal app doesn't either.
PaulS:
The Leonardo requires that DtrEnable be set when opening the serial connection (on the PC end). The Serial Monitor does that. Most PC applications do not. There was a discussion on why GoBetwino failed to work with a Leonardo, and this missing attribute was determined to be the culprit.
I'm guessing that your C# application doesn't use DtrEnable, and that the other terminal app doesn't either.
You can solve the DTR Problem by editing "Arduino\hardware\arduino\cores\arduino\CDC.cpp.
Just comment if (_usbLineInfo.lineState > 0) { at line 208 and } at line 216.
The following testcode should work out of the box
void setup()
{
Serial.begin(115200); //This pipes to the serial monitor
while(!Serial);
Serial1.begin(115200); //This is the UART, pipes to sensors attached to board
}
void loop()
{
if( Serial.available() )
{
int inByte = Serial.read();
Serial1.write( inByte );
}
if( Serial1.available() )
{
int inByte = Serial1.read();
Serial.write( inByte );
}
}
There are two serial ports on the Leonardo, Serial and Serial1. The Serial instance is via the onboard USB-to-serial conversion process. Serial1 is via the RX and TX pins.
Is this also true on the Arduino Micro? I don't know why I never noticed this on any description, but it could solve all my problems!
Edman84:
You can solve the DTR Problem by editing "Arduino\hardware\arduino\cores\arduino\CDC.cpp.
Just comment if (_usbLineInfo.lineState > 0) { at line 208 and } at line 216.
The following testcode should work out of the box
void setup()
{
Serial.begin(115200); //This pipes to the serial monitor
while(!Serial);
Serial1.begin(115200); //This is the UART, pipes to sensors attached to board
}
OH MY GOD! TKX SO MUCH! I was searching for solution today and i was getting sad cause i can't connect my arduino micro in my external serial monitor. Your tip solved my problem! tks again!!!
Edman84:
You can solve the DTR Problem by editing "Arduino\hardware\arduino\cores\arduino\CDC.cpp.
Just comment if (_usbLineInfo.lineState > 0) { at line 208 and } at line 216.
The following testcode should work out of the box
void setup()
{
Serial.begin(115200); //This pipes to the serial monitor
while(!Serial);
Serial1.begin(115200); //This is the UART, pipes to sensors attached to board
}
Edman84:
You can solve the DTR Problem by editing "Arduino\hardware\arduino\cores\arduino\CDC.cpp.
Just comment
if (_usbLineInfo.lineState > 0) {
at line 208 and
}
at line 216.
The following testcode should work out of the box
void setup()
{
Serial.begin(115200); //This pipes to the serial monitor
while(!Serial);
Serial1.begin(115200); //This is the UART, pipes to sensors attached to board
}
Thank u very much for the solution. Almost 5 years gone but still effective. Ive been googling around for a few days and couldnt have found any way to solve that problem until i encounter your post. :))