Arduino Uno with RS232 Shield

I am working on a project to read data from a GPS and display it using RS232 serial connections. As such, we ordered an RS232 shield.

My first question is if the shield does indeed take care of all the RS232 to TTL conversions.

We ran into an issue where the GPS connector and the shield connector were both female so we attempted to use wires to connect the two. I am worried that we did not properly adhere to RS232 connections and my have damaged the shield. However, the code we used did manage to get something although the data looked like gibberish.

Believing that our RS232 connection was faulty, we bought a female to female adapter. However, upon connecting to the GPS, a very quiet but distinct beeping/buzzing sound was heard from the shield.

Earlier today, I had used code to test the RS232 shield with hyper terminal. I could type in a letter and then the board would print out the value of the letter in different formats. This worked fine. Unfortunately, after the aforementioned beeping/buzzing sound, we tried to test the shield again with the code. We were unable to connect to the RS232 Com port in hyper terminal. Also, I'm not sure if the Rx light was lit earlier but currently, the Tx light is the only one lighting up.

I believe we have damaged our shield but before we order another one, I was wondering if anyone can help us.

Thanks for your time.

Attached is the code we had used to test the shield in hyper terminal.

/*
Analog input

reads keyboard input, prints the value out in a variety of formats.

created 24 March 2006
by Tom Igoe
modified by Gerald Donnelly, 2010
*/

int incomingByte = 0; // variable to hold the analog value
void setup() {
// open the serial port at 9600 bps:
Serial.begin(9600);
}

void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
// print it out in many formats:
Serial.print("I received: ");
Serial.println(incomingByte); // print as an ASCII-encoded decimal
Serial.println(incomingByte, DEC); // print as an ASCII-encoded decimal
Serial.println(incomingByte, HEX); // print as an ASCII-encoded hexadecimal
Serial.println(incomingByte, OCT); // print as an ASCII-encoded octal
Serial.println(incomingByte, BIN); // print as an ASCII-encoded binary
Serial.println(incomingByte, BYTE); // print as a raw byte value

// delay 10 milliseconds before the next reading:
delay(10);
}
}

void loop() {
 if (Serial.available() > 0) {
           [glow]// read the incoming byte:[/glow]
 // print it out in many formats:
 Serial.print("I received: ");
 Serial.println(incomingByte);       // print as an ASCII-encoded decimal
 Serial.println(incomingByte, DEC);  // print as an ASCII-encoded decimal
 Serial.println(incomingByte, HEX);  // print as an ASCII-encoded hexadecimal
 Serial.println(incomingByte, OCT);  // print as an ASCII-encoded octal
 Serial.println(incomingByte, BIN);  // print as an ASCII-encoded binary
 Serial.println(incomingByte, BYTE); // print as a raw byte value

 // delay 10 milliseconds before the next reading:
 delay(10);
 }
}

Comments alone are generally not enough to make something happen. What happened to the Serial.read() statement?

hahaha good pick up. I'm not sure when that got deleted. That seems to have fixed the text problem. Thanks a lot.

On the other problem, we get gibberish from the GPS. I had read somewhere that we would need to invert the voltages because the GPS used RS232 versus the Uno's TTL. I am using the RS232 shield so do I need to worry about the voltages?

Thanks again for all your help.

If you are just receiving input from the GPS, then you probably can just use the transistor and two resistors to do the inversion per the below page.

The NewSoftSerial class can deal with inverted logic, but, as far as I know, the hardware serial ports can not.

We had read about using transistors to do the inversion but we had already bought the RS232 shield.

So even with the RS232 shield from cutedigi, we would still need the NewSoftSerial class to do the inversion?

Thanks again for all your input.

we would still need the NewSoftSerial class to do the inversion?

Try it and see. If the input then looks right, yes, you need it. If not, then the trouble is elsewhere, and, no, you don't.

I tried the NewSoftSerial Library and got what looked like a string of blank spaces. I turned to this code below from Arduino Playground with a few added probes.

#include <string.h>
#include <ctype.h>
int ledPin = 13; // LED test pin
int rxPin = 0; // RX PIN
int txPin = 1; // TX TX
int byteGPS=-1;
char linea[300] = "";
char comandoGPR[7] = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;
int indices[13];
void setup() {
pinMode(ledPin, OUTPUT); // Initialize LED pin
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(4800);
for (int i=0;i<300;i++){ // Initialize a buffer for received data
linea*=' ';*

  • } *
    }
    void loop() {
  • digitalWrite(ledPin, HIGH);*
  • byteGPS=Serial.read(); // Read a byte of the serial port*
  • Serial.print("Byte read is: ");*
  • Serial.println(byteGPS);*
  • if (byteGPS == -1) { // See if the port is empty yet*
  • Serial.println("Serial port not available");*
  • delay(100);*
  • } else {*
  • linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer*
  • conta++; *
  • Serial.print(byteGPS, BYTE);*
  • if (byteGPS==13){ // If the received byte is = to 13, end of transmission*
  • digitalWrite(ledPin, LOW);*
  • cont=0;*
  • bien=0;*
  • for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR*
    _ if (linea*==comandoGPR[i-1]){_
    _
    bien++;_
    _
    }_
    _
    }_
    _
    if(bien==6){ // If yes, continue and process the data*_
    * for (int i=0;i<300;i++){*
    _ if (linea*==','){ // check for the position of the "," separator*
    * indices[cont]=i;
    cont++;
    }
    if (linea==''){ // ... and the ""
    indices[12]=i;
    cont++;
    }
    }
    Serial.println(""); // ... and write to the serial port*

    * Serial.println("");
    Serial.println("---------------");
    for (int i=0;i<12;i++){
    switch(i){
    case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
    case 1 :Serial.print("Status (A=OK,V=KO): ");break;
    case 2 :Serial.print("Latitude: ");break;
    case 3 :Serial.print("Direction (N/S): ");break;
    case 4 :Serial.print("Longitude: ");break;
    case 5 :Serial.print("Direction (E/W): ");break;
    case 6 :Serial.print("Velocity in knots: ");break;
    case 7 :Serial.print("Heading in degrees: ");break;
    case 8 :Serial.print("Date UTC (DdMmAa): ");break;
    case 9 :Serial.print("Magnetic degrees: ");break;
    case 10 :Serial.print("(E/W): ");break;
    case 11 :Serial.print("Mode: ");break;
    case 12 :Serial.print("Checksum: ");break;
    }
    for (int j=indices;j<(indices[i+1]-1);j++){
    Serial.print(linea[j+1]);
    }
    Serial.println("");
    }
    Serial.println("---------------");
    }
    conta=0; // Reset the buffer*

    * for (int i=0;i<300;i++){ //
    linea=' ';
    }
    }
    }
    }*

    However, the serial print statement is always -1 or that the serial port is unavailable. On the uno the TX is marked as 1 and the RX is marked as 0 so I feel like that is correct. I'm not sure why it seems the serial port is not connected.
    Thanks for your help._
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

You should not be setting pinMode on the hardware serial pins.

On the other problem, we get gibberish from the GPS.

Earlier, you were getting something, but it wasn't quite what you expected. Now, you are getting anything. What changed?

What kind of GPS is it? Most operate at 4800 baud, but some default to 9600.

The earlier data we were receiving was still just odd characters. We are still receiving that now. I'm sorry for the confusion. The code outputs characters when serial.read returns an int. So changing the format of our output we got a -1 which means the serial port was unavailable.

The GPS we are using is a GPS18 from Garmin. By default the baud rate is 4800.

We set the GPS up with hyperterminal and instantly got NMEA data so the problem isn't the GPS.

We then hooked the RX pin of the RS232 shield up to an oscilloscope to see the output. We get a high signal with a pulsing dip that goes wide to narrow alternating. I'm not sure if this is the right signal for the Rx pin.


\ /
\ /


| |
| |


That's the best I can draw the two alternating forms using text.

sorry for the flood of posts but what does serial.read() = -1 actually mean? Could our GPS be interfering with our input output ports?

what does serial.read() = -1 actually mean?

It means that there was no data available to read.

We set the GPS up with hyperterminal

How? Is it really a Serial device? That is, is it connected to a serial port using a 9 pin D connector?