Pages: [1]   Go Down
Author Topic: NewSoftSerial Rx Corrupt  (Read 1471 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey.

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

Code:
#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 Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm currently running this
On what processor / board?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Official Arduino Duemilanove connected by USB cable
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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 Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Do you need more help?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I get "CHECK!" when I wiggle the jumper about, but when it's stable, nothing.
OK.  So fix the loose wire.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
God Member
*****
Karma: 5
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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! smiley

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

Pages: [1]   Go Up
Jump to: