system
August 23, 2013, 1:14pm
1
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
system
August 23, 2013, 1:32pm
2
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
Ascii character table - What is ascii - Complete tables including hex, octal, html, decimal conversions
If you still need people to help sort your code post both the send and receive sketches within #code
system
August 23, 2013, 1:36pm
3
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);
}
system
August 23, 2013, 4:00pm
5
Aaah!
I know what ASCII Charakters are but I didn't habe the idea that this could cause the Problem.
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
system
August 23, 2013, 9:33pm
6
N3xus132:
Aaah!
I know what ASCII Charakters are but I didn't habe the idea that this could cause the Problem.
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
Try to solve the problem on your own.
Then post your code here using the #.
We will then tell you if you have understood.