Hi
I'm trying to make a thermometer with two OLEDs connected with I2C. I have changed the address of one of them, and i can display proper info on one or the other, but not on both simultaneously.
I was going through different videos, or examples, but nothing seems to work.
Maybe there is something wrong with my code, or my displays, or arduino:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress T1 = { 0x28, 0xFF, 0x91, 0x37, 0x62, 0x17, 0x04, 0xF5 };
DeviceAddress T2 = { 0x28, 0xFF, 0x77, 0xAA, 0x61, 0x17, 0x04, 0x2B };
float temp1;
float temp2;
//software i2C;
#define OLED_RESET 4
Adafruit_SSD1306 Display1(OLED_RESET);
Adafruit_SSD1306 Display2(OLED_RESET);
void setup()
{
Display2.begin(SSD1306_SWITCHCAPVCC, 0x3c);
Display2.clearDisplay();
Display2.display();
Display1.begin(SSD1306_SWITCHCAPVCC, 0x3d);
Display1.clearDisplay();
Display1.display();
sensors.begin();
}
void loop()
{
sensors.requestTemperatures(); //Polls the sensors
temp1 = sensors.getTempC(T1);
temp2 = sensors.getTempC(T2);
//Display1.setTextColor(WHITE);
//Display1.setTextSize(2);
//Display1.setCursor(0,0);
//Display1.println("Temp1");
//Display1.setTextSize(3);
//Display1.println(temp1);
//Display1.setCursor(0,30);
//Display1.setCursor(105,30);
//Display1.println("C");
//Display1.display();
//Display1.clearDisplay();
Display2.setTextColor(WHITE);
Display2.setTextSize(2);
Display2.setCursor(0,0);
Display2.println("Temp2");
Display2.setTextSize(3);
Display2.println(temp2);
Display2.setCursor(0,30);
Display2.setCursor(105,30);
Display2.println("C");
Display2.display();
Display2.clearDisplay();
}
pylon
January 25, 2019, 4:30pm
2
Have you tried using a different reset pin for the two displays?
lesept
January 25, 2019, 6:08pm
3
I've had the same problem using that OLED library and solved by using the U8G2 library, on an ESP32.
// Bus 1 : les 2 écrans
#define SDA1 19
#define SCL1 23
U8G2_SH1106_128X64_NONAME_F_SW_I2C display1(U8G2_R0, SCL1, SDA1);
U8G2_SH1106_128X64_NONAME_F_SW_I2C display2(U8G2_R0, SCL1, SDA1);
in the setup:
// Ecrans
display1.setI2CAddress(0x3C * 2);
display2.setI2CAddress(0x3D * 2);
display1.begin();
display2.begin();
Then calling the display stuff...
pylon
January 25, 2019, 6:17pm
4
U8G2_SH1106_128X64_NONAME_F_SW_I2C display1(U8G2_R0, SCL1, SDA1);
U8G2_SH1106_128X64_NONAME_F_SW_I2C display2(U8G2_R0, SCL1, SDA1);
This is not the same driver chip as the OP is using!
lesept
January 25, 2019, 6:41pm
5
That's what I said in introduction. I believe it doesn't work with his library.
Of course, he needs to keep A4 & A5 for I2C connexion
pylon
January 28, 2019, 7:03pm
6
That's what I said in introduction. I believe it doesn't work with his library.
In which introduction did you say that you were using a different chip so your solution won't work for OP's setup?
lesept
January 29, 2019, 1:15pm
7
I said:
I've had the same problem using that OLED library and solved by using the U8G2 library, on an ESP32 .
I just offered an alternative solution, that I supposed would work, based on previous experience.
Whatever, the OP seems far away now...
pylon
January 29, 2019, 7:53pm
8
I've had the same problem using that OLED library
U8G2_SH1106_128X64_NONAME_F_SW_I2C display1(U8G2_R0, SCL1, SDA1);
U8G2_SH1106_128X64_NONAME_F_SW_I2C display2(U8G2_R0, SCL1, SDA1);
If you're using a SSD1306 library for an SH1106 display it's no surprise that you got problems. That's what I meant.
But I agree, OP seems not to be interested in a solution anymore.
lesept
January 29, 2019, 8:48pm
9
You're right, I didn't pay attention to that, but it indeed worked like a charm... although I had SSD1306 displays