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

Add additional C++ Example for AM2302-Sensor

Open hasenradball opened this issue 7 months ago • 11 comments

Add a C++ Example for AM2302-Sensor.

hasenradball avatar Dec 19 '23 07:12 hasenradball

@lurch Hi,

added in short a cpp example for the AM2302-sensor. It is possible to add to the pico examples?

It makes the main file a little more cleaner :-)

hasenradball avatar Dec 19 '23 07:12 hasenradball

As I might have mentioned before, I only provide "(hopefully) helpful comments", it's not my decision whether to merge PRs in pico-sdk or pico-examples. But my first helpful comment would be that you need to target your PR against develop instead of master :wink:

lurch avatar Dec 19 '23 07:12 lurch

@lurch Thanks for the hint. You are totally right.

:-)

hasenradball avatar Dec 19 '23 08:12 hasenradball

How is this different from the DHT22 code you've added? Or are you adding this as an example of how to use C++?

peterharperuk avatar Dec 19 '23 11:12 peterharperuk

@peterharperuk Hi Peter, the idea was to add this as C++ Example. I got the info in the morning that cpp in gerneral is possible… using classes and instatiation and all this stuff. Then I tried it directly. It makes the main file a little cleaner. Could be an example how it looks like in cpp style. One thing is different here. When call method begin() there is a check if sensor is connected.

And maybee here could also the check placed to distinguish between DHT11 or DHT22.

Best regards Frank

hasenradball avatar Dec 19 '23 13:12 hasenradball

@peterharperuk One other thing ist also improved. If you poll the sensor too often which means < 2 s . Then status is -3 and the read function is not called.

So code is slightly improved. please try it.

So in short:

  • added ìs sensor connected check
  • added check of read frequency

hasenradball avatar Dec 19 '23 13:12 hasenradball

@lurch can you please give a review for this PR.

hasenradball avatar Jan 27 '24 20:01 hasenradball

As I might have mentioned before, I only provide "(hopefully) helpful comments", it's not my decision whether to merge PRs in pico-sdk or pico-examples.

lurch avatar Jan 30 '24 10:01 lurch

@lurch I thought so because you are mentioned as reviewer, sorry for the missunderstanding.

hasenradball avatar Jan 30 '24 10:01 hasenradball

I think GitHub just treats any comment on the code as a "review" :facepalm:

lurch avatar Jan 30 '24 14:01 lurch

@peterharperuk

Added the following features:

  • better human readable error output
  • example with sensor array

Added screenshot how example looks:

20240425_16h59m19s_grim

hasenradball avatar Apr 25 '24 15:04 hasenradball