[fpc-pascal] Reading AM2302 temp/humid sensor on RaspberryPi?

Alexander Hofmann alexander.hofmann at new-h.de
Thu Aug 23 11:40:18 CEST 2018


Hi,

I recently built a Weather-Station using an RPi and Lazarus/FPC, but:
anything that's not I2C or SPI (or otherwise supported within the RPi
hardware) is IHMO hard to realize. I went on and used an AVR (Arduino)
to interface the DHT11, and hooked that up to the Pi with UART (just
before dumping it completely, because it's accuracy and self-heating
issues were just to much to calibrate accurately).

Reason:

Am 23.08.2018 um 11:11 schrieb Bo Berglund:
> An alternate way would be to do an accurate sleep for a time between
> the two limits, say 48 us, after seeing the pulse rise and then
> determine the state of the I/O at that time.
> If the input is 0 then the bit is zero and if it is still 1 the bit is
> a 1...
There are commands like usleep() in Linux. But - as the typical system
on the Pi is not a realtime OS and we have the granularity of the system
scheduler, task switching, interrupts etc. pp. to account for, many
sources give it's accuracy to be only above 100 µs.
Generally I would say that, on any complex system, without considerably
effort, no loop or timer can be 100% sure not to be interrupted while
processing input data for at least a few µs, which is exactly the
problem here.

One solution might be possible, though I never digged in further (and I
suspect it's not possible for a user-land process, but I might be proven
wrong): try do define your own interrupt on the specific pin (there are
some libs for this, also in user-land) and find a hardware timer in the
Broadcom chip that is running stable enough to count a few µs. There are
timers and interrupts in the Chip (see
https://www.studica.com/blog/raspberry-pi-timer-embedded-environments).

Regards,

Alex

PS: I dumped the DHT11 and used a HTDU21D. I2C, stable and easy with FPC
;-))



More information about the fpc-pascal mailing list