User Tools

Site Tools


en:pfw:dht22

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:pfw:dht22 [2025-04-26 10:18] – [Numerical representation of the measured values] mkaen:pfw:dht22 [2025-06-27 12:05] (current) – [Implementation for RP2040 using a PIO block] mka
Line 1: Line 1:
 {{pfw:full-banner.png?500 }} {{pfw:full-banner.png?500 }}
-====== DHT22 Protocol ====== +====== DHT22 ======
-===== Introduction ===== +
 The DHT22 module is a low-cost digital temperature and humidity sensor. It utilizes a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal via a single data pin. It's known for its wider measurement range and higher accuracy compared to its predecessor, the DHT11. The DHT22 module is a low-cost digital temperature and humidity sensor. It utilizes a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal via a single data pin. It's known for its wider measurement range and higher accuracy compared to its predecessor, the DHT11.
  
Line 16: Line 14:
 * Suitable for indoor environmental monitoring, weather stations, and HVAC systems. * Suitable for indoor environmental monitoring, weather stations, and HVAC systems.
  
-===== SDA =====+===== SDA Protocol =====
  
 The DHT22 communicates using a **proprietary single-wire serial protocol**. Here's a breakdown of the process: The DHT22 communicates using a **proprietary single-wire serial protocol**. Here's a breakdown of the process:
Line 43: Line 41:
 {{ :en:pfw:dht22-response.png?nolink |Screenshot of the 40-bit response on the SDA line. (PulsView Logic Analyser)}} {{ :en:pfw:dht22-response.png?nolink |Screenshot of the 40-bit response on the SDA line. (PulsView Logic Analyser)}}
  
-===== Implementation ===== + 
-==== Testing with a Logic Analyser (PulsView) ====+===== Testing with a Logic Analyser (PulsView) =====
  
 Pin P1.0 is bidirectional. It sends the start pulse and then receives the 40 data bits from the sensor module. Pin P1.0 is bidirectional. It sends the start pulse and then receives the 40 data bits from the sensor module.
Line 58: Line 56:
 {{ :en:pfw:dht22-bit_lesen_mit_2xmoon.png?nolink |The timing is critical. So, it's correct now. Here we read a "0"}} {{ :en:pfw:dht22-bit_lesen_mit_2xmoon.png?nolink |The timing is critical. So, it's correct now. Here we read a "0"}}
  
-==== Pseudocode ====+====== Implementation for TI's Launchpad ======
  
-<code> +This program was used to test DHT22 modules before installationThe DHT22 modules were tested for functionality at room temperature, pre-sorted in this wayand then frozen in a bag of moist sand in the freezer and tested again. One module displayed incorrect temperature values ​​in frost conditions, the display of negative values ​​did not comply with the specifications.
-Function: Pio    ( -- )  \ set port I/O functionSDA --> P1.0  +
-Function: wakeup ( -- )  \ notify sensor to prepare the data +
-Function: @data  ( -- sun moon hum tmp chk chksum )  \ get sensor data +
-  get response time of sensor, store in register 'sun' (just for testing) +
-  get startpulse durationstore in register 'moon' +
-  40 loop  +
-     read bit using 'moon' based delay  +
-     lshift bit into array xx yy zz +
-  08 loop        +
-     lshift array  \ adjust xx yy zz --> hum tmp chk  +
-  calculate chksum +
-Function: (dht22)  ( -- sun moon hum tmp chk chksum ) \ wake up and read sensor +
-Function:  dht22   ( -- )  \ print temperatur and humidity +
-Function:  test    ( n -- ) \ multiple readings   +
-    n loop  dht22 +
-</code>+
  
-==== Numerical representation of the measured values ====+[[en:pfw:dht22-msp430g2553-noforth|DHT22 for Launchpad MSP430G2553 and noForth]]
  
-=== Humidity === 
  
-The first 16 bits coming from the DHT22 are the relative humidity in tenths of a percent. They can be processed directly with the 16-bit noForth and correspond to a positive integer. Rounded to whole digits for display purposes. +====== Implementation for RP2040 ======
-Here is an excerpt from the noforth source code:+
  
-<code> +[[en:pfw:dht22-rp2040-nofortht|DHT22 for the Raspberry Pi Pico Board RP2040 and noForth t]] using a PIO block
-.hum ( hum -- )   10 / . ." %rel" space  ;   +
-</code>+
  
-=== Temperature === +PIO stands for //Programmable Input Output//. You can program the PIO blocks with the [[en:pfw:assemblers_pio-assembler|noforth t PIO Assembler]]. 
- +====== Background Information ======
-Die nächsten 16-Bit sind die Temperatur in zehntel Grad Celsius. +
- +
-Temperaturen ab null Grad und höher können mit dem 16-Bit noForth unmittelbar verarbeitet werden, sie entsprechen einer positiven ganzen Zahl. +
- +
-Temperaturen unter null Grad stellt der DHT22 so dar: Das MSB der 16-Bit ist gesetzt, doch ansonsten wird die Temperatur ganzzahlig 'positiv' angegeben. Dieses Zahlenformat //entspricht nicht// dem Zweierkomplement des noForthHier muss zunächst das MSB ausgewetet werden um das Vorzeichen zu bestimmen.  Danach kann der Messwert wie eine positive ganze Zahl weiter verarbeit werden. Zur Ausgabe wird das Vorzeichen vorangestellt. Die ganzen Grad werden links vom Dezcimalpunkt, die Zehntel rechts davon abgebildet. Die Einheit °C wird angegeben.  +
- +
-<code> +
-: .tmp ( tmp -- )   +
-  dup hx 8000 and hx 8000 =  \ check MSB +
-      if [char] -  +
-      else [char] +  +
-      then emit +
-  hx 7fff and ( tmp -- +tmp )    \ reset MSB +
-  10 /mod 3 .r [char] . emit .    \ --> TTT.T +
-  [char] f decemit  [char] C emit  \ print °C +
-  space +
-  ;   +
- </code> +
- +
- +
-==== Source Code - and what it was used for.==== +
- +
-[[en:pfw:dht22-msp430g2553-noforth|DHT22 with Launchpad MSP430G2553 and noForth]] +
- +
-This program was used to test DHT22 modules before installation. The DHT22 modules were tested for functionality at room temperature, pre-sorted in this way, and then frozen in a bag of moist sand in the freezer and tested again. One module displayed incorrect temperature values ​​in frost conditions. The display of negative values ​​did not comply with the specifications+
-==== More information on the MSP430G2553 ====+
  
 +  * How this was discovered: [[en:pfw:dht22tmpformat|The temperature format of the DHT22]]
   * [[https://www.ti.com/lit/ug/slau144j/slau144j.pdf|MSP430x2xx Family guide SLAU144J.PDF]]   * [[https://www.ti.com/lit/ug/slau144j/slau144j.pdf|MSP430x2xx Family guide SLAU144J.PDF]]
   * [[https://www.ti.com/lit/ds/symlink/msp430g2553.pdf|MSP430G2553 datasheet SLAS735J.PDF]], port data on page 49ff   * [[https://www.ti.com/lit/ds/symlink/msp430g2553.pdf|MSP430G2553 datasheet SLAS735J.PDF]], port data on page 49ff
 +  * [[https://home.hccnet.nl/anij/nof/noforth.html| noforth.html - find your version, docmentation,  tool.f and asm.f here.]] All about noForth.
 +  * [[en:pfw:whatisapioblock|What is a PIO block?]]
  
-==== All about noForth ==== +====== Aids ======
- +
-[[https://home.hccnet.nl/anij/nof/noforth.html| noforth.html - find your version, docmentation,  tool.f and asm.f here.]] +
- +
---- +
- +
-=== Source code editor ===+
  
 +MK:\\
 I like //Notepad Next// for Linux, a cross-platform, reimplementation of //Notepad++//. I like //Notepad Next// for Linux, a cross-platform, reimplementation of //Notepad++//.
-https://github.com/dail8859/NotepadNext +https://github.com/dail8859/NotepadNext\\
- +
-=== Terminal === +
 To work with the embedded noForth system I use //e4thcom// by Manfred Mahlow. To work with the embedded noForth system I use //e4thcom// by Manfred Mahlow.
-https://wiki.forth-ev.de/doku.php/projects:e4thcom +https://wiki.forth-ev.de/doku.php/projects:e4thcom\\ 
- +Sometimes I also use Windows and Teraterm, for example, to log longer MCU outputs to a file. I also prefer it for testing parts of the source code using copy and paste.\\ 
-=== Logic Analyser === +In this project I used a Logic Analyzer by AZDelivery8 CH, 24MHz. (Amazon)\\
- +
-AZDelivery Logic Analyzer 8 CH, 24MHz. (Amazon)\\+
 //PulseView// is a Qt-based logic analyzer and oscilloscope GUI for sigrok. //PulseView// is a Qt-based logic analyzer and oscilloscope GUI for sigrok.
- 
---- 
  
en/pfw/dht22.1745655480.txt.gz · Last modified: 2025-04-26 10:18 by mka