Pages: [1]   Go Down
Author Topic: Problem reading serial data  (Read 1052 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I'd like to build a device wit Arduino that reads data from a serial TomTom GPS and, managing string, displays some informations on a LCD.
As a first step I've tried to connect Arduino an the GPS device in order to see if the strings where read correctly. The GPS display sends strings at 4800 baud and I've tested it with a pc and a serial connection and everything was ok. When I've connected it to Arduino I've put this circuit between the gps and the arduino:

My idea to check the data strings was to read from the device and to send it to the "serial monitor" and I've used this code:

Code:
#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3
#define ledPin 13

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;

void setup()  {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  Serial.begin(9600);
  
}

void loop() {
  // listen for new serial coming in:
  char someChar = mySerial.read();
  // print out the character:
  mySerial.print(someChar);
  Serial.print(someChar);
  // toggle an LED just so you see the thing's alive.  
  // this LED will go on with every OTHER character received:
  toggle(13);

}


void toggle(int pinNum) {
  // set the LED pin using the pinState variable:
  digitalWrite(pinNum, pinState);
  // if pinState = 0, set it to 1, and vice versa:
  pinState = !pinState;
}

some data arrives to the monitor, but caracters are "strange"!!
Where am I wrong?

Thanks in advance!

Alex
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 638
Posts: 50319
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to post a link to your GPS. If the GPS serial output is TTL level that you are treating as RS232 level (using the MAX232 chip), that would account for the strange characters.

SoftwareSerial is obsolete. Use NewSoftSerial, instead. NewSoftSerial has an option to invert the incoming serial data. That seems to be required for some GPSs.

If SoftwareSerial is managing the specified tx and rx pins, you don't need to have pinMode statements for them.

SoftwareSerial does not have a method that tells you whether there is serial data to read, or not. NewSoftSerial does. Trying to read serial data, when none is available, will get a -1. Printing that will show  y with 2 dots above it. Is that the "strange" data you are seeing?

More details about your specific problem, including sample output, would be helpful.
Logged

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

Hi and thanks for the reply
The gps is this:

When I connect it to a serial port on the pc I read data perfectly!
Do I need Max232 or not?
Tonight I'll try newsoftserial and keep you updated

Bye!
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8601
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The gps is this
Sorry but I doubt anyone is any wiser, all we see is a silver box and some wires.

____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Adelaide
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

True; the picture does not help much but the statement that it works fine with a PC serial port means that it is probably putting out RS232 levels.
Therefore you will need the MAX232 level converter chip or something similar to get these signals into the Arduino.

The circuit you supplied for your MAX232 implementation is OK.
I would look to the pin mode statements in your code, as pointed out elsewhere if you are using softserial this is already taken care of.

Cheers

Peter B.
Logged

peter_b

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1658
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The GPS would not be TTL level... so you would want to use the level converter.

Make sure you are not trying to connect Transmit on the GPS to Transmit on the Arduino (same for Receive).  You probably need to cross those signals over between the devices.

« Last Edit: October 28, 2010, 06:18:19 am by pwillard » Logged

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

Thank you very much for answers.
Tonight my whole evening will be dedicated to test everything again!

So, it's clear that if the gps works with the pc serial port it needs max232 to be connected to Arduino.

this is the result of a connection gps-pc:

and it's what I expect from the connection with Arduino

When (with max232 in the middle) I've tried to read data and see them in the monitor the result (tonight I'll post it) was "similar" to the right one (I could recognise some carachter, the lenght of the lines seemed to be correct, ecc..).
I hope that the new software layer (newsoftserial) will give me the good result.
Then next step will be string manipulation"!
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Especially as you said...

Quote
the lenght of the lines seemed to be correct

I wonder if your data is inverted?

In other words, what you think is binary 00001100 is 11110011.... quite easy to get this inversion from various sources.

Between reading each byte and displaying in, do a bitwise NOT.

You may also be encountering problems because you and your Arduino are not on the same page re- the "type" (in the narrow sense) of your data.

Post your code. (Sorry if you have done... doing this in haste.) People will soon be able to tell you if my ideas were relevant.


Logged

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

I've replaced the library with newsoftserial and it perfectly works!
thanks to everyone for support!

just a curiosity: why the max232 works also without capacitors????
Logged

Somewhere in the Sonoran Desert
Offline Offline
Full Member
***
Karma: 1
Posts: 108
"This was not intended to be a factual statement."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
just a curiosity: why the max232 works* also without capacitors????
*for some certain value of 'works.'

I suspect that the signals you are communicating with are not true RS-232 levels. C1 and C2 are external capacitors used for voltage doubling and inversion. I imagine the signal is +5V high 0V low instead of the standard +3V to +15V high and -3V to -15V low. But the reciever is tolerant enough to accept these, especially at such a slow baud rate. For example the MAX232A is typically <1.3V is low and >1.8 is high.

I wouldn't expect it to work with all recievers nor would it be especially tolerant of noise.

Hook an oscope to the signals and let us know what you find.
Logged

Pages: [1]   Go Up
Jump to: