pyFirmata icon indicating copy to clipboard operation
pyFirmata copied to clipboard

Support for Ping (pulseIn Firmata) and other improvements

Open NeoPolus opened this issue 8 years ago • 4 comments

  • Support for pulseIn compatible Firmata, needed for ultrasonic ranging sensors that use a pulse to measure distances: the new "ping" method to the Pin class returns the echo time. An utility function to convert to distance was also added.
  • Improved the Board class, now it supports the Python "with" statement to be able to automagically manage the Iterator thread (autostarts the iterator, and takes care to call board.exit()).
  • Better support for working with timeouts (useful when the communication with the board hangs -thought that should no longer happen if we use the new 'with' support-).

NeoPolus avatar Mar 30 '16 10:03 NeoPolus

Hi, thanks for your extensive pull request. However, it is usually easier to implement features if they are small and contained. My reaction on these three proposals:

  1. I can't find this anywhere in the https://github.com/firmata/arduino library, is that correct? Because I would like to keep this a lean library, and not add code for every different sensor out there. Implementing this should be fairly easy by extending the Board class in your own code. Or did you run into things that made this hard?

  2. I really like the idea of running in a with block! However, to make it less "automagically" as you describe it somewhere I would be in favour of the following syntax, which is more explicit about what's happening:

    with Iterator(board):
        ...
    

    Which is probably easiest implemented with an _is_running attribute on the Iterator.

  3. Instead of raising a different error, wouldn't it be better to check for the length of self.sp.read() before passing it into ord alltogether? Or does this problem only occur when improperly exiting?

If you would like to move forward with one or more of these proposals, could you please do so in separate pull requests?

Also, please take PEP8 (https://www.python.org/dev/peps/pep-0008/) into account (use 4 spaces instead of tabs, etc.). I use flake8 to check this.

tino avatar Oct 29 '16 22:10 tino

So, what's the status on this? any chance that pyFirmata will get ping support at some point?

youssefhabri avatar Jul 09 '19 21:07 youssefhabri

This one would be really helpful, any chance we can provide pulse in through a special flag? without pulsein ultrasonic is not usable in firmata.

michaellee8 avatar Nov 08 '21 09:11 michaellee8

What can we do to make this PR successful?

Kakcalu13 avatar Feb 02 '24 21:02 Kakcalu13