user10945: 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.

user13432: ser.write(str(x_value));

Writes the string representation of the integer x_value, which is a sequence of ASCII characters.
ByteReceived = (Serial.read());
Serial.print(ByteReceived);

Reads a character (byte) and prints to the value (again as a sequence of characters).
45 51 48 45 53 52 45 49 52 45 52 55 55....

45 is ASCII character value for the character '-', 51 is the character '3', 48 is '0' and so on.
Cheers!

10945: <p>I set up a serial connection and sending integers from a Raspberry Pi to an Arduino.</p>

<p>This is the Python code in my Raspberry Pi:</p>

<pre><code>import serial
ser = serial.Serial('/dev/ttyACM2', 9600)
ser.write(str(x_value));
</code></pre>

<p>And this is the command line output for <code>x_value</code>:</p>

<blockquote>
  <p>-38 -38 -38 -40 - 38 - 39 - 40 - 12 18 26 25 49...</p>
</blockquote>

<p>They are x coordinate values I generated and they range from -100 to 100. And here's the Arduino code for receiving serial data:</p>

<pre><code>int ByteReceived;

void loop() {
  while(1) {
    if (Serial.available() &gt; 0) {
      ByteReceived = (Serial.read());
      Serial.print(ByteReceived);
      Serial.print("\n");   
    }
  }
</code></pre>

<p>On the serial monitor I'm receiving these numbers:</p>

<blockquote>
  <p>46 45 51 48 45 53 52 45 49 52 45 52 55 55....</p>
</blockquote>

<p>They are numbers between 40-60 and no way proportional to the values I sent from <code>serial.write</code>.</p>

<p>I'm really confused right now. Can someone help me to figure out what caused this problem?</p>

<p>Thank you so much.</p>
 13432: <pre><code>ser.write(str(x_value));
</code></pre>

<p>Writes the string representation of the integer <code>x_value</code>, which is a sequence of ASCII characters.</p>

<pre><code>ByteReceived = (Serial.read());
Serial.print(ByteReceived);
</code></pre>

<p>Reads a character (byte) and prints to the value (again as a sequence of characters).</p>

<pre><code>45 51 48 45 53 52 45 49 52 45 52 55 55....
</code></pre>

<p><code>45</code> is ASCII character value for the character '-', <code>51</code> is the character '3', <code>48</code> is '0' and so on.</p>

<p>Cheers!</p>
