The I2C sample at the Seeed Wiki was Software I2C.
However, I wanted to use Hardware I2C on my ESP32-C3.
According to the ESP32-C3 datasheet, I2C can be assigned to Any GPIO pins.
I was able to use the TwoWire class’s begin(int sda, int scl, uint32_t frequency = 0)
to display the OELD of the XIAO Expansion board, with using the Hardware I2C of the ESP32C3.
I would like to ask someone kind to verify this.
Below is the sketch I used.
//I2C test for XIAO ESP32C3 with Expansion board
#include <Wire.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0);
void setup() {
//setup debug port
Serial.begin(115200);//
delay(1000);
//The following constants are defined in variants/XIAO_ESP32C3/pins_arduino.h
//static const uint8_t SDA = 6;
//static const uint8_t SCL = 7;
bool var = Wire.begin(SDA,SCL); //defined with sdapin and sclpin
//for debug
if(var) Serial.println("I2C connected");
else Serial.println("I2C not connected");
u8g2.begin();
}
void loop() {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(0,15,"Hello World!"); // write something to the internal memory
u8g2.drawStr(0,30,"Hello World!");
u8g2.drawStr(0,40,"Hello World!");
u8g2.sendBuffer(); // transfer internal memory to the display
}