Here is my code:

import serial

ser = serial.Serial('/dev/ttyAMA0')
x = 0
while x <= 30:
       opc_data = ser.read() 
       print opc_data 
       x = x+1

When I run this code, nothing is printed to the console for the most part, but every once in a while a digit shows up like a 1, 2, f, or g

What I am expecting to get is two numbers, one around 1800 and one around 20. My question is: why are the numbers I am expecting to see not showing up? Is there an issue with the code? or Is it an issue with the OPC that is sending the RPi data? or something else?

Edit: inWaiting "gets the number of bytes in the input buffer" and it "returns the number of bytes in the receive buffer" as an int.

Edit: Pi model: A, OS: Raspbian wheezy, Baud rate: 9600



The issue is with the code and the system. The system was not holding pressure, therefore more often than not no value was being printed.

The issue with the code then is that ser.read() returns a single byte of data. I need at least two bytes to be returned and I need to figure out how to convert this data into data that I can understand.

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.