In Arduino IDE, install Adafruit SSD1306 library.
Open ssd1306_128x64_i2c example.
This exercise run on ESP32-C3-DevKitM-1, but the default I2C SDA pin (GPIO8) is connected to on-board RGB LED. (ref: arduino-esp32 (ESP32-C3) scan i2c device address, using custom SDA and SCL) In my exercise SDA/SCL are re-allocated to GPIO3 and GPIO2.
  Here list the modification I apply on ssd1306_128x64_i2c example,marked
  in RED:
		.
		.
		.
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
/* remarked by Erik 2021-12-13
 * On my SSD1306 128x64 OLED
 * - No RESET pin
 * - I2C Address = 0x3C
 * - I have to re-allocate I2C SDA/SCL, due to conflict with onboard RGB LED.
 * - SDA = 3
 * - SCL = 2
 */
#define SDA_pin 3
#define SCL_pin 2
#define OLED_RESET     -1 //4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C //0x3D /// ...
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display;
#define NUMFLAKES     10 // Number of snowflakes in the animation example
		.
		.
		.
void setup() {
  Serial.begin(9600);
  // by Erik 2021-12-13
  // Call Wire.setPins to assign SDA/SCL pins
  Wire.setPins(SDA_pin,SCL_pin);
  display = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
		.
		.
		.
		
No comments:
Post a Comment