Issues Reading from Raspberry Pi Serial Port with Python

Hi, I am working on a project that uses a Raspberry Pi in conjunction with an Arduino which reads analog values from a potentiometer and sends them to the serial port, which are then read by the Pi. I wrote a simple program to test this out, which reads incoming data from the Pi, converts it to an integer value and prints it, which works great on my Mac, but does not work on my Pi. I get the following error:

value = ord(
TypeError: ord(): expected a character, but a string of length 0 found

I have tried different values for timeout, with timeout = none the program just waits forever.
Here is my Python and Arduino Code, please let me know if you see anything wrong or have an suggestions. Thanks!


import serial
from time import sleep

ser = serial.Serial(

#/dev/tty.usbserial-AH02OC4V for mac, command line to find port: ls /dev/tty.*
#/dev/ttyUSB0 for Pi/Linux, command line to find port: ls /dev/tty*

value = 0
while True:
	value = ord(
	print "value: " 
	print value


void setup()

void loop()
  if (Serial.available() > 0)
    int pyVal =;
    int potVal = analogRead(0)/4;

I have no idea what differences there may be between Python on a Mac and on an RPi (somewhat outside the scope of the Arduino Forum). Are they both using the same Python version - there can be problems with 3 vs 2.7

You may wish to try this Python - Arduino demo which works with Python 2.7 and has not been tested with Python 3.


Put a sleep between the python write and read.