Compare commits

..
6 Commits
Author SHA1 Message Date
ghassan 7e11450076 Upload files to "src/i2c/esp32s3_dual_i2c" 2025-06-21 14:29:53 +03:00
ghassan 36185974eb Upload files to "src/i2c/esp32c3_master_i2c" 2025-06-21 14:29:11 +03:00
ghassan 9a7677a857 Update src/i2c/esp32c3_master_i2c/esp32c3_master_i2c.ino 2025-06-21 14:25:09 +03:00
ghassan a37ff59dc5 add files 2025-06-17 09:33:55 +03:00
ghassan b5c8409dcc Update docs/readme.md 2025-06-14 22:27:50 +03:00
ghassan ca9c816bb0 updated pictures file names 2025-06-14 22:16:46 +03:00
9 changed files with 305 additions and 117 deletions

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 KiB

File renamed without changes.
+29 -9
View File
@@ -2,7 +2,7 @@
## ESP32C3 (Master) Connection ## ESP32C3 (Master) Connection
![ESP32S3 Pinout](./images/esp32c3_pinout.png "Text to show on mouseover") ![ESP32C3 Pinout](./images/xiao_esp32c3_pinout.png "Text to show on mouseover")
``` ```
SDA_PIN = 7 SDA_PIN = 7
@@ -14,13 +14,33 @@
![ESP32S3 Pinout](./images/esp32s3_pinout.png "Text to show on mouseover") ![ESP32S3 Pinout](./images/esp32s3_pinout.png "Text to show on mouseover")
``` ```
// Red Joystic // Red Joystic Public - Slave Address
DIV_ADD = 0x10 #define DIV_ADD 0x10
SDA_PIN = 5
SCL_PIN = 4 // Blue Joystic Public - Slave Address
#define DIV_ADD 0x20
// PUBLIC -> I2C PINS
#define SDA_PIN 5
#define SCL_PIN 4
// LOCAL -> I2C PINS
#define SDA_PIN 5
#define SCL_PIN 4
// JOYSTIC
#define X 1
#define Y 2
#define B 3
// FAST LED
#define STRIP_PIN 8
#define STRIP_LEDS 16
// DOTMATRIC
#define DMX 8
#define DMY 8
#define DIN 10
#define CIN 9
// Blue Joystic
DIV_ADD = 0x20
SDA_PIN = 5
SCL_PIN = 4
``` ```
@@ -1,62 +1,77 @@
#include <Wire.h> #include <Wire.h>
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 #define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32 #define SCREEN_HEIGHT 32
#define OLED_RESET -1 // No reset pin #define OLED_RESET -1 // No reset pin
#define OLED_ADDR 0x3C #define OLED_ADDR 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() { // NEW Datatype For State
Serial.begin(115200); enum _state { NOT_READY, READY, SENDING };
// Initialize I2C bus (ESP32-C3 default pins) // Variables
Wire.begin(); _state state = NOT_READY;
// Scan I2C devices void setup() {
Serial.println("Scanning I2C devices...");
// scanI2C(); // Serial
Serial.begin(115200);
// Initialize OLED
if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) { // Initialize I2C bus (ESP32-C3 default pins)
Serial.println("SSD1306 allocation failed"); Wire.begin();
while(1);
} // Scan I2C devices
display.clearDisplay(); Serial.println("Scanning I2C devices...");
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE); // Scan I2C
display.setCursor(0,0); scanI2C();
display.println("Hello, ESP32-C3!");
display.display(); // Initialize OLED
} if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
Serial.println("SSD1306 allocation failed");
void scanI2C() { while(1);
byte error, address; }
int nDevices = 0;
for(address = 1; address < 127; address++ ) { // Print On Display
Wire.beginTransmission(address); oled_write("Hello, ESP32-C3!");
error = Wire.endTransmission();
if (error == 0) { }
Serial.print("I2C device found at address 0x");
if (address<16) Serial.print("0"); void loop() {
Serial.println(address, HEX);
nDevices++; // Send Tex Message To Slave
} else if (error==4) { i2c_send_string(0x55, Question("String Message"));
Serial.print("Unknown error at address 0x");
if (address<16) Serial.print("0"); // Request Data
Serial.println(address, HEX); Wire.requestFrom(0x55, 1);
}
} // Read Data Available
if (nDevices == 0) if(Wire.available()) {
Serial.println("No I2C devices found"); if(char(Wire.read()) == 'N') {
else Serial.println("Requested Data : Not Ready");
Serial.println("Scan complete"); state = NOT_READY;
} } else {
Serial.println("Requested Data : Ready");
void loop() { state = READY;
// Nothing to do here for this simple example }
scanI2C(); }
delay(1000);
} // Request Data
Wire.requestFrom(0x55, 6);
// Prepare 6 Bytes Of Data
uint8_t data[6];
// Read Data Available
if(Wire.available()) {
for(int i=0; i<6; i++) {
data[i] = Wire.read();
Serial.print(char(data[i]));
}
Serial.println();
}
}
+51
View File
@@ -0,0 +1,51 @@
// Question
String Question(String Message) {
Serial.print(Message + " : ");
while(!Serial.available());
Message = Serial.readStringUntil('\n');
while(Serial.available()) Serial.read();
Message.trim();
Serial.println(Message);
return Message;
}
// OLED Display
void oled_write(String message) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(message);
display.display();
}
// I2C Scanner
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");
}
@@ -0,0 +1,22 @@
// This Function If Called Sends A Text Message Via I2C
void i2c_send_string(uint8_t Slave, String message) {
// Sending Data
Wire.beginTransmission(Slave);
// First Data Byte Is Length
Wire.write(message.length());
// Second Send Data One Byte At A Time
for(int i=0; i<message.length(); i++) {
// Send String Bits
Wire.write(message[i]);
}
// Finally Closing Transmission
Wire.endTransmission();
}
+65 -46
View File
@@ -1,47 +1,66 @@
#include <Wire.h> #include <Wire.h>
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#define OLED_WIDTH 128 #define OLED_WIDTH 128
#define OLED_HEIGHT 32 #define OLED_HEIGHT 32
#define OLED_RESET -1 #define OLED_RESET -1
#define OLED_ADDR 0x3C #define OLED_ADDR 0x3C
// Master bus 1 (OLED): SDA 2, SCL 3 // Master bus 1 (OLED): SDA 2, SCL 3
#define SDA_1 2 #define SDA_1 2
#define SCL_1 3 #define SCL_1 3
// Master bus 2 (just for demo, not slave): SDA 4, SCL 5 // Master bus 2 (just for demo, not slave): SDA 4, SCL 5
#define SDA_2 4 #define SDA_2 4
#define SCL_2 5 #define SCL_2 5
TwoWire I2Cone = TwoWire(0); // Master I2C
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &I2Cone, OLED_RESET); TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1); // OLED Display
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &I2Cone, OLED_RESET);
void setup() {
Serial.begin(115200); // Slave I2C
TwoWire I2Ctwo = TwoWire(1);
// Initialize first I2C bus (OLED)
I2Cone.begin(SDA_1, SCL_1, 100000); // NEW Datatype For State
if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) { enum _state { NOT_READY, READY, SENDING };
Serial.println("OLED allocation failed");
while(1); // Variables
} // _state state = NOT_READY;
display.clearDisplay(); _state state = READY;
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0); void setup() {
display.println("Hello, ESP32-S3!");
display.display(); Serial.begin(115200);
Serial.println();
// Initialize second I2C bus (just for demo, not slave) Serial.println("ESP32S3 System Started !");
I2Ctwo.begin(0x55, SDA_2, SCL_2, 100000);
// You could scan for devices or use another I2C device here // Initialize first I2C bus (OLED)
} I2Cone.begin(SDA_1, SCL_1, 100000);
void loop() { // Starting OLED
// Nothing to do here for this simple example if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
delay(1000); Serial.println("OLED allocation failed");
while(1);
}
// Display OLED Message
oled_write("Hello, ESP32-S3!");
// On Receive Data
I2Ctwo.onReceive(i2c_received);
I2Ctwo.onRequest(i2c_request);
// 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);
} }
+9
View File
@@ -0,0 +1,9 @@
// OLED Display
void oled_write(String message) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(message);
display.display();
}
@@ -0,0 +1,52 @@
void i2c_received(int data) {
// Read If Available
if(I2Ctwo.available()) {
// Calculate Data Length
uint8_t datalength = I2Ctwo.read();
// Creating Data Array Based On Data Length
uint8_t data[datalength];
// Data Buffer
String message;
// Assembling Message Data
for(int i=0; i<datalength; i++) {
message += char(I2Ctwo.read());
}
// Printe Received Message
Serial.println("Message : " + message);
}
}
void i2c_request() {
if(state == READY) {
I2Ctwo.write(char('Y'));
Serial.println("Requested Data : Ready");
state = SENDING;
} else if(state == SENDING) {
uint8_t data[6] = { 'H', 'E', 'L', 'L', 'O', 'W' };
for(int i=0; i<6; i++) {
I2Ctwo.write(data[i]);
Serial.print(data[i]);
}
Serial.println("Requested Data : Ready -> Sending");
state = NOT_READY;
} else {
I2Ctwo.write(char('N'));
Serial.println("Requested Data : Not Ready");
state = NOT_READY;
}
}