question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Digital Reads Return `None`

See original GitHub issue

When 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:closed
  • Created 8 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Vladivariuscommented, Jan 18, 2018

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.

board = Arduino('COM5')
BTN = board.get_pin('d:10:i')
thread = util.Iterator(board)
thread.start()
sleep(0.01)
print(BTN.read())
0reactions
jochasingacommented, Oct 30, 2016

@tino well that makes sense. I’m closing this issue for now unless someone reopen again.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found