Serial Connection between 2 Arduinos

Hello Everyone!

I have the following problem:
I use an Arduino Uno (number 1) and a second Arduino (Atmega 328P-PU) on a breadboard with a 16MHz crystal (number 2).

When I write number 0 to the serial Port on Arduino 2, the Serial Display on the PC on Arduino 1 shows 48.

Arduino 2:
I use the command Serial.write(counter);
The variable Counter is defined like this: byte counter=0;

I use the following commands at Arduino 1:
If(Serial.available() > 0)
{ incomingByte = Serial.read();
Serial.println(incomingByte, DEC);
}

I Set the Baud Rate on both devices to 2400.

Can anybody tell me what I'm doing wrong?

Tanks Armin

Armin,

When I write number 0

You are confusing numbers and characters.

What you wrote was the ascii character '0' which has a numeric value of 48.

See this to shed some light

If you still need people to help sort your code post both the send and receive sketches within #code

On the receiving side, use write() instead of println().

The problem is that you're receiving an ascii character code 48 (representing the character '0') but instead of writing the character code directly to the serial port (which would cause '0' to display in the serial monitor) you're printing the decimal number 48.

Simple conversion on the receive side:

if (Serial.available()>0){
Serial.print (Serial.read() - 48);
}

Aaah! :slight_smile:
I know what ASCII Charakters are but I didn't habe the idea that this could cause the Problem. :wink:

I will try the Code by Substrate 48.

Thanks at all for your help. I think I am now bald to solve it on my own :slight_smile:

N3xus132:
Aaah! :slight_smile:
I know what ASCII Charakters are but I didn't habe the idea that this could cause the Problem. :wink:

I will try the Code by Substrate 48.

Thanks at all for your help. I think I am now bald to solve it on my own :slight_smile:

Try to solve the problem on your own.
Then post your code here using the #.
We will then tell you if you have understood.