we found that the i2c pins of the master was swapped

This commit is contained in:
Ghassan Yusuf 2025-06-11 00:04:42 +03:00
parent 7e476e1e67
commit 5ebbc747fd
5 changed files with 102 additions and 3 deletions

View File

@ -5,8 +5,8 @@
![ESP32S3 Pinout](./images/esp32c3_pinout.png "Text to show on mouseover") ![ESP32S3 Pinout](./images/esp32c3_pinout.png "Text to show on mouseover")
``` ```
SDA_PIN = 6 SDA_PIN = 7
SCL_PIN = 7 SCL_PIN = 6
``` ```
## ESP32S3 (Slaves) Connection ## ESP32S3 (Slaves) Connection

View File

@ -1,4 +1,4 @@
// MAster // Master
#include "dice.h" // Dice Function #include "dice.h" // Dice Function
#include "header.h" // Player Data Types #include "header.h" // Player Data Types

View File

@ -0,0 +1,43 @@
#include <Wire.h>
// Custom I2C pins for ESP32C3
#define I2C_SDA_PIN 7
#define I2C_SCL_PIN 6
void setup() {
Serial.begin(115200);
Wire.setPins(I2C_SDA_PIN, I2C_SCL_PIN);
Wire.begin();
Serial.println("Master ready. Scanning for slaves...");
scanI2C();
}
void loop() {
if (Serial.available()) {
int value = Serial.parseInt();
if (value >= 0 && value <= 255) {
Serial.print("Sending value: ");
Serial.println(value);
Wire.beginTransmission(0x10); // Change to 0x20 for the second slave
Wire.write(value);
Wire.endTransmission();
}
}
}
void scanI2C() {
byte error, address;
int nDevices = 0;
Serial.println("Scanning I2C bus...");
for(address = 1; address < 127; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
Serial.println(address, HEX);
nDevices++;
}
}
if (nDevices == 0)
Serial.println("No I2C devices found");
}

View File

@ -0,0 +1,28 @@
#include <Wire.h>
// Custom I2C pins for ESP32-S3
#define I2C_SDA_PIN 5
#define I2C_SCL_PIN 4
#define SLAVE_ADDR 0x20 // Use 0x20 for the second slave
uint8_t receivedValue = 0;
void setup() {
Serial.begin(115200);
Wire.setPins(I2C_SDA_PIN, I2C_SCL_PIN);
Wire.begin(SLAVE_ADDR);
Wire.onReceive(receiveEvent);
Serial.print("Slave ready at address 0x20");
}
void loop() {
// Nothing to do here; all logic is in callbacks
}
void receiveEvent(int numBytes) {
if (Wire.available()) {
receivedValue = Wire.read();
Serial.print("Received value: ");
Serial.println(receivedValue);
}
}

View File

@ -0,0 +1,28 @@
#include <Wire.h>
// Custom I2C pins for ESP32-S3
#define I2C_SDA_PIN 5
#define I2C_SCL_PIN 4
#define SLAVE_ADDR 0x10 // Use 0x20 for the second slave
uint8_t receivedValue = 0;
void setup() {
Serial.begin(115200);
Wire.setPins(I2C_SDA_PIN, I2C_SCL_PIN);
Wire.begin(SLAVE_ADDR);
Wire.onReceive(receiveEvent);
Serial.print("Slave ready at address 0x10");
}
void loop() {
// Nothing to do here; all logic is in callbacks
}
void receiveEvent(int numBytes) {
if (Wire.available()) {
receivedValue = Wire.read();
Serial.print("Received value: ");
Serial.println(receivedValue);
}
}