we found that the i2c pins of the master was swapped
This commit is contained in:
parent
7e476e1e67
commit
5ebbc747fd
@ -5,8 +5,8 @@
|
||||

|
||||
|
||||
```
|
||||
SDA_PIN = 6
|
||||
SCL_PIN = 7
|
||||
SDA_PIN = 7
|
||||
SCL_PIN = 6
|
||||
```
|
||||
|
||||
## ESP32S3 (Slaves) Connection
|
||||
|
@ -1,4 +1,4 @@
|
||||
// MAster
|
||||
// Master
|
||||
|
||||
#include "dice.h" // Dice Function
|
||||
#include "header.h" // Player Data Types
|
||||
|
43
src/game/i2c_master_test/i2c_master_test.ino
Normal file
43
src/game/i2c_master_test/i2c_master_test.ino
Normal 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");
|
||||
}
|
28
src/joystic/i2c_blue_joystic/i2c_blue_joystic.ino
Normal file
28
src/joystic/i2c_blue_joystic/i2c_blue_joystic.ino
Normal 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);
|
||||
}
|
||||
}
|
28
src/joystic/i2c_red_joystic/i2c_red_joystic.ino
Normal file
28
src/joystic/i2c_red_joystic/i2c_red_joystic.ino
Normal 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user