Help, multiple i2c buses esp32
Posted: Wed Apr 05, 2023 5:08 am
Hello, I want to use an i2c oled screen through the GPIO32 and GPIO33 ports of the esp32 and leave the GPIO21 and GPIO22 ports free for other i2c connections, but I can't get the screen to show an image, this is my code:
Code: Select all
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define I2C_FREQ 400000
#define SDA_1 21
#define SCL_1 22
#define SDA_2 33
#define SCL_2 32
TwoWire I2C_1 = TwoWire(0);
TwoWire I2C_2 = TwoWire(1);
void setup() {
I2C_1.begin(SDA_1, SCL_1, I2C_FREQ);
I2C_2.begin(SDA_2, SCL_2, I2C_FREQ);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
}
void loop() {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);
display.print("I2C Scan por Aaronfix");
display.display();
}