AHT25 I2C sensor with Heltec Lora ESP32-S3 V3 - Issues

Hi! I’m having trouble reading my AHT25 sensor over I2C.

The sensor itself works as I have connected it to my ESP8266 NodeMCU with SDA on D2 and SCL on D1 and I get temperature and humidity readings using this library: https://github.com/dvarrel/AHT20

All I did was change it to Wire.begin(5, 4) and that then works on my ESP8266. So this validates my sensor works.

As for the Heltec board, I have been reading everywhere about I2C on these devices and how there are two buses on the ESP32. I tried all sorts. I tried soldering to the two test pins on the back (17, 18), I tried using SDA 41 and SCL 42, I tried 21, 22, 20, 21… I tried every library I could find for the AHT25.

This I2C scanner code finds the device:
/* Originally published by Heltec-Aaron-Lee on github.
* https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series/issues/62
* Wire - I2C Scanner
*
* for example the WeMos D1 Mini I2C bus uses pins:
* D1 = SCL
* D2 = SDA
*/

#include <Wire.h>

const int SCLpin = 42;
const int SDApin = 41;

void setup()
{
Serial.begin(115200);
Serial.println(“I2C Scanner”);
Serial.println("SDA Pin = "+String(SDA));
Serial.println("SCL Pin = "+String(SCL));
Wire.begin(SDApin, SCLpin);
}

void loop()
{
  byte error, address;
  int nDevices;
  Serial.println("Scanning...");
  nDevices = 0;
  for (address = 1; address < 127; address++)
  {
    // The i2c scanner uses the return value of Write.endTransmisstion to see if a device did 
acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println(" !");
      nDevices++;
    }
    else if (error == 4)
    {
      Serial.print("Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  }
  else {
    Serial.println("Done.\n");
  }
  delay(2000);
} 

I don’t understand. I’m fairly inexperienced with electrics and I2C is new to me but why is the I2C scanner finding it but when I then try to use Wire.begin(41, 42) in the AHT25 library, it fails to ACK with my sensor on the Heltec board but the same library with Wire.begin(5, 4) works on my ESP8266 with the same sensor.

Any help would be appreciated… I spent many many hours now to get this to work. All I want is to read these readings ands end them over Lora. Lora works well but I can’t get this sensor to work!

PS: Wiring wise, it’s just a 5cm lead direct to the pins. Some pics attached (excuse my crap soldering)!

!

If you search the Heltec forums for “wifi lora v3 i2c” you will find a number of threads that discuss how to define the second I2C bus.

But of course I have. It’s not working. The I2C scanner sees the sensor on the normal bus or the second bus. Wire or Wire1. I’m just lost because I’m doing what I saw being the resolution everywhere and I still can’t read values from the sensor. All the examples fail with it not being able to do the aht.begin() even though the I2C scanner sees 0x38.

Edit: Oh, I also tried an Adafruit AM2320 which also didn’t work. I2C scanner sees it but can’t read values using any of the libs. Again, that sensor works on my ESP8266.

Can you share the code that you tried to use for the AHT25?

Sure! Using this library: https://github.com/dvarrel/AHT20

I have tried using Wire1.begin or Wire.begin. I also tried all sorts of pin combinations. The output I get is Either “AHT20 not detected. Please check wiring. Freezing.” or sometimes -50C and 0% humidity reading. The same code on the ESP8266 on pin 4 and pin 5 works with the same sensor.

/**************************************************************************``
Tests the getTemperature and getHumidity functions of the aht20 library
**************************************************************************/
#include <Wire.h>
#include <AHT20.h>

AHT20 aht20;

const int SCLpin = 42;
const int SDApin = 41;

void setup()
{
  Serial.begin(115200);
  Serial.println("Humidity AHT20 examples");

  Wire.begin(SDApin, SCLpin);
  //Check if the AHT20 will acknowledge
  if (aht20.begin() == false)
  {
    Serial.println("AHT20 not detected. Please check wiring. Freezing.");
    while(1);
  }
  Serial.println("AHT20 acknowledged.");
}

void loop()
{
  //If a new measurement is available
  if (aht20.available() == true)
  {
    //Get the new temperature and humidity value
    float temperature = aht20.getTemperature();
    float humidity = aht20.getHumidity();

    //Print the results
    Serial.print("Temperature: ");
    Serial.print(temperature, 2);
    Serial.print(" C\t");
    Serial.print("Humidity: ");
    Serial.print(humidity, 2);
    Serial.print("% RH");

    Serial.println();
  }

  //The AHT20 can respond with a reading every ~50ms. However, increased read time can cause 
  //the IC to heat around 1.0C above ambient.
  //The datasheet recommends reading every 2 seconds.
  delay(10000);
}

Can you edit your post such that it is nicely formatted within code tags?

1 Like

And how is your sensor wired to your board? (All four of them)

Sorry, how do you mean? The original post includes a picture of how I wired the AHT25 up to the Heltec board.

Small pins on the AHT25 which I soldered to and connected it to 3.3V and GND as well as SDA to 41 and SCL to 42.

This is the pinout for the AHT25

Edit: Also the sensor is picked up by the I2C scanner so wiring must be correct. Also I think there is an internal pull up resistor on the Heltec board right? I did try with two 4.7k resistors on SDA and SDL, that didn’t make a difference.

Hi blueiska,

I did experience something similar about half a year ago, also a I2C sensor that worked flawlessly on other ESP boards. I2C address detected OK, but functionality NOK.

The solution was using alternative ports for that sensor. -
Try another moving the I2C to other GPIOs.
If that also fails, try to assign other pins for clock and input/output.

Reason behind: The haltec devise also supports LoRaWan, thus parts of the system is already occupied. Obviously some registers are not available anymore.

It’s a bit of looking around and experimenting, but you’ll make it!

Good Luck!
Snookie

1 Like

Really frustrating! I spent way to long on getting this working…

I have just tried a bunch of pin combinationsn no luck. However, I have noticed something interesting.

If I keep resetting the board with the RST pin, I eventually get an ACK from the AHT library but then it proceeds to read -50C and 0% humidity, suggesting it’s not actually talking to the sensor. Could this be suggestive of something?

Humidity AHT20 examples

AHT20 not detected. Please check wiring. Freezing.

ESP-ROM:esp32s3-20210327

Build:Mar 27 2021

rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)

SPIWP:0xee

mode:DIO, clock div:1

load:0x3fce3808,len:0x44c

load:0x403c9700,len:0xbd8

load:0x403cc700,len:0x2a80

entry 0x403c98d0

Humidity AHT20 examples

AHT20 not detected. Please check wiring. Freezing.

ESP-ROM:esp32s3-20210327

Build:Mar 27 2021

rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)

SPIWP:0xee

mode:DIO, clock div:1

load:0x3fce3808,len:0x44c

load:0x403c9700,len:0xbd8

load:0x403cc700,len:0x2a80

entry 0x403c98d0

Humidity AHT20 examples

AHT20 acknowledged.

Temperature: -50.00 C Humidity: 0.00% RH

Temperature: -50.00 C Humidity: 0.00% RH

Temperature: -50.00 C Humidity: 0.00% RH

Temperature: -50.00 C Humidity: 0.00% RH

Have you considered potential differences between the AHT20 and AHT25 maybe?
You could try giving https://github.com/enjoyneering/AHTxx a shot. You can supply the SDA and SCL pin numbers to the begin() function.

I have actually and used that exact library to being with. Both of those libraries work on my ESP8266. I have even tried to edit the source code to use Wire1 and not Wire. None of that worked.

This is really strange!

Can you test the Adafruit AHT20 on a simple ESP32DEV board as proof of concept?

On my Heltec V2 runs a web server, it serves as WiFi node, one I2C sensor, one one wire temp. sensor, one relays.
I’d say, enough resources should be available for one I2C sensor on your side.

In addition, I did also kill I2C sensors and were trying for days, till I did understand, the sensor is simply not responding anymore.

Bottom line: Proof of concept with another ESP32, that the sensor still works.
Or test another I2C sensor on your heltec.

Hallelujah! :joy: The problem was literally a shitty solder on the ground pin header. I cannot believe it! I wasted a month of mine time as I assumed I had good contact to begin with. I thought my multi-meter was broken when I tested it. I can’t believe myself. Seriously… mistery solved! Thanks everyone who responded for trying and working through this with me.

All the best everyone! Check your contacts!

1 Like

40+ years and this gets me at least once a year, you are not alone, we share your pain.

And thank you for reminding us to check such things - visual inspection is never as good as testing or just a quick run around the board to touch up.

2 Likes