BME280 and AM2315 not working together

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

BME280 and AM2315 not working together

Post by earthres »

I have a BME280 and AM2315 sensor on the same Nano (or UNO) board. When I run separately a BME280 test sketch and an AM2315 test sketch with that hardware configuration, each sensor works. But when I run the sketch below, which should provide results from both sensors, the BME280 works but the AM2315 always returns NAN (or 0, depending on how I try to read the sensor) for both temperature and relative humidity. The individual sensor tests work with or without separate pullup resistors (10K or 4.7K, it doesn't matter) on the AM2315.

There's no code in the loop function because this code is intended to be used with an on/off timer and data logging at intervals set by the timer board.

Any idea why these two sensors won't work together on the same board??

Code: Select all

// BME280_AM2315, Sept. 2022 
#include <Wire.h>
#include <Adafruit_AM2315.h>
Adafruit_AM2315 am2315; float am2315_T,am2315_H;
#include <Adafruit_BME280.h>  
Adafruit_BME280 bme; float T_BME,RH_BME,P_BME,P_inHg,elev=0.131;// km
void setup() {
  Serial.begin(9600); 
  Serial.println(F("Reading AM2315..."));
  if(am2315.begin()) Serial.println(F("AM2315 initiated")); delay(250);
  if (! am2315.readTemperatureAndHumidity(&am2315_T, &am2315_H)) {
    Serial.println(F("Failed to read data from AM2315"));
    //return;
  }  
  am2315_T=am2315.readTemperature();
  am2315_H=am2315.readHumidity();
  Serial.println(F("Reading BME280...")); 
  if(bme.begin()) Serial.println("BME280 initiated"); delay(250);  
  T_BME=bme.readTemperature();delay(10);
  RH_BME=bme.readHumidity();  delay(10); 
  P_BME=bme.readPressure();   delay(10);
  //The formula needs elevation in km, 131 m at my site.
  P_inHg=(P_BME/100.)/exp(-0.119*elev-0.0013*elev*elev);// sea level
  P_inHg*=29.921/1013.25; // to in Hg  
  Serial.print(F("Temp *C: ")); Serial.println(am2315_T);
  Serial.print(F("Hum %: ")); Serial.println(am2315_H);    
  Serial.println(F("Values..."));
  Serial.print(am2315_T,2); Serial.print(',');Serial.println(am2315_H,2); 
  Serial.print(T_BME,2); 
  Serial.print(',');Serial.print(RH_BME,2);Serial.print(',');
  Serial.print(P_BME/100.,1);Serial.print(',');
  Serial.println(P_inHg,2);   
} 
void loop() {}

User avatar
rooppoorali
 
Posts: 98
Joined: Sat Jul 16, 2022 12:04 pm

Re: BME280 and AM2315 not working together

Post by rooppoorali »

Hi, how are your devices connected to Arduino?

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: BME280 and AM2315 not working together

Post by earthres »

Both devices are connected to the SCL/SDA pins through breadboard connections. Both work properly when they are tested separately (with example code provided for each sensor) in this hardware configuration. The problem is that the AM2315 refuses to return data when the code I posted runs. When multiple I2C devices are connected I understand that there can sometimes be problems with having "too many"(?) pullup resistors active. However, as I noted, in this hardware configuration (where the Adafruit BME280 breakout board has its own built-in pullup resistors), the tests on the individual sensors work properly with or without adding pullup resistors on the AM2315 -- I've tried adding both 10K and 4.7K resistors, but it doesn't make any difference.

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: BME280 and AM2315 not working together

Post by earthres »

NOTE: The code I'm having problems with uses the now-discontinued AM2315 rather than the AM2315C, which is a completely different sensor in the same physical housing as the AM2315. But having made that clear, there is still the question of why the "old" AM2315 (which is still a very good T/RH sensor) won't work together with the BME280 in the code I gave.

User avatar
Franklin97355
 
Posts: 23903
Joined: Mon Apr 21, 2008 2:33 pm

Re: BME280 and AM2315 not working together

Post by Franklin97355 »

What is the actual output of your code? Can you post pictures of your connections, including pullups you use if you do?

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: BME280 and AM2315 not working together

Post by earthres »

Here's the output:
Reading AM2315...
Reading BME280...
Values...
AM2315 T, RH: nan,nan
BME280 T, RH, P: 31.73,71.00,1003.7,30.11

In this case I did include 10K pullup resistors on the AM2315. Because each sensor works when tested separately, there's no point to show the connections. If the connections were a problem the individual sensors wouldn't work. The question remains as to why they wont work with the code I've posted. BTW, I've also tried inserting some delays of a few seconds in case the sensors need to "warm up" somehow and this is a "one shot" read, but that doesn't make any difference.

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: BME280 and AM2315 not working together

Post by adafruit_support_bill »

Because each sensor works when tested separately, there's no point to show the connections. If the connections were a problem the individual sensors wouldn't work.
That is not necessarily true. These devices are sharing the i2c bus.

And based on the sample output you posted, it appears that neither device is successfully initialized.

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: BME280 and AM2315 not working together

Post by earthres »

BME280_AM2315.jpg
BME280_AM2315.jpg (120.8 KiB) Viewed 112 times
If neither device is successfully initialized, why does the BME280 still work? I redid the breadboard with a MetroMini. Here's the image. No pullups, but it doesn't make any difference.

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: BME280 and AM2315 not working together

Post by earthres »

I ran an I2C scanner sketch on this hardware configuration. The result shows that the AM2315, address 0x5C, is found only on the first scan. The BME280, 0x77, continues to be found. That certainly seems to be the problem, but why is this happening?? And can it be fixed??

I2C Scanner
Scanning...
I2C device found at address 0x5C !
I2C device found at address 0x77 !
done

Scanning...
I2C device found at address 0x77 !
done

Scanning...
I2C device found at address 0x77 !
done

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: BME280 and AM2315 not working together

Post by adafruit_support_bill »

What happens if you disconnect the BME280? Does it consistently see the AM2315?

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: BME280 and AM2315 not working together

Post by earthres »

No it doesn't!
I2C Scanner
Scanning...
I2C device found at address 0x5C !
done

Scanning...
No I2C devices found

Scanning...
No I2C devices found

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: BME280 and AM2315 not working together

Post by earthres »

And, yes, with the BME280 removed I put 2 10K pullups on the AM2315.

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: BME280 and AM2315 not working together

Post by adafruit_support_bill »

The AM2315 has internal 4.7L pullups, so additional pullups are not required. 10K in parallel with 4.7K give you 3.2K equivalent pullup resistance. That would not be an issue for most microcontrollers. Not sure about the AM2315. Have you tried it without the additional pullups?

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: BME280 and AM2315 not working together

Post by earthres »

hmm... the original Adafruit documentation for the AM2315 said that 2 10K pullups were required. But, as I have noted previously, it doesn't appear to make any difference. Yes, I also tried it with no pullups added and it doesn't make any difference with any of the code examples, including the I2C address scanner. Also, I have two AM2315s and they both behave the same.

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: BME280 and AM2315 not working together

Post by adafruit_support_bill »

Sorry, I forgot that we had two versions of this:
The older AM2315 did require pullups. https://www.adafruit.com/product/1293
The newer version with the 'C' suffix has them built-in. https://www.adafruit.com/product/5182
Just to be clear, are yours the AM2315C version?

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”