Serial keymap messed up?

My 1st post on the arduino forum :slight_smile:

Today I just received my new Arduino 2560.
I am still abit of a noob to Arduino.
I am trying to let it communicate to a Wavecom modem on Serial3.

The Wavecom and my PC are both set to 9600.
When I hook up the modem to my PC everything works fine.
The modem only sends/receives ASCII.

When the modem sends RING to arduino this comes out:

I tried connecting Arduino Serial3 to my PC and typing RING but then I get exactly the same as above.

I am puzzled :frowning:

How can I get Arduino to read/write the proper characters from/to the serial port?

Here is my code:

byte incomingByte = 0;
String buffer =  String("");
//set to true to bypass modem init loop for testing
boolean waitForPhoneNumber = false;

void setup() {
        Serial.begin(9600);
	Serial3.begin(9600);
        pinMode(13, OUTPUT);
}

void loop() {
        //buffer string filler
        while (Serial3.available() > 0)  {
          digitalWrite(13, HIGH);
          incomingByte = Serial3.read();
          buffer = buffer + incomingByte;
          //next 2 lines are for debugging purposes only
          Serial.println(buffer);
          Serial.println("test");
        }
        digitalWrite(13, LOW);
        //init modem
        if (!waitForPhoneNumber)  {
          Serial3.println("AT+CLIP=1");
          delay(500); // to allow modem to respond
          if ((buffer.indexOf("ok")) >= 0)  {
            waitForPhoneNumber = true;
            buffer = "";
          }
        }
        //check if modem sends my phone number
	if (waitForPhoneNumber) {
          //random phone number for testing:
          if (buffer.indexOf("31123456789") >= 0) {
            Serial3.println("ath");
            buffer = "";
          }
	}
        //just in case, will probably never occur
        if (buffer.length() > 100)  {
          buffer = "";
        }
}

Many thanks in advance!

Welcome!

How are you making the mega to PC connection? You have RS232 to USB adapter wired up or something?

CrossRoads:
Welcome!

How are you making the mega to PC connection? You have RS232 to USB adapter wired up or something?

Thank you for your reply.

COM5 is connected to the Arduino oboard USB port.

I have Putty open on COM3, thats a Prolific USB to serial adapter attached to Serial3 (pin 14 and 15).

When I connect the Wavecom modem directly to the Prolific USB to Serial adapter on COM3 it works fine on 9600.

I only use 3 wires to communicate with the Wavecom modem TX, RX, and Ground.
Swapping RX and TX wires doesn't work, and I am 100% sure that Ground is properly connected.

I added some debug lines to that it writes the entire buffer string and "test" to Serial after each received character on Serial3.

Considering that the string "test" arrives in one piece... I think the problem is actually in the PC sending the "RING" command to the Arduino. Or the receiving process in the Arduino.

Could it be an encoding problem?

bubulindo:
Considering that the string "test" arrives in one piece... I think the problem is actually in the PC sending the "RING" command to the Arduino. Or the receiving process in the Arduino.

Could it be an encoding problem?

Thank you for your reply.

The interesting thing is that capitol R always comes out as a +, I as [, etc.

But how do I change the encoding to fit the encoding of my PC and Wavecom modem?
I hope this doesn't mean that I have to write code for an alternative ASCII table :frowning:

btw I am not pretending to actually know how encoding works, me = noob

Well... I've read somewhere that to interface cell phones, you need to convert the string you are sending to a different encoding (7 bit or something like that) for it to work. However, I have no idea if this is the case.

Have you checked all the communication setups? if it's 8N1 on all the devices... Can you do a loopback test with the PC? cut the Arduino out of the equation and see if the modem sends to the computer the same data? You could try and change the bitrate, but if it's persistent, I don't think it's a bitrate problem.

The consistent nature smacks of inversion.

an inverted R isn't a \ or +, or for that matter [ or , .

this is cryptic. LOL

bubulindo:
an inverted R isn't a \ or +, or for that matter [ or , .

this is cryptic. LOL

Modem > PC COM3 = OK @ 9600 8N1
PC COM3 > Modem = OK @ 9600 8N1
Arduino USB > PC USB = OK @ 9600 8N1
PC USB > Arduino USB = OK @ 9600 8N1
Arduino Serial3 > PC/modem = problem
PC/modem > Arduino Serial3 = problem

(arduino usb is com5 on pc, COM3 is physical serial port on PC)

When I connect my PC (or any device for that matter) to one of the Serial(1, 2 or 3) interfaces what settings should I use?
So far I've been using 9600 8N1 for everything.

I have noticed another strange thing:
When I send "abc" (all 3 characters at once) through the Serial Monitor it comes out the other end as:
"Oยง"
But when I send those 3 characters individually (one by one) it comes out as:
"O'N"
The above 2 actions are repeatable with the same results

For testing I used:

byte incomingByte = 0;

void setup() {
	Serial.begin(9600);
        Serial3.begin(9600);
}

void loop() {
	if (Serial.available() > 0) {
		incomingByte = Serial.read();
                Serial.print(incomingByte); //just to make sure whatever I am sending gets received properly
		Serial3.print(incomingByte);
	}
}

Getting desperate now :frowning:

edit: i tried using 2 stop bits instead of 1 and/or 7 databits instead of 8, but that doesn't appear to change anything, same output in the above 2 tests

I have Putty open on COM3, thats a Prolific USB to serial adapter attached to Serial3 (pin 14 and 15).

Via something like a MAX232, I hope?

AWOL:
a MAX232

What's that?

(google-ing it right now)

edit: slamming head on desk now, I thought that the ports on Arduino where already RS232.

edit2: I still can't believe I spent hours cursing in frustration because of a little extra chip I needed that I never knew existed :astonished:

Thanks for all your help!

edit3: Did I damage my Arduino by connecting RS232 directly to TTL?

Probably as you were still getting repeatable results out of it.

LOL

Another problem of Arduino giving power to people... LOL We, or I, assumed that you'd connect this through some converter. So, yeah. get a MAX232, or my favorite DS275 and give it a try. You may have burnt the pins... give it a go either way.

an inverted R isn't a \ or +, or for that matter [ or , .

Don't forget that the interpretation of an inversion on an asynchronous serial line isn't simple.
The inversion changes the position of whatever is interpreted as the start bit.

Groove nailed it, though somewhat tersely!

It is an unfortunate historical accident that 'serial' has come to be associated with 'RS232', but the inherent inversion from what is thought as normal has been forgotten, as has the level shift.

I have used PIC microcontrollers directly with RS232 with bit-banging, directly to I/O pins, relying on the in-built protection, and all was fine. i think your AVR may be ok. Only time will tell.