Go Down

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

loldrup

to macegr:
Are you sure on that one? I have a RS232 converter myself, and judging by the size of the RS232 conversion chip itself, I don't think this functionality can possibly be embedded on the Basic Stamp. Also, on my Basic Stamp development board, there's a separate RS232-conversion chip right behind the 9-pin RS232-port. This would be redundant if the BS could do the conversion itself.

Will be up and looking for my original GPS cable in just a minute :)

loldrup

My GPS actually WORKS. Now I'm using its original cable, attached to a PC and then using hyperterminal for communication. Loads of NMEA-sentences are comming in.
The original cable is a USB to PS/2-jack converter. The GPS is a little black box with a cable with a PS/2-jack. That is, I don't believe the GPS is using the true PS/2-protocol - it's just using the same jack. If it were using the PS/2-protocol, my Basic Stamp wouldn't have been able to communicate with it using its standard Serial library. Also, In windows XP, the adapter is listed as a "USB-to-serial bridge".

All this doesn't solve my problem though - just puzzles me even more. This really sucks. I hadn't expected serial communication using an arduino to be so impossible.

loldrup

This really keeps puzzling me. This is the code I'm using now:

[font=Courier]#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

SoftwareSerial softSerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 softSerial.begin(4800);
 Serial.begin(4800);
}

void loop() {
 char someChar = softSerial.read();
 char oneMoreChar = Serial.read();
 // print out the character:
 Serial.println("Output: ");
 Serial.println(someChar, DEC);
 Serial.println(oneMoreChar, DEC);
 delay(1000);
}[/font]

As you see I check for input on both the hardware- and the software-serial. I attach the TX line from the GPS to the pins 0,1,2,3  ten seconds at a time. I always get this output:

[font=Courier]Output:
0
-1[/font]

That is, I get "0" from the hardwareserial and "-1" from the softwareserial.

My PC is listening using 4800 baud, so no need for baud-changing all the time.

Jassper

This has already been mentioned but, Sounds to me like your GPS is RS-232 12v, and I believe the Stamps are as well, depending on how old it is.

I just got my Arduino talking to my PC, the Arduino is TTL logic level or 3.3v. The PC expects 12volt levels. I used the ST232 to convert the TTL to RS-232, with out it, my PC shows the same thing you are getting -1 or 0, over and over, or sometimes nothing at all.

Disconnect your com cable and leave the GPS powered. Measure the voltage on the TX pin of the GPS to ground. It's best with a analog meter because depending on how often the GPS sends data the meter will jump around so you might need to put your meter on high hold. Analog meters you can see bounce as data is sent.

Anyways, if you see levels > 5 volts, then you will need to convert TTL/CMOS to RS-232

Fjornir

What GPS are you using? Which pin numbers from the GPS are you connecting to which pins on the arduino? Looking at the code I can see you're a bit confused - the -1 is coming from the hardware serial (connected to your PC) not the software serial. If you used more meaningful variable names you'd probably avoid some confusion.

That said, the -1 is -expected- in this case and mem explained why earlier in the thread. Serial.read() will return -1 unless there is data available on the port. You're not testing to see if there's data before you do your read and since your PC isn't actively sending data you're always going to get a -1 out of it.

Post a photo of the wiring going from your GPS to your arduino - it might offer some clue as to what's going on here. Serial IO is really really easy on the Arduino so you've probably just made a dumb mistake. Happens to all of us.

mrmeval

If the unit needs 232 level data instead of TTL you can find the old schematic of the serial version of the arduino. It works with most modern serial ports.

Since the Arduino has tied up the hardware serial pins consider using the software serial library and picking arbitrary pins.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1196667255

http://www.libelium.com/squidbee/index.php?title=Main_Page

loldrup

to fjornir:
The GPS is a little black box with a cable with a ps/2 jack with four active wires. Two for power and two for communication. I connect the tx and the rx to the pins 0 and 1 on the arduino (in both possible constellations, just to be sure).

I will try to borrow a camera from one of my hallmates and post a picture.

to jassper:
Now I tried putting my rs232 to TTL converter in between. It has a female DB9 port on the 12v side. I put the TX pin from the GPS into pin3 on this DB9 port. TX and RX on the TTL-side went to pin0 and 1 on the arduino. Still no result other than "-1" and "0". Then I tried connecting my arduino to my PC through the rs232 to TTL converter (removing the USB cable going to the arduino and powering arduino through 9v adapter):
With both constellations of TX/RX on the converter to TX/RX on the arduino, I got this message:

[font=Courier]avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51[/font]

Maybe the pins o and 1 on the arduino have been fried?

Fjornir

Who is the manufacturer of the GPS unit and what is the part number?

loldrup

The GPS has the name "GPS-601" (which doesn't really say much) and uses the Cirfstar III chip. It looks very much like this:
http://en.wikipedia.org/wiki/File:GPS_receiver_(mouse).jpg


I found something interesting on the site Marcos linked to ( http://www.libelium.com/squidbee/index.php?title=GPS_module ) :

[font=Courier]This example shows how to connect the GPS module to an Arduino board and watch the NMEA sentences.

Connect the GPS shield as shown in the picture and then connect two short cables to +5V and GND from the GPS shield to the Arduino board. Finally, plug the USB cable to your computer.

Open a terminal program to listen the serial port. Use the following serial port configuration: 4800 baud, 8 data bits, no parity, 1 stop bit, no flow control. [/font]

This text seems to be saying that you can read that libelium GPS unit without having any code running on the Arduino. That is, when the GPS unit is attached to the arduino, it will all by itself, forward its serial data to the PC. Fancy..

loldrup

For a good measurement: Heres my code in a slightly more polished edition:

[font=Courier]#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

SoftwareSerial softSerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 softSerial.begin(4800);
 Serial.begin(4800);
}

void loop() {
 Serial.println("Just about to receive data:");
 char softSerialChar = softSerial.read();
 char hardSerialChar = Serial.read();
 // print out the character:
 Serial.println("Received from software serial: ");
 Serial.println(softSerialChar, DEC);
 Serial.println("Received from hardware serial: ");
 Serial.println(hardSerialChar, DEC);
 Serial.println("");  //just to make some space
 delay(1000);
}[/font]

Fjornir

Eh. I give up. You answer part of the questions posed to you but not all of them. You assert things which experienced members of the forum question but are unwilling to back up those assertions with measurements to support your assertions. You ignore suggestions and corrections from people trying to help you or, worse, argue with them even when the evidence (ie: your project isn't working) shows you to be wrong.

Good luck. You're going to need it.

loldrup

#26
Jan 25, 2009, 10:45 am Last Edit: Jan 25, 2009, 12:22 pm by loldrup Reason: 1
I didn't implement the use of Serial.available() but thats because I prefer to see -1 than to see nothing. I perfectly well know that receiving -1 means nothing were there - it doesn't mean that I actually received "-1".
I didn't check the voltage of the TX line because I don't have an analog voltmeter. Other times where I have tried this with my voltmeter, it hasn't been able to measure the full voltage of the line. My voltmeter is way too slow to catch the changing voltage. Also, it's not really necessary, as I have already accepted the proposition that my GPS might be 12v. That's why I started experimenting using my RS232 to TTL converter in between the GPS and the arduino. Theres no reason to make experiments to convince me when I'm already accepting the idea (and my recent use of the RS232 to TTL converter shows this).

Is the above behavior unacceptable, or do you have other reasons to discard my case?

loldrup

The only text on the GPS is this:
"[font=Courier]Model no.:
GPS-601
Made in Taiwan
Tested to comply with FCC standards[/font]"

Thats why I can't tell you either manufacturer name or part number. I've tried googling "GPS-601" but it doesn't reveal much.

Jassper

Your adaptor need to be powered. simply connecting the TX/RX line won't do it. Adaptors like that are useually port powered threw pin 7 (RTS) of the DB9 connector. You might be able to use the +5v from the Arduino to power the adator. If you don't have the specs for the adaptor, open the case and see if you can I dentify where to power it from.

loldrup

This is the adapter that I am using:
http://awce.com/rs1.htm
That website says: "Pin 1 and 2 require +5V (regulated) and ground." I think they mean pin1 has to have 5v and pin2 has to go to ground - both on the 5v side. Also, thats the names on the pins 1 and 2 on the TTL side, so thats how I have wired it up. The voltage is there and its 5.00 volt.
Referring to this image:
http://www.circuitdb.com/show.php?cid=172
I'm connecting the TX line from the GPS to either pin2 or pin3 on the 12v side. So Im trying all four combinations (pin2 or 3 on the 12v side and crossing or not crossing the two com lines from pin "T" and "R" on the converter to pin0 and 1 on the arduino). I also tried the pin4, just in case I am doing a "mirroring" mistake. The GPS is powered from the power from the power pins from its original cable (a usb to serial converter). This power source works fine, as I managed to get data from the GPS to my PC using them.
All while I'm running this code on the arduino:

[font=Courier]void setup()  {
 Serial.begin(4800);
}

void loop() {
 char hardSerialChar = Serial.read();
 Serial.print(hardSerialChar, DEC);
}[/font]

I simplified the code a bit. I don't know what baud rate the arduino PC-side software uses for uploading code to the arduino, but I have set the Serial monitor to listen using baud 4800.

As always, the result is a series of "-1" :(

I haven't got hold of a camera yet, but I'm working on it.

Thank you all for your help and patience. I really appreciate it!

Go Up