[fpc-pascal] Reading AM2302 temp/humid sensor on RaspberryPi?
Bo Berglund
bo.berglund at gmail.com
Thu Aug 23 07:17:08 CEST 2018
On Wed, 22 Aug 2018 23:19:28 +0200, Bo Berglund
<bo.berglund at gmail.com> wrote:
>I wonder if there are any demo projects around for reading the AM2302
>DHT sensor on a RaspberryPi through FreePascal?
>Any links to sample code would be appreciated.
>I have used it on an ESP-07 WiFi module (C language and Arduino
>environment) but now I would like to get it going on an RPi using
>FPC/Lazarus.
Just to clarify, if I have to go the Do It Yourself route and read the
data from the sensor directly:
I have done some relay control GPIO I/O code before using FPC on the
RPi2 which used the PiGpio.pas unit:
(http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#PiGpio_Low-level_native_pascal_unit_.28GPIO_control_instead_of_wiringPi_c_library.29)
But that code only used simple pin on/off commands at low speed and
for the DHT sensor one needs to set and clear the pins at microsecond
timing and to read the data one needs to measure pin level durations
at microsecond level. This might not easily be accomplished on a Linux
system...
The DHT sensor is started by pulling the comm line low for about 1 ms,
then releasing it. Then the DHT will send 40 bits of data where the
bit value depends on the pulse high time in a 0-1-0 sequence where the
1 time is (nominal) 26 us for data=0 and 70 us for data=1.
So one has to measure the high time for each pulse to determine the
bit value. And the resolution is in the us range...
So I wonder if there are some examples of doing that, for example
using the PiGpio unit.
But better yet would be a complete DHT driver in pascal of course...
Question: Should I ask this on the Lazarus list instead?
(There seems to be no Pascal subforum at the Raspberrypi forum...)
--
Bo Berglund
Developer in Sweden
More information about the fpc-pascal
mailing list