I set up a serial connection and sending integers from a Raspberry Pi to an Arduino.
This is the Python code in my Raspberry Pi:
import serial
ser = serial.Serial('/dev/ttyACM2', 9600)
ser.write(str(x_value));
And this is the command line output for x_value
:
-38 -38 -38 -40 - 38 - 39 - 40 - 12 18 26 25 49...
They are x coordinate values I generated and they range from -100 to 100. And here's the Arduino code for receiving serial data:
int ByteReceived;
void loop() {
while(1) {
if (Serial.available() > 0) {
ByteReceived = (Serial.read());
Serial.print(ByteReceived);
Serial.print("\n");
}
}
On the serial monitor I'm receiving these numbers:
46 45 51 48 45 53 52 45 49 52 45 52 55 55....
They are numbers between 40-60 and no way proportional to the values I sent from serial.write
.
I'm really confused right now. Can someone help me to figure out what caused this problem?
Thank you so much.