adafruit / Adafruit_CircuitPython_DHT

CircuitPython support for DHT11 and DHT22 type temperature/humidity devices
MIT License
182 stars 64 forks source link

Add RPi (non-pulseio) support #18

Closed jerryneedell closed 5 years ago

jerryneedell commented 5 years ago

This replaces PR #14 - it reconciles the changes with the current master with a few additional changes from the original PR from @ladyada 1)Main fix was to correct a bug in the pulseio code that had the relational test for the delay waiting for pulses inverted. This broke the pulseio version -- OK now 2)Attempted to make the non-pulseio more like the pulseio in its treatment of the incoming string of transitions - only use the last 81 transitions received. There are still a lot of errors when running on a Raspberry Pi, but this seems to help a bit - still > 10% failed readings 2) changed timeout waiting for pulses on non-pulseio to .25 sec (was .1) to match pulseio version. No apparent impact.

To look at the memory impact I ran the test code from @brennen to look at gc.mem_free at various points with the new code and with the current master code.

It looks like the new code consumes ~500bytes additional RAM if I am interpreting this correctly. Is that OK?

new version
Adafruit CircuitPython 4.0.0-alpha.1-99-g293345119 on 2018-10-12; Adafruit Trinket M0 with samd21e18
>>> import dht_brennen
before import: 19472
after import: 16736
before init: 16736
after init: 16656
before sensor read: 16656
Temp: 67.5 F Humidity: 69.1%
after sensor read: 16064
before sensor read: 16640
Temp: 67.5 F Humidity: 69.1%
after sensor read: 16560

Here is the same test with the current master - (no RPi code )

current master
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 4.0.0-alpha.1-99-g293345119 on 2018-10-12; Adafruit Trinket M0 with samd21e18
>>>
>>> import dht_brennen
before import: 19472
after import: 17104
before init: 17104
after init: 17024
before sensor read: 17024
Temp: 67.8 F Humidity: 66.2%
after sensor read: 16432
before sensor read: 17008
Temp: 67.8 F Humidity: 64.1%
after sensor read: 16432
before sensor read: 17008
Temp: 67.8 F Humidity: 64.1%
after sensor read: 16432
before sensor read: 17008
Temp: 67.8 F Humidity: 64.2%
ladyada commented 5 years ago

just to check, did you mpycross before importing and taking the gc memory readings?

jerryneedell commented 5 years ago

@ladyada yes -- both readings were with .mpy file

jerryneedell commented 5 years ago

I tested thsi on a trinket_M0 and on a Raspberry Pi 3B + -- Note: I cannot test the "led" example since I don't have that hardware.

ladyada commented 5 years ago

@jerryneedell - thank you!

@tannewt is 500 bytes ok?

tannewt commented 5 years ago

I think its fine for now. How about moving it into a private function? That way if I ever do lazy bytecode loading it'll stay out of memory.

Are there plans to add pulseio support to Blinka? We should remove it at that time.

jerryneedell commented 5 years ago

How do I move it to a private function? do you mean create two functions - one for pulseio one for non-pulseio and make them private then call the one wanted for each case? Sorry -- still not fully comfortable in Python...

ladyada commented 5 years ago

pulseio for blinka is a long ways away

tannewt commented 5 years ago

@jerryneedell yup! and by private I mean named with a starting underscore.

jerryneedell commented 5 years ago

Ok. I’ll try it and post it for your review. Hopefully this weekend.

jerryneedell commented 5 years ago

@tannewt Is this what you are looking for re: private functions?

jerryneedell commented 5 years ago

@tannewt does this need more work?