Issues with serial.Read

Hey guys, I'm extremely lost here. I have this simple program running on my arduino:

byte incomingByte;   // for incoming serial data
void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();
                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte);
        }
}

I have my Arduino hooked up to the serial port of my desktop computer and on my desktop, I am running a small program that will send the characters "Hello" and "Bye". The program can be obtained from http://sheepdogguides.com/dt4q.htm.

However, when "Hello" is sent, the Arduino responds with:

I received: 171 I received: 58 I received: 58 I received: 10 I received: 2

when "Bye" is sent, the Arduino responds with:

I received: 175 I received: 168 I received: 2

None of these values correspond to the correct ASCII values and I'm not quite sure what is going on. I'm assuming my issue is with the data type but I've tried decimal, hex, byte, and even converting by subtracting '0' but nothing is helping. Any help would be greatly appreciated.

Thanks again!

I have my Arduino hooked up to the serial port of my desktop computer...

Did you mean to write "USB port" or do you really mean "serial port"?

Looks like the baud rate is wrong to me.

Did you mean to write "USB port" or do you really mean "serial port"?

I really meant serial port. I'm using an older desktop computer.

Looks like the baud rate is wrong to me.

I've also tried a baud rate of 115200 with same results. If the baud rate was wrong, wouldn't I be receiving nothing at all?

No. If the baud rate is wrong the bits are skewed. They can easily come out as something else.

I’m almost positive that a baud rate of 9600 is also used by the program sending the “Hello” and “Bye” texts. The two should match, correct?

kyman2008: The two should match, correct?

Yes. It is critical that they do.

What happens if you use a known string from the Arduino IDE's Serial Monitor?

And what do you get when you use the Arduino IDE's serial window? That should tell you whether it's a problem with your Arduino code (if you get the same output), or with your third party application (if you get the expected output).

And what do you get when you use the Arduino IDE's serial window? That should tell you whether it's a problem with your Arduino code (if you get the same output), or with your third party application (if you get the expected output).

When I input "Hello" using the IDE serial window I get:

I received: 72 I received: 101 I received: 108 I received: 108 I received: 111

This matches the ASCII perfectly. This makes it look like my code if fine. I'm not quite sure what is going wrong between the computer and the arduino though.

My ultimate goal is to read in serial values from an OpenEEG board. From this particular board, I should be receiving bytes that are 90 and 165. However, the arduino doesn't read them as such. I resorted to this third party program I am using so I can know what is being sent and I should be able to verify it. I figured this would help me solve my other problem. However, the values I am reading are still not matching what is being sent. I still cannot figure out where my issue lies.

kyman2008: This matches the ASCII perfectly. This makes it look like my code if fine. I'm not quite sure what is going wrong between the computer and the arduino though.

Using the Serial Monitor tells you that the connection between your Arduino and PC are working correctly. The software you were using as a test is doing something different. To understand what, you'd probably need a look at the actual source code of that particular program. However, what is the point?

kyman2008: My ultimate goal is to read in serial values from an OpenEEG board. From this particular board, I should be receiving bytes that are 90 and 165. However, the arduino doesn't read them as such

How have you determined this to be the case? It sounds like we should be troubleshooting this problem and not the random program you found on the internet.

How have you determined this to be the case? It sounds like we should be troubleshooting this problem and not the random program you found on the internet.

The OpenEEG boards I am using were manufactured by Olimex and are universal. I don't want to go into too much detail, but according to the P2 protocol that the boards use, I should receive: One packet that has a 2 byte sync sequence (165,90), the version number (1 byte), the packet number (1 byte), and information on six channels (two bytes each) and a button state (1 byte), giving a total of 17 bytes.

Therefore, I should be receiving the following stream of data (each one is a binary 8bit number (0-255)): 165 90 any 8bit number any 8bit number

8 MSB bits of ch1

8 LSB bits of ch1 8 MSB bits of ch2

8 LSB bits of ch2 8 MSB bits of ch3

8 LSB bits of ch3 8 MSB bits of ch4

8 LSB bits of ch4 8 MSB bits of ch5

8 LSB bits of ch5 8 MSB bits of ch6

8 LSB bits of ch6 1 byte (8 bit) the buttons states (if it's pushed one bit will be changed)

However, using the code I posted earlier (only with a baud rate of 57600 since this is what the boards operate at), the Arduino never responds with bytes 90 or 165, even though they should appear frequently.

I don't want to go into too much detail...

I've noticed. If you continue withholding details I'm leaving.

However, using the code I posted earlier (only with a baud rate of 57600 since this is what the boards operate at), the Arduino never responds with bytes 90 or 165, even though they should appear frequently.

Which board? An Uno? A Mega?

How are you connecting the OpenEEG board to your Arduino?

Which board? An Uno? A Mega?

How are you connecting the OpenEEG board to your Arduino?

I’m using an Arduino Mega 2560. The OpenEEG board has a serial port output that is intended to run to the serial port on a computer. The OpenEEG board is operating properly as the data is coming in flawlessly on the desktop computer with various software. However, I’m trying to bypass the whole desktop computer by running straight from the OpenEEG serial output to the Arduino serial input, so I just have a couple wires connecting the two.

so I just have a couple wires connecting the two

No RS232-to-TTL converter?

No RS232-to-TTL converter?

No, do you think this could this be the issue?

So how are you connecting this OpenEEG board (or your computer serial port) to your Arduino?

Two issues: 1. Communications will not work because the signal is inverted. 2. The RS-232 voltage levels will damage your Arduino.

Noobie question, but is there any chance this could be built into the OpenEEG board? Or is it since my desktop computer can pick up the signal, that means I must need a RS232 to TTL converter?

Thanks again guys

kyman2008: Noobie question, but is there any chance this could be built into the OpenEEG board?

The site for this project is probably one of the most difficult I have ever tried to navigate before.

Can you please find a link to the schematic of the board you are using and a link to the description of the protocol being used?