| Posted: 04:57am 04 Oct 2023 |
|
|
|
The AHT10 Humidity and Temperature Sensor is marketed as a more accurate and cheaper substitute for the DHT sensors. It uses I2C for communication so so does not require a firmware driver or CSub to use on MMBasic.
Here is some test code for the PicoMite. It can be daisy-chained from the top of an RTC module, though the pads don't align so the leads must cross over.
'Read AHT10 using System I2C
Dim Integer dat(6), addr, bytes5, n Dim Float humid, temp 'Find address I2C write &h38, 0, 1, 0 ' write zero to that adress If MM.I2C=0 Then ' check for errors addr = &H38 Else addr = &H39 EndIf Print ;" AHT10 address ";Hex$(addr,2);" Hex" Print Print "dat()" Print "0 1 2 3 4 5 40 bit word humid temp rel. humidity temp" Print
Do I2C write addr, 0, 3, &b10101100,&b00110011,0 'trigger measurement Pause 75 'wait for data I2C read addr, 1, 6, dat() 'read 6 data bytes Print Hex$(dat(0),2);" "; ' "State" byte = &H1C bytes5 = 0
For n=1 To 5 bytes5 = bytes5 + (dat(6-n)<<8*(n-1)) 'Assemble 40 bit word Print Hex$(dat(n),2);" "; 'print data bytes Next
Print ,Hex$(bytes5,10),Hex$(bytes5>>20,5), Hex$(bytes5 And (&Hfffff),5), ' humid = (bytes5>>20) / 2^20 * 100 'extract humidity humid = bytes5 / &H10000000000 * 100 'equivalent result to the line above ' temp = (bytes5 And (2^20 - 1)) / (2^20) * 200 - 50 'extract temperature temp = (bytes5 And &Hfffff)/&H100000*200-50 'equivalent result to the line above temp = Int(temp*10)*0.1 'truncate temp Print humid; "%", temp;" C" Pause 2000 ' read every 2S Loop End And the output
Saved 1277 bytes AHT10 address 38 Hex
dat() 0 1 2 3 4 5 40 bit word humid temp rel. humidity temp
1C B6 C0 45 02 1F B6C045021F B6C04 5021F 71.38713007% 12.6 C 1C B6 47 55 02 05 B647550205 B6475 50205 71.20259409% 12.5 C 1C B6 4B 05 02 1A B64B05021A B64B0 5021A 71.20822077% 12.6 C 1C B6 58 05 02 00 B658050200 B6580 50200 71.22805719% 12.5 C 1C E6 BB E5 0B F9 E6BBE50BF9 E6BBE 50BF9 90.13045458% 13 C 1C FF FF F5 25 C2 FFFFF525C2 FFFFF 525C2 99.99993531% 14.3 C 1C FF FF F5 3E 12 FFFFF53E12 FFFFF 53E12 99.99993588% 15.5 C
The humidity readings differ significantly from a DHT11, breathing on it rapidly takes it to 99.9%. Temp. response is faster too. |