How to get an AM2305C Tempreture & Humidity Sensor to work with STM32F103C8T6 Blue Pill

Hi guys, am a little new at this so i sincirely need your help.

So I have a temperature & humidity sensor i got from http://www.aosong.com/en/products-70.html which is probably based on the AM2315C - Encased I2C Temperature/Humidity Sensor https://learn.adafruit.com/am2315-encased-i2c-temperature-humidity-sensor?view=all
I am trying to get it to read the temperature and humidity values, via an STM32F103C8T6 that am using as my microcontroller.

So whats going on is when i try this code:

#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

sensors_event_t humidity, temp;
void setup() {
  Serial.begin(115200);
  if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }
  Serial.println();
  Serial.println("Temperature C || Humidity %rH");
}
void loop() {
  aht.getEvent(&humidity, &temp);// วัดค่าอุณหภูมิและความชื้น
  Serial.print(temp.temperature);
  Serial.print("                ");
  Serial.println(humidity.relative_humidity);
  delay(1000);
}

I got from this guy on YouTube and uploaded it in my Arduino Uno; it works perfectly, tried it with my ESP 32, works flawlessly and reads accurate values, BUT when i try to use the same code with my STM32 (STM32F103C8T6) Blue Pill it says "Could not find AHT? Check wiring" probably because of this line of course

  if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");   
  }

I'm not sure if it's something to do with the I2C pins and how they are defined for each board, or maybe the STM32F103C8T6 requres a different library, am not sure. By the way i also tried adding 2 10k pull-up resistors between the SDA & SCL ( AM2315C) and the SDA & SCL (STM32F103C8T6), still no change.

My pinout is as follows:

STM32F103C8T6 >> AM2315C

5v (I tried with 3.3v too) >> VDD
GND GND
PB6 (SCL) >> I2C SCL (White Line)
PB7 (SDA) >> I2C SDA (Yellow Line)

I need this to work for a project am doing and i would apppreciate if someone pointed me in the right direction, please let me know if i need to share more info so aid in the solving process.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.