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

Deinitialize pulsein object on exit, gave option to choose whether or not to use pulseio #46

Merged
merged 5 commits into from
Aug 19, 2020

Conversation

evaherrada
Copy link
Collaborator

No description provided.

@evaherrada
Copy link
Collaborator Author

Tried to test but my pi was not cooperating

@jerryneedell
Copy link

jerryneedell commented Jul 17, 2020

@dherrada I tested this on a Pi 4B+ with a DHT22 both with and without pulseio. It works both ways but I did see more checksum errors without pulseio.

use_pulseio=False

pi@gjnpi4desk:~/projects/DHT $ python3 dht_simpletest.py
Temp: 74.1 F / 23.4 C    Humidity: 51.8% 
Temp: 74.1 F / 23.4 C    Humidity: 51.7% 
Temp: 74.1 F / 23.4 C    Humidity: 51.8% 
Checksum did not validate. Try again.
Temp: 74.1 F / 23.4 C    Humidity: 50.5% 
Temp: 73.9 F / 23.3 C    Humidity: 51.8% 
Checksum did not validate. Try again.
Temp: 74.1 F / 23.4 C    Humidity: 50.6% 
Temp: 74.1 F / 23.4 C    Humidity: 52.0% 

use_pulseio=True

pi@gjnpi4desk:~/projects/DHT $ python3 dht_pulseio.py 
Temp: 74.1 F / 23.4 C    Humidity: 52.0% 
Temp: 74.1 F / 23.4 C    Humidity: 51.6% 
Temp: 73.9 F / 23.3 C    Humidity: 51.5% 
Temp: 73.9 F / 23.3 C    Humidity: 51.5% 
Temp: 73.9 F / 23.3 C    Humidity: 51.5% 
Temp: 74.1 F / 23.4 C    Humidity: 51.6% 
Temp: 74.1 F / 23.4 C    Humidity: 51.6% 
Temp: 73.9 F / 23.3 C    Humidity: 51.5% 
Temp: 73.9 F / 23.3 C    Humidity: 51.5% 
Temp: 73.9 F / 23.3 C    Humidity: 51.5% 
Temp: 74.1 F / 23.4 C    Humidity: 51.6% 

@jerryneedell
Copy link

jerryneedell commented Jul 17, 2020

I also test this on a feather_m4_express and the bitbang does not work at all

use_pulseio=False

Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 5.4.0-beta.0-402-g5cd6bb4d5 on 2020-05-30; Adafruit Feather M4 Express with samd51j19
>>> import dht_bitbang_m4
A full buffer was not returned. Try again.
A full buffer was not returned. Try again.
A full buffer was not returned. Try again.

use_pulseio=True

import dht_pulseio_m4
Temp: 76.3 F / 24.6 C Humidity: 50.3%
Temp: 76.3 F / 24.6 C Humidity: 50.1%
Temp: 76.1 F / 24.5 C Humidity: 50.1%


FYI -- I upgraded to the latest version of the CP main repository and get the same results on the M4 -- biting  does not appear to be working on the M4  and I have previously found that it does not work on an M0 either....


Is bitbang supposed to work at all under CP? If not, it should not be an option. If it should work, then something is broken.

@evaherrada
Copy link
Collaborator Author

@jerryneedell Ok. I think I'll add a comment somewhere in the example that explains this.

@evaherrada
Copy link
Collaborator Author

evaherrada commented Jul 17, 2020

Is bitbang supposed to work at all under CP?

I think so. The learn guide (https://learn.adafruit.com/dht/dht-circuitpython-code#step-2980241) says it should work on any pin with PWM support, which, on the M4, is most of them (https://learn.adafruit.com/assets/78438), and, on the M0, is a lot of them (https://learn.adafruit.com/assets/46247).

@jerryneedell
Copy link

tested updated PR on Raspberry Pi 4B= with DHT 22

pi@gjnpi4desk:~/projects/DHT $ python3 dht_simpletest.py 
Temp: 74.8 F / 23.8 C    Humidity: 54.3% 
Temp: 74.8 F / 23.8 C    Humidity: 53.9% 
Temp: 74.7 F / 23.7 C    Humidity: 53.8% 
Temp: 74.8 F / 23.8 C    Humidity: 53.9% 
Temp: 74.8 F / 23.8 C    Humidity: 53.8% 
Temp: 74.8 F / 23.8 C    Humidity: 53.8% 
^Creceived SIGINT

Traceback (most recent call last):
  File "dht_simpletest.py", line 34, in <module>
    time.sleep(2.0)
KeyboardInterrupt

pi@gjnpi4desk:~/projects/DHT $ python3 dht_bitbang.py    --- with use_pulseio=Fasle
Temp: 74.8 F / 23.8 C    Humidity: 53.7% 
Temp: 74.8 F / 23.8 C    Humidity: 53.6% 
Temp: 74.8 F / 23.8 C    Humidity: 53.7% 
Temp: 74.8 F / 23.8 C    Humidity: 53.7% 
Temp: 74.8 F / 23.8 C    Humidity: 53.7% 
Temp: 74.8 F / 23.8 C    Humidity: 53.7% 
Temp: 74.8 F / 23.8 C    Humidity: 53.7% 
Temp: 74.8 F / 23.8 C    Humidity: 53.6% 
^CTraceback (most recent call last):
  File "dht_bitbang.py", line 34, in <module>
    time.sleep(2.0)
KeyboardInterrupt

also tested using pulseio on feather m4_express -- worked normally.

@evaherrada evaherrada requested a review from a team July 17, 2020 18:58
@evaherrada
Copy link
Collaborator Author

@jerryneedell Do you think it's worth taking a deeper look into the bitbang issue on CircuitPython? Is there a valid reason that anyone would want to use the bitbang method over pulseio?
I think that the really important ones are having both bit-banging and pulseio working on the Pi, and having pulseio working on CircuitPython. If you agree, then I think we should do what you suggested and disable bit-banging on CircuitPython for this library.

@jerryneedell
Copy link

jerryneedell commented Jul 24, 2020

@jerryneedell Do you think it's worth taking a deeper look into the bitbang issue on CircuitPython? Is there a valid reason that anyone would want to use the bitbang method over pulseio?
I think that the really important ones are having both bit-banging and pulseio working on the Pi, and having pulseio working on CircuitPython. If you agree, then I think we should do what you suggested and disable bit-banging on CircuitPython for this library.

Since bitbang does not appear to work under CP and I am not aware of anyone interested in fixing it, I agree it should be removed. Just throw an error if Pulseio is not available.

@evaherrada
Copy link
Collaborator Author

@jerryneedell Ok, that's what I'll do.

@evaherrada
Copy link
Collaborator Author

@jerryneedell To be completely honest, I didn't test this last commit outside of mock testing the if statement in the repl in circuitpython and on the raspberry pi

@goldyfruit
Copy link

In my case I had to add dhtDevice.exit() to my try then it worked.

@kattni
Copy link

kattni commented Aug 17, 2020

@jerryneedell Dylan is off for a while. Any chance you could take over this PR?

@jerryneedell
Copy link

@jerryneedell Dylan is off for a while. Any chance you could take over this PR?

I’ll take a look at it tomorrow. I kind if lost track of it.

@jerryneedell
Copy link

jerryneedell commented Aug 18, 2020

@kattni I have tested this on a feather_m0 (basic) and on a Raspberry Pi 4
It works on both using pulseio and as expected throws an error on the M0 if pulseio is disabled.
On the Raspberry Pi 4 there are occasional errors - more when using bitbang.

By "taking over" this PR - did you want me to do more than this testing? I do not know what the full motivation was for this PR to begin with. The issues with bitbang seem to have eclipsed the issue related to de-init.

Do you want to go ahead and merge this as it is since it appears to be working and no one else has commented on the changes. I wish there were a better way to do this since it has a large piece of code that is never used by CircuitPython (only Blinka) but I don't have anything in mind. Is the bitbang support from Blinka important enough to keep it?

Let me know how you want to proceed.

@kattni
Copy link

kattni commented Aug 19, 2020

Is the bitbang support from Blinka important enough to keep it?

@makermelissa Can you weigh in on this? Please glance over the entire thread. The question regarding Blinka is in the comment from Jerry immediately before this one, and that's the thing I'm specifically looking for input on. Thanks!

@kattni
Copy link

kattni commented Aug 19, 2020

@jerryneedell I'm bringing in Melissa for the Blinka part of the decision. Then we can sort out where to go from here.

@jerryneedell
Copy link

jerryneedell commented Aug 19, 2020

If I recall correctly, bitbang was originally introduced for the RPi because pulseio was not available. See #18 and #14. Are there are some SPC's supported by Blinka that still do not have pulseio? I was just wondering if it was still useful to have. It would simplify and reduce the size the library to take it out if it is not needed.

@jerryneedell
Copy link

especially note this comment #18 (comment)

@makermelissa
Copy link
Collaborator

That's a good point @jerryneedell. There are actually only a few boards (Raspberry Pi only perhaps) that have the pulseio available, so it's probably worth keeping for the other boards that don't have the hardware support.

@jerryneedell
Copy link

If we are going to keep bitbang, then I think this PR is OK - possibly with one change as noted above.

@kattni
Copy link

kattni commented Aug 19, 2020

@jerryneedell Can you please make the change you suggested? Then we can get this merged.

@jerryneedell
Copy link

@jerryneedell Can you please make the change you suggested? Then we can get this merged.

OK -- I "think" I did that correctly ...

Copy link

@jerryneedell jerryneedell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added doctoring for new kwarg - use_pulseio
tested on RPi 4

Copy link

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks everyone who worked on this!

@kattni kattni merged commit a67ac23 into master Aug 19, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Aug 21, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_DHT to 3.5.0 from 3.4.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DHT#46 from adafruit/pulseio-fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_HCSR04 to 0.4.3 from 0.4.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_HCSR04#21 from FoamyGuy/dannystaple-readme-patch

Updating https://github.com/adafruit/Adafruit_CircuitPython_INA219 to 3.4.4 from 3.4.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_INA219#24 from nvtkaszpir/patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_INA219#23 from nvtkaszpir/patch-2
  > Merge pull request adafruit/Adafruit_CircuitPython_INA219#22 from nvtkaszpir/patch-3

Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS to 4.1.0 from 4.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#20 from adafruit/lsm6dso32

Updating https://github.com/adafruit/Adafruit_CircuitPython_MS8607 to 1.0.1 from 1.0.0:
  > updated PID

Updating https://github.com/adafruit/Adafruit_CircuitPython_PCT2075 to 1.1.4 from 1.1.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_PCT2075#12 from garrettheath4/readme-fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_PM25 to 1.0.3 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_PM25#6 from dglaude/patch-2

Updating https://github.com/adafruit/Adafruit_CircuitPython_PN532 to 2.2.0 from 2.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_PN532#37 from dunkmann00/listen-for-passive-target

Updating https://github.com/adafruit/Adafruit_CircuitPython_TLC59711 to 1.2.3 from 1.2.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_TLC59711#14 from FoamyGuy/remove_hardcoded_baudrate

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font to 1.2.0 from 1.1.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_Bitmap_Font#27 from FoamyGuy/adding_more_examples
  > Merge pull request adafruit/Adafruit_CircuitPython_Bitmap_Font#24 from FoamyGuy/fix_docs_link_in_readme

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_Adafruit to 1.2.0 from 1.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_Adafruit#6 from dhalbert/fix-packet-sizes

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.8.2 from 2.8.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#88 from FoamyGuy/fix_load_glyphs_for_builtin

Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.4.2 from 2.4.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#64 from rhooper/adjust-copyright

Updating https://github.com/adafruit/Adafruit_CircuitPython_Motor to 3.2.1 from 3.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Motor#46 from caternuson/example_rename
  > Merge pull request adafruit/Adafruit_CircuitPython_Motor#44 from caternuson/digi_step

Updating https://github.com/adafruit/Adafruit_CircuitPython_ProgressBar to 1.3.2 from 1.3.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_ProgressBar#14 from FoamyGuy/simpletest_improvement

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyBadger to 3.1.0 from 3.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyBadger#35 from FoamyGuy/adding_cpb_gizmo
@SecT0uch
Copy link

SecT0uch commented Nov 7, 2020

I have several remarks regarding this:

  • Shouldn't the exit() function be automatically called after a measure with pulseio ?
  • Shouldn't we quiet the exit() function? (Remove the print())
  • Impossible to measure using Bitbang for me:
    pi@raspberrypi:~ $ python3 dht_simpletest.py 
    A full buffer was not returned. Try again.
    A full buffer was not returned. Try again.
    A full buffer was not returned. Try again.
    A full buffer was not returned. Try again.
    

I'm using a Raspberry Pi zero W, on pin D18

I can submit a PR regarding the exit() function if needed.

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

Successfully merging this pull request may close these issues.

6 participants