I have an OLED display that is 128x128 and uses the SH1107 driver IC, and BMP388 pressure sensor and I'm using an Arduino UNO. They both use I2C but for some reason I cannot get them to both work at the same time, if I comment certain parts out that involve the pressure sensor the OLED display will work fine and display all the other things i did earlier, if I leave in the pressure sensor related code, everything works fine in the serial monitor, however the OLED goes black and doesnt work, I've checked multiple things such as:
- Making sure they have different addresses, the OLED is (0x3C) and the sensor is (0x77).
- Trying new sketches that dont involve the other sensors.
- Tried to define the addresses of each.
-The last thing I tried was using HW but wasnt able to figure it out.
#include <Arduino.h>
#include <U8g2lib.h>
#include "DHT.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP3XX bmp;
#define OLED_SDA A4
#define OLED_SCL A5
U8G2_SH1107_128X128_1_SW_I2C u8g2 (U8G2_R0, OLED_SCL, OLED_SDA, U8X8_PIN_NONE);
void draw(void) {
// // graphic commands to redraw the complete screen should be placed here
float h = dht.readHumidity();
float t = dht.readTemperature();
u8g2.setFont(u8g2_font_ncenB10_tr);
u8g2.drawStr(35,30,"T: ");
u8g2.setCursor(55, 30); u8g2.print(t); u8g2.print(" °C");
u8g2.drawStr(35,60,"H:");
u8g2.setCursor(55, 60); u8g2.print(h); u8g2.print(" %");
u8g2.drawStr(35,90,"P: ");
u8g2.setCursor(55, 90); u8g2.print(bmp.pressure / 100.0); u8g2.print(" hPa");
u8g2.drawStr(35,120,"UV Level: ");
}
void setup(void) {
u8g2.begin();
dht.begin();
//Serial.begin(9600);
//while (!Serial);
//Serial.println();
//Serial.println("Checking if all sensors connected properly and can all give reading on serial monitor");
//if (!bmp.begin_I2C()) { // hardware I2C mode, can pass in address & alt Wire
// Serial.println("Could not find a valid BMP3 sensor, check wiring!");
// while (1);
//}
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}
void loop(void) {
float h = dht.readHumidity();
float t = dht.readTemperature();
// Wait a few seconds between measurements.
delay(2000);
// if (! bmp.performReading()) {
// Serial.println("Failed to perform reading :(");
// return;
//}
//Serial.print("Temp = ");
//Serial.print(t);
//Serial.println(" C");
//Serial.print("Humidity = ");
//Serial.print(h);
//Serial.println(" %");
//Serial.print("Pressure = ");
//Serial.print(bmp.pressure / 100.0);
//Serial.println(" hPa");
//Serial.println();
u8g2.firstPage();
do {
draw();
} while ( u8g2.nextPage() );
delay(1000);
}
