I don't know your board and I don't know the ESP32 platform well. The MCU in question has 2 i2c peripherals, i.e. inside the chip there are 2 separate buses, ok.
The standard wire is configured by default on pins 21(SDA) and 22(SCL).
Serial.println(SDA);
Serial.println(SCL);
While the Wire1
object exists but is not configured, to configure it I use:
// 26(SDA1) and 27(SCL1) but other pins can be used.
bool res = Wire1.begin(26, 27, 100000);
Serial.print("res = ");
Serial.println(res);
Ok, I don't use U8x8lib.h
but the following lib from Adafruit:
I create my oled object like this:
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
Note the &Wire1 argument
I initialize and use the oled object like this:
// nel setup()
if(!oled.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("SSD1306 allocation failed");
for(;;); // Don't proceed, loop forever
}
oled.clearDisplay();
for(int16_t i=0; i<oled.width(); i+=4) {
oled.drawLine(0, 0, i, oled.height()-1, SSD1306_WHITE);
oled.display(); // Update screen with each newly-drawn line
delay(1);
}
So I use the second hardware device which is much more
fast and configurable compared to implementation of the I2c protocol via software.
I only now notice that the constructor you call is the following:
U8X8_SSD1306_128X64_NONAME_SW_I2C(uint8_t clock, uint8_t data, uint8_t reset = U8X8_PIN_NONE)
3 arguments in this order: SCL, SDA, RESET_PIN
You wrote:
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(18, 17, 21);
Then: 18(SCL), 17(SDA), 21(RESET)
But pin 21 should be SDA, in my case it is.
However I would try to use the following constructor:
U8X8_SSD1306_128X64_NONAME_2ND_HW_I2C(uint8_t reset = U8X8_PIN_NONE)
So you create your u8x8 object like this:
U8X8_SSD1306_128X64_NONAME_2ND_HW_I2C u8x8();
[Italiano]
Io non conosco la tua scheda e conosco non bene la piattaforma ESP32. La MCU in questione ha 2 periferiche i2c, cioè dentro il chip ci sono 2 bus separati, ok.
La wire standard è configurata di default sui pin 21(SDA) e 22(SCL).
Serial.println(SDA);
Serial.println(SCL);
Mentre l'oggetto Wire1
esiste ma non è configurato, per configurarlo io uso:
// non sono obbligato ad usare 26(SDA1) e 27(SCL1)
bool res = Wire1.begin(26, 27, 100000);
Serial.print("res = ");
Serial.println(res);
Ok, io non uso U8x8lib.h
ma quella di Adafruit:
Creo il mio oggetto oled così:
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
Nota l'argomento &Wire1
Inizializzo e uso l'oggetto oled così:
// nel setup()
if(!oled.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("SSD1306 allocation failed");
for(;;); // Don't proceed, loop forever
}
oled.clearDisplay();
for(int16_t i=0; i<oled.width(); i+=4) {
oled.drawLine(0, 0, i, oled.height()-1, SSD1306_WHITE);
oled.display(); // Update screen with each newly-drawn line
delay(1);
}
In questo modo uso la seconda periferica hardware che è molto più
rapida e configurabile di una implementazione del protocollo I2c via software.
Noto solo ora che il costruttore che richiami è il seguente:
U8X8_SSD1305_128X32_NONAME_SW_I2C(uint8_t clock, uint8_t data, uint8_t reset = U8X8_PIN_NONE)
3 argomenti in questo ordine: SCL, SDA, RESET_PIN
Tua hai scritto:
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(18, 17, 21);
Allora : 18(SCL), 17(SDA), 21(RESET)
Ma il pin 21 dovrebbe essere SDA, nel mio caso lo è.
Comunque io proverei ad usare il costruttore seguente:
U8X8_SSD1306_128X64_NONAME_2ND_HW_I2C(uint8_t reset = U8X8_PIN_NONE)
Quindi crei il tuo oggetto u8x8 in questo modo:
U8X8_SSD1306_128X64_NONAME_2ND_HW_I2C u8x8();
Ciao.