Go Down

Topic: NewSoftSerial Rx Corrupt (Read 1 time) previous topic - next topic

Zephyrs

Hey.

I'm currently running this code just to test the NewSoftSerial library.

Code: [Select]
#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?

Coding Badly

Quote
I'm currently running this

On what processor / board?

Zephyrs

Official Arduino Duemilanove connected by USB cable

Coding Badly


Pin 0 and pin 1 are available through Serial (the hardware supported serial port)

Why are you using NewSoftSerial with these pins?

Zephyrs

#4
Oct 20, 2010, 09:33 am Last Edit: Oct 20, 2010, 09:36 am by leelokhin Reason: 1
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

Coding Badly


Zephyrs

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.

Coding Badly

Quote
I get "CHECK!" when I wiggle the jumper about, but when it's stable, nothing.

OK.  So fix the loose wire.

Zephyrs

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.

Coding Badly


Which pair of pins are you using for the "CHECK!" test?

Zephyrs

#10
Oct 20, 2010, 10:44 am Last Edit: Oct 20, 2010, 10:45 am by leelokhin Reason: 1
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.

Zephyrs

#11
Oct 20, 2010, 11:30 am Last Edit: Oct 20, 2010, 11:53 am by leelokhin Reason: 1
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.


mikalhart

#12
Oct 21, 2010, 12:45 am Last Edit: Oct 21, 2010, 03:20 am by mikalhart Reason: 1
Quote
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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy