I have set up 2 DHT22 sensors and 2 BMP280 sensors with an Arduino Uno SMD R3 board. The DHTs are working fine and are outputting correct temperature and humidity values to the Serial monitor. The BMPs are connected via I2C and do not.
I assigned the standard address (0x77) to one of them, and set the other to 0x76 by placing a jumper between GND and SDO. However, in the Serial output, both devices are detected and connected (this is checked in the loop()
by using the Wire library), but only one of them (0x77) shows up with the correct pressure and temperature. The other address is recognized, but it seems not to be able to transmit data.
There are already pullups on the SCL and SDA lines to the +5V terminal.
Both BMP280 sensors work, by reversing their position, it is still address 0x77 that works, however, once I change the jumper, neither works. Might this be simply an issue with the breadboard or is there an address conflict somehow? Also, I have tried several values for the pullup resistors (4.7 kOhm, 10kOhm and 140kOhm), they all seem to have the same effect.
The output looks like this:
Found address: 118 (0x76)
Found address: 119 (0x77)
Found 2 device(s).
DHT22_1: hum1 = 28.00 %, temp1 = 24.80 C
DHT22_2: hum2 = 24.80 %, temp2 = 24.70 C
BMP280_0x77: t_77 = 25.83 Cp_77 = 100039.43 Pa
BMP280_0x76: t_76 = 0.00 Cp_76 = 0.00 Pa
and I used the following code:
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
// Constants
#define DHTPIN_1 5 // pin for data
#define DHTPIN_2 4
#define DHTTYPE DHT22 // what type of sensor: DHT 22 (AM2302)
DHT dht1(DHTPIN_1, DHTTYPE); // initializes sensor
DHT dht2(DHTPIN_2, DHTTYPE); // initializes sensor
Adafruit_BMP280 bm77; // I2C
Adafruit_BMP280 bm76(0x76); // I2C
// Variables
int chk;
float hum1; // stores humidity
float temp1; // stores temperature
float hum2; // stores humidity
float temp2; // stores temperature
// --- Setup --- //
void setup()
{
delay(1000);
Serial.begin(9600);
dht1.begin();
dht2.begin();
bm77.begin();
delay(500);
bm76.begin();
}
void loop()
{
byte count = 0;
Wire.begin();
for (byte i = 1; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
hum1 = dht1.readHumidity(); // reads and stores hum
temp1= dht1.readTemperature(); // reads and stores temp
hum2 = dht2.readHumidity(); // reads and stores hum
temp2= dht2.readTemperature(); // reads and stores temp
// serial output commands
delay(2000); // reading needs to be delayed by at least 2000ms
Serial.print("DHT22_1: ");
Serial.print("hum1 = ");
Serial.print(hum1);
Serial.print(" %, temp1 = ");
Serial.print(temp1);
Serial.println(" C");
Serial.print("DHT22_2: ");
Serial.print("hum2 = ");
Serial.print(hum2);
Serial.print(" %, temp2 = ");
Serial.print(temp2);
Serial.println(" C");
delay(500);
Serial.print("BMP280_0x77: ");
Serial.print("t_77 = ");
Serial.print(bm77.readTemperature());
Serial.print(" C");
Serial.print("p_77 = ");
Serial.print(bm77.readPressure());
Serial.println(" Pa");
delay(500);
Serial.print("BMP280_0x76: ");
Serial.print("t_76 = ");
Serial.print(bm76.readTemperature());
Serial.print(" C");
Serial.print("p_76 = ");
Serial.print(bm76.readPressure());
Serial.println(" Pa");
Serial.println();
}
The setup I used. red = +5V, black = GND, green = SCL, blue = SDA, yellow = DHT data lines, white = jumper between GND and SDO. Pictured is a different model of the BMP series, but in my case, I used the BMP280 and did not connect the other connectors. Edit: seems to be missing in the diagram, but of course, the positive and ground terminal are connected to the breadboard.