You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to read analog data from the arduino. Whenever I read the data the first value is always None. Subsequent readings are okay. I have implemented a check in my code but i was wondering why this was the case.
Here is my code:
#!/usr/bin/python3
# Import Libraries
import time
import pyfirmata
# Creates a new board
board = pyfirmata.Arduino('/dev/ttyAMA0')
# Start the iterator
it = pyfirmata.util.Iterator(board)
it.start()
# Setup the analog pin
analog_input = board.get_pin('a:0:i')
# get the data
try:
analog_value = analog_input.read()
while analog_value == None:
analog_value = analog_input.read()
time.sleep(0.1)
finally:
board.exit()
it = None
print(analog_value)
I have tried waiting 1 second before the first reading but this makes no difference
Thanks
Martyn
The text was updated successfully, but these errors were encountered:
@martynwheeler I think, this answers the "how" of your question: #57 (comment). In particular, "read() can return None in the beginning when there aren't any reads yet.".
I am trying to read analog data from the arduino. Whenever I read the data the first value is always None. Subsequent readings are okay. I have implemented a check in my code but i was wondering why this was the case.
Here is my code:
I have tried waiting 1 second before the first reading but this makes no difference
Thanks
Martyn
The text was updated successfully, but these errors were encountered: