Go Down

Topic: simple serial issue (Read 10243 times) previous topic - next topic

loldrup

Hi
I'm connecting my GPS to pin 0 and 1 on my arduino, in the hope of receiving any data from it. The GPS outputs EMEA-data as soon as it is turned on. It's led is turned on, so it has poower,  and I'm running  this code on the arduino:

while (true) {
   Serial.println("true-loop:");
   incomingByte = Serial.read();
   Serial.println(incomingByte);
}

the only output i get is:

true-loop:
-1
true-loop:
-1

etc...

I guess the "-1" means that no bytes were read. I've tried switching around the TX and the RX lines to the GPS, it makes no difference. The GPS runs at 4800bps and the arduino is configured to use 9600, but this shouldn't make  a difference. The GPS should still send something, even though the arduino will interpret it weirdly. I get NOTHING - not even something weird. What can be wrong? The same setup worked fine with a BASIC STAMP.

Jassper

#1
Jan 22, 2009, 06:59 pm Last Edit: Jan 22, 2009, 07:02 pm by Jassper Reason: 1
Quote

The GPS runs at 4800bps and the arduino is configured to use 9600, but this shouldn't make  a difference.


It might matter. A lot of things I have worked with will reject anything that is not the correct baud. If this is the case with the Arduino, then the data will be ignored before ever reaching the serial buffer.

Try matching the baud and make sure your voltage levels are correct. on the TX/RX pin, you may need a TTL to RS232 (Logic level) converter.

pwillard

don't assume that baud rate mismatch will do something... very often a mismatch will result in nothing being displayed.

mem

#3
Jan 22, 2009, 08:14 pm Last Edit: Jan 22, 2009, 08:14 pm by mem Reason: 1
You can avoid those -1 outputs by checking if data is available before trying to read it.


while (true) {
  if(Serial.available() ){
    incomingByte = Serial.read();
    Serial.printlincomingByte);
 }
}

But you will not get anything useful if you don't have the baud rate set correctly.

anachrocomputer

Yes, first thing to do is to set the baud rate to 4800 for the NMEA data.

loldrup

Now the baud rate is correct:
[font=Courier]
while(true) {
 int serialInput;
 Serial.begin(4800);
 serialInput = Serial.read();
 Serial.begin(9600);
 Serial.println("Seria input was:");
 Serial.println(serialInput);
}[/font]

But the output is still always -1

I measured the voltage the GPS receives: its 4,75
Next step will be to hook it up to the Basic Stamp and make it work there, and then transition the RX and TX line to the Arduino, but leave it power fed from the Basic Stamp, to rule out power supply being an issue. But that'll be tomorrow.. I have to go to sleep now.

Jassper

#6
Jan 23, 2009, 02:00 am Last Edit: Jan 23, 2009, 02:02 am by Jassper Reason: 1
You are still setting it to 9600
Take out the second Serial.begin()

Also, that should be in the void setup()

loldrup

#7
Jan 23, 2009, 08:43 am Last Edit: Jan 23, 2009, 08:59 am by loldrup Reason: 1
I set it to 9600 when the communication is intended for my PC. I put it back to 4800 when I take data in from the GPS. The GPS can't receive data, and therefore shouldn't care about the bits floating to it from the 9600baud sentences sent to the PC.
The code is in the [font=Courier]void loop()[/font] method (I'm not sure whether this method will loop all by itself, so I built my own loop ("[font=Courier]while (true)[/font]")

loldrup

And now it got a proper 5.02v power supply. It still doesn't work though. I can't get my Basic Stamp Editor to recognize my BS2pe, so I can't test whether it would work with the basic stamp. It did make it work with the basic stamp this summer though..
crap.

macegr

"Should" and reality are often very different. RS232 is not a multi-drop interface. Pins 0 and 1 are TTL level, not PC standard RS232...is your GPS TTL-serial? If the PC is talking to the Arduino via the USB port, then those pins are under full control of the internal FTDI chip. With the GPS connected to those pins, you would be seeing the data, garbled or not, come into the PC before the Arduino even had a chance to see it. Your while-true loop may be interfering with the Arduino's ability to check the serial buffers (I don't know if that's true, I have little knowledge of how the Arduino handles this).

Just a few of the possible problems here.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

loldrup

The GPS can run of both 12v and 5v. This I found out by experiment. Also, it can communicate with my basic stamp, which is purely TTL. So yes, my GPS is TTL-serial.

I will check your suggestion about Arduino not seeing the signals because of the FTDI "taking over" by listening to the FTDI using windows Hyperterminal (can't do it right now though, as I'm at work..).
It seems implausible though, as that would render the hardware-serial-port of the arduino useless for anything else than PC-communication, and I know other projects has used the serial interface of the arduino to talk with other devices than the PC.

I'll also try to remove the while loop.

darudude

have you tried the Software Serial library for the GPS? This would keep the normal serial for communicating with the PC, so theres no problems on that end and you don't have to kee changing the baud rate.

westfw

Simple thing to try: are you sure you have the right gps wires connected to the right pins?  "tx" and "rx" are ambiguous after all; one devices TX MUST talk to the other devices RX.

loldrup

to macegr:
I tried listening to the COM-port using hyperterminal, but of course the result is the same as when listening to the line via the arduino serial monitor. IE. no extra (garbled) stuff from the GPS were to be found. No matter whether it was the arduino or the FTDI chip that handled the incomming data from the GPS, it would be the PC that received it. And it doesn't.

I also removed my own "while (true)" loop in case it caused problems. It didn't change anything. I also found out that "void loop()" function loops by itself, so no use for my own while loop.

to westfw:
I always try both options, just in case.

I tried the SoftwareSerial. No luck. Then I tried connecting the GPS to the PC. No luck either. I'm starting to suspect that my GPS is somehow defective. Tomorrow I'll try with its original cable, just for a good measurement, but I'm too tired to search for that now.
Sleep well!

macegr

So, not to beat a dead horse, but it sounds really fishy for the GPS to be "both 12V and 5V". Normally a TTL-serial interface won't work at all with equipment expecting 12V RS232 levels. And the fact that you used the Basic Stamp isn't proof you were using TTL...it's not purely TTL. The Basic Stamp has RS232 level-conversion hardware if you're using it with the pins that are also used for downloading the program, which happens if you choose pin 16 in the SERIN and SEROUT commands.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Go Up