diff --git a/docs/readme.md b/docs/readme.md index 4b3770e..1fe95e8 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -5,8 +5,8 @@ ![ESP32S3 Pinout](./images/esp32c3_pinout.png "Text to show on mouseover") ``` - SDA_PIN = 6 - SCL_PIN = 7 + SDA_PIN = 7 + SCL_PIN = 6 ``` ## ESP32S3 (Slaves) Connection diff --git a/src/game/code/code.ino b/src/game/code/code.ino index 9ac3e84..fbb90b0 100644 --- a/src/game/code/code.ino +++ b/src/game/code/code.ino @@ -1,4 +1,4 @@ -// MAster +// Master #include "dice.h" // Dice Function #include "header.h" // Player Data Types diff --git a/src/game/i2c_master_test/i2c_master_test.ino b/src/game/i2c_master_test/i2c_master_test.ino new file mode 100644 index 0000000..bf15b49 --- /dev/null +++ b/src/game/i2c_master_test/i2c_master_test.ino @@ -0,0 +1,43 @@ + #include + + // 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"); + } \ No newline at end of file diff --git a/src/joystic/i2c_blue_joystic/i2c_blue_joystic.ino b/src/joystic/i2c_blue_joystic/i2c_blue_joystic.ino new file mode 100644 index 0000000..a47359d --- /dev/null +++ b/src/joystic/i2c_blue_joystic/i2c_blue_joystic.ino @@ -0,0 +1,28 @@ + #include + + // 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); + } + } diff --git a/src/joystic/i2c_red_joystic/i2c_red_joystic.ino b/src/joystic/i2c_red_joystic/i2c_red_joystic.ino new file mode 100644 index 0000000..804ca60 --- /dev/null +++ b/src/joystic/i2c_red_joystic/i2c_red_joystic.ino @@ -0,0 +1,28 @@ + #include + + // 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); + } + }