Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:38 11 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : AHT10 Humidity sensoe

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1986
Posted: 12:10am 25 Jan 2025
Copy link to clipboard 
Print this post

I changed from HTU21D to AHT10 and modified my code accordingly. The AHT10 won't work,
I checked to make sure I had the correct address &H38 and found while searching that people have had trouble with AHT10 on the same bus as another device. I also have a BMP280 pressure sensor on the bus, address $H40.
Anyone had success with the AHT10 on the same bus as another device.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1986
Posted: 01:08am 25 Jan 2025
Copy link to clipboard 
Print this post

Just found this....
  Quote  While technically possible to put an AHT10 on the same I2C bus as another device, it is strongly discouraged as the AHT10 can often disrupt communication on the bus due to its unique communication protocol, making it preferable to use the AHT10 on a separate I2C bus if you need to connect multiple devices; essentially, it's best to use the AHT10 alone on its dedicated I2C bus to avoid potential issues with other devices on the same bus.


Looks like I will have to get some more HTU21D
Edited 2025-01-25 11:10 by palcal
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2606
Posted: 01:12am 25 Jan 2025
Copy link to clipboard 
Print this post

Have had no issue with AHT10 sharing System I2C with DS3231 RTC, 24C32 EEPROM and VL53LOX laser distance device at the same time. Works with all PicoMite firmware.
'AHT10 on System I2C

Dim Float humid, temp
Const AHaddr = &H38 ' AHT10 I2C address
I2C write AHaddr, 0, 3, 172, 51, 0  'trigger first AHT10 measurement to refresh data
Pause 45               'wait for data

Do
 T% = timer + 999
 AHT10
 Print "Temp ";temp;"`C","Humidity ";humid;"%"
 Do : Loop Until timer > T%
Loop

Sub AHT10
  I2C read AHaddr,1,5,dat() 'read first 5 data bytes - last one not needed.
  humid = Cint(dat(1) / 2.56)
  temp = Cint((((dat(3) And 15) << 8) + dat(4)) / 2.048 - 500) / 10
  I2C write AHaddr, 0, 3, 172, 51, 0  'trigger measurement for next read
End Sub


Edit
The AHT10 address can also be &H39 if a link is bridged. This will find it.
'Find address
I2C write &h38, 0, 1, 0  ' write zero to that adress
 If MM.I2C=0 Then             ' check for errors
   AHaddr = &H38
  Else
   AHaddr = &H39
 EndIf
Print ;" AHT10 address ";Hex$(addr,2);" Hex"
You can run this as is or add it to the setup area of the program above.
Edited 2025-01-25 12:09 by phil99

Footnote added 2025-01-25 12:14 by phil99
Correction, change last line to:-
Print ;" AHT10 address ";Hex$(AHaddr,2);" Hex"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1986
Posted: 02:06am 25 Jan 2025
Copy link to clipboard 
Print this post

I'm using MX170, would that make a difference.
I'll try it again with your code.
Thanks Phil.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2606
Posted: 04:34am 25 Jan 2025
Copy link to clipboard 
Print this post

Adapted to PIC32MX170 MM2.
Comment VL53LOX out if you don't have it.
'25/01/2025
'MM2 v5.05.05
'Read AHT10, DS3231 and VL53LOX using I2C
RTC GETTIME : Print Date$, Time$
'pin 17 = I2C clock, Pin 18 = I2C data
I2C OPEN 100, 100, PU
Dim Integer  dat(4), dst(1), dist
Dim Float humid, temp, Trtc
Const VLaddr=&H29, AHaddr = &H38   'VL53LOX & AHT10 device addresses
I2C write VLaddr,0,2,0,1          'trigger first VL53LOX measurement
I2C write AHaddr, 0, 3, 172, 51, 0  'trigger first AHT10 measurement

Print "rel. humidity    temp                                         distance"
Pause 75                   'wait for data

Sub AHT10
  I2C read AHaddr, 1, 5, dat() 'read first 5 data bytes - last one not needed.
  humid = Cint(dat(1) * 0.390625)
  temp = Cint((((dat(3) And 15) << 8) + dat(4)) * 0.48828125 - 500) * 0.1

  I2C write AHaddr, 0, 3, 172, 51, 0  'trigger measurement for next read
End Sub

Sub VL53LOX
  I2C write VLaddr,1,1,30
  I2C read VLaddr,0,2,dst()
  dist = (dst(0)<<8) + dst(1)

  I2C write VLaddr,0,2,0,1  'trigger measurement for next read
End Sub

Sub DS3231 'read DS3231 RTC temp, if installed
 Local integer Tdeg, Tdec
 On Error skip 3 : RTC GetReg 17,Tdeg : RTC GetReg 18,Tdec
 Trtc = 0.1 * Cint((Tdeg + Tdec / 256)*10) And &hFFF)
End Sub

Do
  AHT10
  DS3231
  VL53LOX 'Comment this out if you don't have it
  Print  humid;" %",, temp;" C",, "RTC Temp  ";Trtc;" C",, dist" mm"
  Pause 2000 ' read every 2S
Loop

End

> RUN
25-01-2025      15:33:49
rel. humidity    temp                                         distance
52 %            23.2 C         RTC Temp   23.3 C                89 mm
52 %            23.3 C         RTC Temp   23.3 C                91 mm
52 %            23.2 C         RTC Temp   23.3 C                88 mm
52 %            23.2 C         RTC Temp   23.3 C                89 mm
52 %            23.2 C         RTC Temp   23.3 C                88 mm
52 %            23.2 C         RTC Temp   23.3 C                88 mm
>


  Quote  ... AHT10 on the same I2C bus as another device, it is strongly discouraged .... due to its unique communication protocol
I don't understand this bit. Its communication appears to be exactly the same as any other I2C device.

The program above uses standard MMBasic commands in the standard manner. I haven't included the 24C32 EEPROM in the program but it also works with the AHT10 on the same bus at both 100kHz and 400kHz.
Edited 2025-01-25 15:27 by phil99
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1986
Posted: 05:21am 25 Jan 2025
Copy link to clipboard 
Print this post

Thanks for that Phil. Will try tomorrow.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
scruss
Regular Member

Joined: 20/09/2021
Location: Canada
Posts: 91
Posted: 01:47am 26 Jan 2025
Copy link to clipboard 
Print this post

All the AHT sensors I have used are very well-behaved
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025