Offline
Newbie
Karma: 0
Posts: 16
|
 |
« on: February 25, 2013, 02:29:43 am » |
I having troubles with Arduino Leonardo when reading from Serial1 Here is my super simple code: int incomingByte = 0;
void setup(){ Serial1.begin(57600); }
void loop() { // send data only when you receive data: while (Serial1.available()) { Serial.print("Available"); if (Serial1.available() > 0) { // read the incoming byte: incomingByte = Serial1.read(); // say what you got: Serial.print("I received: "); Serial.println(incomingByte, DEC); } } }
When I write from PC I dont see any activity on FTDI LEDs (green, yellow) Interesting thing is: when I skip Serial1.begin(57600); I see blinking light (yellow) on FTDI board conected to PIN 0/1, when I send data from PC But when I run: int incomingByte = 0;
void setup(){ Serial1.begin(57600); }
void loop() { Serial1.println(100,DEC); // send data only when you receive data: while (Serial1.available()) { Serial.print("Available"); if (Serial1.available() > 0) { // read the incoming byte: incomingByte = Serial1.read(); // say what you got: Serial.print("I received: "); Serial.println(incomingByte, DEC); } } }
I see green light on FTDI working all the time, and when I write on other side (PC) yellow LED on FTDI blinks, but I receive some messy data, even if I write same thing all the time.... Please advise. I just want to read and write completely independently.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #1 on: February 25, 2013, 02:34:39 am » |
while (Serial1.available()) { Serial.print("Available"); if (Serial1.available() > 0) { Unless there is serial data, the print() method won't be called. If it is, where could that serial data have gone? Is there ANY reason for the if statement? When I write from PC I dont see any activity on FTDI LEDs (green, yellow) There are no FTDI LEDs on a board with no FTDI chip. What is connected to pins 0 and 1 that you are trying to read from/write to?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 36
Posts: 1253
|
 |
« Reply #2 on: February 25, 2013, 04:06:49 am » |
Ectar, since you use two serial port, you must initialize them both.
I see Serial1.begin(), but you should also do Serial.begin().
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3310
|
 |
« Reply #3 on: February 25, 2013, 06:00:57 am » |
You may have first to describe how you have wired things up. Without any wiring you cannot read or write anything to/from Serial1 because nothing is connected there. So say us how your hardware looks like (you can make a photograph if that's easier for you).
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #4 on: February 25, 2013, 01:04:44 pm » |
Alright, here is the setup - super simple: https://www.dropbox.com/s/bogzbc2v3j91rvl/IMG_00000002.jpgFTDI breakout on picture connected to PC... it has 2 light green, yellow. and acts as serial port. PC is just for debugging, it will be connected to some other devices via SERIALUSB.
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3310
|
 |
« Reply #5 on: February 25, 2013, 01:35:03 pm » |
On your PC you have 2 serial devices then, one is the Leonardo, the other is the FTDI board. What programs on your PC are listening to these serial devices? What baud rates have you configured on these programs? What number of data bits, stop bits and parity?
Do you have the schematics of your FTDI board (just to check that the labels are on the right pins)?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #6 on: February 25, 2013, 06:19:00 pm » |
I use Putty, settings are 57600, 8, 1, N Local echo turned on. FTDI has 5 pins: 3.3V GND RX TX 5V
FTDI RX goes to PIN1 (TX) FTDI TX goes to PIN0 (RX)
Can someone post me an example where I can read data from Serial1 and print it in Serial, Read data from Serial and print it in Serial1 ? This essentially what I need, just need to run some logic in between....
|
|
|
|
« Last Edit: February 25, 2013, 06:24:07 pm by ectar »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #7 on: February 25, 2013, 06:27:02 pm » |
FTDI has 5 pins: Of which you have connected 3. What happens if you connect either 3.3V or 5V to the appropriate pin on the Arduino? Or, have you determined that these are actually output pins? Just curious, as I don't have one of those boards, although I do have a Leonardo that reads perfectly well from an XBee on TX/RX.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #8 on: February 25, 2013, 06:31:15 pm » |
Just connected 5V, doesn't help any way... which is expected.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #9 on: February 25, 2013, 06:50:33 pm » |
There are some inconsistencies in the way RX and TX are sometimes labeled. What happens if you swap the wires, so RX is connected to RX, and TX is connected to TX?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13898
Lua rocks!
|
 |
« Reply #10 on: February 25, 2013, 07:04:07 pm » |
Show us your sketch where you initialize both serial ports.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #11 on: February 25, 2013, 07:40:08 pm » |
Sure, here is my current sketch: int incomingByte = 0;
void setup(){ Serial1.begin(57600); Serial.begin(57600); }
void loop() { //Serial1.println(100,DEC); // send data only when you receive data: while (Serial1.available()) { Serial.print("Available"); if (Serial1.available() > 0) { // read the incoming byte: incomingByte = Serial1.read(); // say what you got: Serial.print("I received: "); Serial.println(incomingByte, DEC); } } } Swapping RX-TX on Leonardo (0<->1) doesn't help But when I detach RX-TX and send characters over to COM9 (FTDI) I see it blinks, if I attach them to Leonardo, and reboot, nothing blinks when I send characters.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13898
Lua rocks!
|
 |
« Reply #12 on: February 25, 2013, 07:44:18 pm » |
Serial.begin(57600);
On the Leonardo you have to wait for Serial to become active: Serial.begin(57600); while (!Serial) { }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #13 on: February 25, 2013, 07:58:56 pm » |
Tried, still doesn't work here is my sketch: int incomingByte = 0;
void setup(){ Serial1.begin(57600); Serial.begin(57600); while (!Serial1) { } }
void loop() { //Serial1.println(100,DEC); // send data only when you receive data: while (Serial1.available()) { Serial.print("Available"); if (Serial1.available() > 0) { // read the incoming byte: incomingByte = Serial1.read(); // say what you got: Serial.print("I received: "); Serial.println(incomingByte, DEC); } } }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13898
Lua rocks!
|
 |
« Reply #14 on: February 25, 2013, 08:09:55 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
|