[Bugfix] Refracture of not working dht.c Example#440
[Bugfix] Refracture of not working dht.c Example#440hasenradball wants to merge 5 commits intoraspberrypi:developfrom
dht.c Example#440Conversation
- refracture dht.c example - improve functionality
- fix for negative temperature detection
|
@lurch Hi, |
|
a) I personally don't have a DHT sensor, so I'm unable to test this However I do have a good eye for detail, so I sometimes (voluntarily) leave comments which I hope are helpful 😉 It looks like there's a large chunk of code-duplication between |
|
@lurch Hi, thanks for your comment. An Additional reason is I wanted to separate the acknowledge and the data reading sequence. Frank |
|
Cool. This demonstrates why testing on actual hardware is more important than somebody (e.g. me) just naively reading the code! 😆 |
- correction into c style initialisation (line 118)
|
@lurch Hi, the most libraries of DHT Sensor don' t check the sensor status (timeout or checksum error). |
|
I did a quick test with a dht11 and it's reporting a bit hot... Sensor-status: 0 |
|
@peterharperuk I tested everything with a AM2302 (aka DHT22 Sensor). |
|
@peterharperuk could you make a short test, please? In Line 82: replace This seems the only difference between DHT22 and DHT11 regarding data reading. I this works for the DHT11 I will check with the DHT22 variant. Question: Thanks Frank :-) |
|
Yes, DHT22 woks nicely! Sensor-status: 0 |
|
Changing the sleep didn't seem to make any difference unfortunately. I have a same resistor fitted I used for DHT22. I will say that your code at least works - unlike the existing code in the repository, so it's an improvement. |
|
@peterharperuk Maybee I needed to look for an DHT11 Sensor, I thought these type of sensor are out of date and most replaced by an DHT22. So I concentrated on the DHT22 one. |
|
No worries. It might be better to remove support if they're hard to get. Any way, a quick look at the data sheet suggests to me that we should be dividing by 256 rather than 10? If I do that the numbers look better |
|
Can you put the sheet you have into this chat? If it is as you said.
|
|
@peterharperuk And for the DHT22: Ahhh now I got it. High byte is Integer data |
|
This is what I was looking at https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf |
|
@peterharperuk 3.5…5.5 V which makes the sensor not suitable for the Pi pico (3.3 V). |
- add power up time for sensor to reach stable state
|
@peterharperuk But in fact I am wondering that you got some data response with the code for the DHT22. |
|
@peterharperuk My proposal is we merge this code with respect it works only for AM2302. |
|
Hi, yes this change is fine as it is. I might push a minor change to build for DHT11 as it seems to work for me at 3v. But you can leave me to do that. Thanks for your work! |
|
@peterharperuk I checked the data sheet.
You could make a check in the setup if a dht11 or a dht22 is connected. have a nice christmas |
|
@peterharperuk |
|
I'm sure it's possible. LWIP has a webserver which stores its webpages in the binary itself (which of course lives in flash). I put an example together awhile ago https://github.com/peterharperuk/pico-examples/tree/add_httpd |
|
@peterharperuk |
|
|
@lurch thanks for your hint. But one question, if such things like fileystem and so on will be added. |
|
The Raspberry Pi Pico SDK already supports C++ https://www.raspberrypi.com/documentation/pico-sdk/index_doxygen.html |
|
@lurch so if I would I could directly switch to C++, right? |
|
@hasenradball This one also needs to be targeted against |
|
@lurch already switched. Just a question, what I have to do to setup my own projects folder for the pico? |
See Chapter 8 of https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf |
|
@lurch one question, Is there a SW Docu available for the Pico compared to this one? Frank |
The documentation for the Pico and RP2040 can be found at https://www.raspberrypi.com/documentation/microcontrollers/rp2040.html#documentation The documentation for the C/C++ SDK can be found at https://www.raspberrypi.com/documentation/pico-sdk/ The documentation for the MicroPython port can be found at https://docs.micropython.org/en/latest/library/rp2.html However the page that you linked to was for Arduino documentation, and that isn't something that Raspberry Pi officially supports, so you'll have to look elsewhere for that. |
|
@lurch Thanks |
did you already have the addition to the dht for the DHT11 sensor? Best regards |
|
@peterharperuk |
dht.c Exampledht.c Example
|
@peterharperuk Hi Peter, just a short question this example is for the Pico. |
|
For controlling "regular" GPIO pins you should continue to use |
|
@lurch Is there any hint if there is the plan or interest on the PR? |
|
Yes, we're interested in improved examples. It just needs time from someone to test and review it. |


Refracture
dht.cExampleThis code is adapted to the Pico c files and was mainly taken from here:
AM2302-sensor
Tested
Code is tesed on Arduino NANO, ESP8266, and also on Pi Pico
Screeshot