cancel
Showing results for 
Search instead for 
Did you mean: 

How do i connect an AM2315C - Encased I2C Temperature/Humidity Sensor to a STM32F103C8T6?

PKala.1
Associate

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");
    while (1) delay(10);
  }

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 >> 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. Unfortunately I'm using Arduino IDE because i can't program with my ST-Link because theSTM32CubeProgrammer gives error: "No STM32 target found!" but that a problem for another day, So i appreciate any help in advance.

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @PKala.1​ ,

Since the AM2315C is not from ST, I would suggest to look for help on their community. I see however you are trying to interface the module to an STM32F103C8T6 with a 5V Vdd, but the MCU works only up to 3.6V. Can you try to change the Vdd level to e.g. 3V and check?

-Eleon