I am trying to read analog read from ardunio connected to my raspberry pi. Following are my raspberry pi and arduino codes.

Raspbery pi:

import time
import serial 
ser = serial.Serial('/dev/ttyACM0',9600)

while True:
    value = ser.readline()
    print (value)

Arduino Code:

int val_1,val_2;
void setup()

void loop()
    val_1 = analogRead(A0);
    val_2 = analogRead(A1);

When I try to run my python script, I get the initial analog readings from the arduino, but as the values seems to be not updating. I had to restart the script every time to read the analog pin readings.

Need to know where I am going wrong or have I missed out important factor in this.

Thanks in advance :)

  • Does the answer from oh.dae.su help you? If so, please accept it with a click on the tick on its left side. This finishes your question and it will not pop up again year by year. – Ingo Nov 5 '19 at 11:52

You write with your Arduino to the serial interface continuously without any break.

On the Raspberry Pi you only read a single line every 0.5 seconds. This means your writing and reading are not in sync.

An easy remedy would be to add a delay in your Arduino code


that is longer than the sleep in your Raspberry Pi code. You can drop the sleep in your Raspberry Pi code altogether.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.