pico-examples icon indicating copy to clipboard operation
pico-examples copied to clipboard

[Question]: Pico gpio/dht_sensor Example not working

Open hasenradball opened this issue 8 months ago • 9 comments

Dear Pico Fellows,

the DHT Sensor example does not work. I get always bad data. It seems the code is written not robust enough, and also less comments. Is it fine for you when I provide an improved code on basis on this: AM2302-sensor

With this approach you will be also possible if the error is caused by a timeout or checksum_error.

hasenradball avatar Nov 28 '23 13:11 hasenradball

It's possible that https://github.com/raspberrypi/pico-examples/issues/423#issuecomment-1742244505 also applies here?

lurch avatar Nov 29 '23 01:11 lurch

@lurch thank for you comment. I have additionally 2 questions (e.g.: for the dht example)

  1. I generally see no usage of classes lets say, all code parts mainly placed in main.c files For example providing an dht class via include, create an object and do it object orientated. Doe this not work with the pico c SDK?

  2. I saw it mainly in the code of dht -> function read_from_dht()

  • no line of comment in the whole file if this occurs and someone searches an error in it, it might be it results in an complete new code, instead of fix this.

No clue whats the intention of this part if you look in lines 67 ... 71. Also no clue why the check if humidity > 100 and temperature >125 is there (lines 79 ... 87)? If this occurs the data received is wrong. The sensor will never send such values. So if this happens it seems the data query procedure is wrong.

hasenradball avatar Nov 29 '23 08:11 hasenradball

All the examples stick to C because that's just keeps things simple. Yes there seems to be a quite a few issues with this example. I doubt anyone has looked at it for some time. The points you raise are valid. Feel free to improve it and add some comments - or else I'll look at getting one of those sensors and doing it myself.

peterharperuk avatar Nov 29 '23 09:11 peterharperuk

Hi @peterharperuk,

thanks for your feedback I started to have a look at it. I currently reworked a DHT Class ( see here: AM2302-sensor )

So I know what happens and what should happen. I will check, but having a reviewer and discussion partner would be great! :-)

hasenradball avatar Nov 29 '23 09:11 hasenradball

@lurch @peterharperuk

I proposed a PR #440. This code is adapted to the Pico c files and was mainly taken from here: AM2302-sensor

hasenradball avatar Nov 29 '23 21:11 hasenradball

@peterharperuk Hi Peter, apologies for asking directly. Do you have an hint for an example for an Pi PicoW how to send an http request?

I want just to send some data to an server. Nothing complex.

hasenradball avatar Apr 19 '24 09:04 hasenradball

I've used the lwip http client. There's an example here...

https://github.com/raspberrypi/pico-examples/pull/385

I think this depends on the following PR's so it might not compile on its own... https://github.com/raspberrypi/pico-examples/pull/475 https://github.com/raspberrypi/pico-examples/pull/460

(I will get around to merging your PR's soon)

peterharperuk avatar Apr 19 '24 09:04 peterharperuk

Thank for fast reply I will have an look on it.

Regarding the PR's,here some nice feedback for the DHT sensor lib which was the basis for the Pico Example update: Just for you information: https://github.com/hasenradball/AM2302-Sensor/issues/10

hasenradball avatar Apr 19 '24 10:04 hasenradball