raspberrypi / pico-examples

BSD 3-Clause "New" or "Revised" License
2.62k stars 779 forks source link

Add additional C++ Example for AM2302-Sensor #450

Open hasenradball opened 6 months ago

hasenradball commented 6 months ago

Add a C++ Example for AM2302-Sensor.

hasenradball commented 6 months ago

@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 :-)

lurch commented 6 months ago

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:

hasenradball commented 6 months ago

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

:-)

peterharperuk commented 6 months ago

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

hasenradball commented 6 months ago

@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 commented 6 months ago

@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:

hasenradball commented 5 months ago

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

lurch commented 5 months ago

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.

hasenradball commented 5 months ago

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

lurch commented 5 months ago

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

hasenradball commented 2 months ago

@peterharperuk

Added the following features:

Added screenshot how example looks:

20240425_16h59m19s_grim