Digital Reads Return `None`
See original GitHub issueWhen I did this on an Arduino Uno:
>>> board.digital[3].mode = INPUT
>>> board.digltal[3].enable_reporting() # Not sure why this has to be an explicit method call
>>> print(board.digital[3].read()) # Return None most of the time
The last statement return None
most of the time. It did work sometime, returning True
on an open switch and False
on closed. However, I had to explicitly start a thread with
>>> thread = util.Iterator(board)
>>> thread.start()
And with that it still returned None
very often.
Issue Analytics
- State:
- Created 8 years ago
- Comments:17 (11 by maintainers)
Top Results From Across the Web
pyfirmata digital read problems - Interfacing w - Arduino Forum
If the button is closed when the program starts, it returns a true and I never see the None again. Just plain weird...
Read more >arduino read in pyfirmata gives output as none - Stack Overflow
INPUT it = pyfirmata.util.Iterator(board) it.start() board.digital[3].read(). Most of the time it work, but sometimes None still show up.
Read more >How to return None if Dictionary key is not available - Edureka
I need a way to get a dictionary value if its key exists, or simply return None, if it does not. However, Python...
Read more >Stop Returning None From Python Functions | by Imran Ali
Often, when reading Python code, you'll come across utility functions that will return None. Although it might seem natural to return None in...
Read more >Python return statement - DigitalOcean
If the function doesn't have any return statement, then it returns None . def print_something(s): print('Printing::', s) output = ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also had this problem and solved it by adding some delay after starting the iterator thread. Some time is probably needed for the serial communication to be initialized propertly. 10ms is enough.
@tino well that makes sense. I’m closing this issue for now unless someone reopen again.