Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the first values read from the arduino always None #92

Open
martynwheeler opened this issue Apr 23, 2020 · 1 comment
Open

Why is the first values read from the arduino always None #92

martynwheeler opened this issue Apr 23, 2020 · 1 comment

Comments

@martynwheeler
Copy link

martynwheeler commented Apr 23, 2020

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

@JeS24
Copy link

JeS24 commented Apr 3, 2021

@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.".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants