0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« on: October 19, 2010, 11:36:09 pm » |
Hey. I'm currently running this code just to test the NewSoftSerial library. #include <NewSoftSerial.h> NewSoftSerial CheckBinary(0,1);
void setup() { CheckBinary.begin(9600);
}
void loop() { if (CheckBinary.available()) CheckBinary.print(char(CheckBinary.read())); } I put in 12345678, and the last few characters come back corrupted. Any ideas?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #1 on: October 20, 2010, 12:24:07 am » |
I'm currently running this On what processor / board?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« Reply #2 on: October 20, 2010, 12:36:54 am » |
Official Arduino Duemilanove connected by USB cable
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #3 on: October 20, 2010, 02:08:04 am » |
Pin 0 and pin 1 are available through Serial (the hardware supported serial port)
Why are you using NewSoftSerial with these pins?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« Reply #4 on: October 20, 2010, 02:33:15 am » |
As a way to test NewSoftSerial. I've had code connecting two arduinos together, but there was a portion not working - the NewSoftSerial in particular. This code is just to test the functionality. I once read on a post by the author of NewSoftSerial as a way of testing functionality. Serial works perfectly fine. NewSoftSerial doesn't. EDIT: Author states here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1252024653/5#5
|
|
|
|
« Last Edit: October 20, 2010, 02:36:06 am by leelokhin »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #5 on: October 20, 2010, 03:02:20 am » |
Do you need more help?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« Reply #6 on: October 20, 2010, 03:03:32 am » |
Indeed, I have. Pin 8,2,3, and 9 have been tested with a normal operatioin script, but not that particular test script. Rx/Tx's a bit off, always.
I did it by setting an arduino to repeat "CHECK!" very quickily in the setup loop, and trying to receive it on a Software Rx Pin. I get "CHECK!" when I wiggle the jumper about, but when it's stable, nothing.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #7 on: October 20, 2010, 03:23:10 am » |
I get "CHECK!" when I wiggle the jumper about, but when it's stable, nothing. OK. So fix the loose wire.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« Reply #8 on: October 20, 2010, 03:31:33 am » |
I did. Trust me, the wires are completely stable. When I get some movement on the wire, as in it ISN'T completely connected, it transmits.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #9 on: October 20, 2010, 03:39:47 am » |
Which pair of pins are you using for the "CHECK!" test?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« Reply #10 on: October 20, 2010, 03:44:16 am » |
Hardware Serial 0, 1 for the transmitter, so 1 for Tx.
SoftwareSerial, the pins stated above.
I'm reasonably certain it's not the wire - as the Tx LED on the Transmitter Arduino doesn't flash even when the Receiver Arduino says it receives some junk.
|
|
|
|
« Last Edit: October 20, 2010, 03:45:28 am by leelokhin »
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks
|
 |
« Reply #11 on: October 20, 2010, 04:30:54 am » |
Wrote a bit of debug code.
From what I can tell, for future reference purposes, is that NewSoftSerial.read can't be polled too quickily, or else it'll just return -1 if it isn't ready, even at 9600 baud. I added a 12ms delay (Minimum) between each read and it works just fine.
|
|
|
|
« Last Edit: October 20, 2010, 04:53:47 am by leelokhin »
|
Logged
|
|
|
|
|
Austin, TX USA
Offline
God Member
Karma: 3
Posts: 992
Arduino rocks
|
 |
« Reply #12 on: October 20, 2010, 05:45:50 pm » |
From what I can tell, for future reference purposes, is that NewSoftSerial.read can't be polled too quickily, or else it'll just return -1 if it isn't ready, even at 9600 baud. I added a 12ms delay (Minimum) between each read and it works just fine.
Right! 16MHz is pretty fast. If you poll *any* serial port for a character that hasn't arrived yet, you won't get it!  BTW, I don't recommend the technique of using delay() to wait for serial characters. The best technique is to wait until NewSoftSerial::available() returns a non-zero value. Also, if you have one Arduino communicating to another, make sure their Grounds are connected. Mikal
|
|
|
|
« Last Edit: October 20, 2010, 08:20:14 pm by mikalhart »
|
Logged
|
|
|
|
|
|