latest update
This commit is contained in:
1 parent
5ebbc747fd
commit
4931548171
5 files changed
+441
-21
No files matched your search
@@ -0,0 +1,62 @@
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 32
|
||||
#define OLED_RESET -1 // No reset pin
|
||||
#define OLED_ADDR 0x3C
|
||||
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize I2C bus (ESP32-C3 default pins)
|
||||
Wire.begin();
|
||||
|
||||
// Scan I2C devices
|
||||
Serial.println("Scanning I2C devices...");
|
||||
// scanI2C();
|
||||
|
||||
// Initialize OLED
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
|
||||
Serial.println("SSD1306 allocation failed");
|
||||
while(1);
|
||||
}
|
||||
display.clearDisplay();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
display.setCursor(0,0);
|
||||
display.println("Hello, ESP32-C3!");
|
||||
display.display();
|
||||
}
|
||||
|
||||
void scanI2C() {
|
||||
byte error, address;
|
||||
int nDevices = 0;
|
||||
for(address = 1; address < 127; address++ ) {
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
if (error == 0) {
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address<16) Serial.print("0");
|
||||
Serial.println(address, HEX);
|
||||
nDevices++;
|
||||
} else if (error==4) {
|
||||
Serial.print("Unknown error at address 0x");
|
||||
if (address<16) Serial.print("0");
|
||||
Serial.println(address, HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found");
|
||||
else
|
||||
Serial.println("Scan complete");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Nothing to do here for this simple example
|
||||
scanI2C();
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#define OLED_WIDTH 128
|
||||
#define OLED_HEIGHT 32
|
||||
#define OLED_RESET -1
|
||||
#define OLED_ADDR 0x3C
|
||||
|
||||
// Master bus 1 (OLED): SDA 2, SCL 3
|
||||
#define SDA_1 2
|
||||
#define SCL_1 3
|
||||
|
||||
// Master bus 2 (just for demo, not slave): SDA 4, SCL 5
|
||||
#define SDA_2 4
|
||||
#define SCL_2 5
|
||||
|
||||
TwoWire I2Cone = TwoWire(0);
|
||||
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &I2Cone, OLED_RESET);
|
||||
|
||||
TwoWire I2Ctwo = TwoWire(1);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize first I2C bus (OLED)
|
||||
I2Cone.begin(SDA_1, SCL_1, 100000);
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
|
||||
Serial.println("OLED allocation failed");
|
||||
while(1);
|
||||
}
|
||||
display.clearDisplay();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
display.setCursor(0,0);
|
||||
display.println("Hello, ESP32-S3!");
|
||||
display.display();
|
||||
|
||||
// Initialize second I2C bus (just for demo, not slave)
|
||||
I2Ctwo.begin(0x55, SDA_2, SCL_2, 100000);
|
||||
// You could scan for devices or use another I2C device here
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Nothing to do here for this simple example
|
||||
delay(1000);
|
||||
}
|
||||
Reference in new issue
Block a user