I am having 2 esp32s3 by seed studio, I am trying to communicate between the two ESPs using I2C, so what I am trying to do is that I send data to Master ESP via BLE using NRF connect app then that data is transferred to the slave ESP but in my case what is happening is that data is getting sent successfully but the slave is not receiving it
// Master (ESP32-S3) - i2c_json_master.ino
// Sends a JSON packet over I2C to a Slave ESP32-S3
#include <Wire.h>
#include <ArduinoJson.h>
// I2C address of the Slave
#define SLAVE_ADDR 0x50
void setup() {
Serial.begin(115200);
// Initialize I2C as master (SDA = 21, SCL = 22 on Seed Studio ESP32-S3)
Wire.setPins(5, 6);
Wire.setClock(100000);
Wire.begin();
delay(100);
Serial.println("I2C Master Initialized");
}
void loop() {
// Create a JSON object
StaticJsonDocument<200> doc;
doc["id"] = 123;
doc["status"] = "OK";
doc["value"] = 50.5;
// Serialize to string
String json;
serializeJson(doc, json);
// Send JSON over I2C
Wire.beginTransmission(SLAVE_ADDR);
Wire.write((const uint8_t *)json.c_str(), json.length());
byte status = Wire.endTransmission();
if(status == 0)
{
Serial.println("Data Transmission Successful");
}
Serial.print("Sent JSON: ");
Serial.println(json);
delay(2000);
}
Here is my slave code
void onReceive(int bytes) {
len = 0;
// Serial.println("Data received");
while (Wire.available() && len < sizeof(incoming) - 1) {
incoming[len++] = Wire.read();
}
incoming[len] = '\0';
dataReceived = true;
// vProcessData();
// Serial.println(incoming);
}
void setup() {
Serial.begin(115200); /* prepare for possible serial debug */
Serial.println("Reset Reason: " + String(esp_reset_reason()));
if(Wire.begin(SLAVE_ADDR, I2C_SDA, I2C_SCL, FREQ))
{
Serial.println("I2C Initialized");
}
Wire.onReceive(onReceive);
esp_task_wdt_deinit();
vInit_Preferences();
if (wifiStatus) {
wm.autoConnect();
} else if (!wifiStatus) {
vStartWifiManager();
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("Wifi Connected");
} else {
Serial.println("Wifi Not Connected");
}
lv_xiao_touch_init();
// mcp.begin_I2C(I2C_ADDR);
// mcp.pinMode(WIFI_BTN, INPUT_PULLDOWN);
// mcp.pinMode(PIR_PIN, INPUT_PULLDOWN);
// mcp.pinMode(BTN_PIN, INPUT_PULLDOWN);
lv_init();
tft.begin(); /* TFT init */
tft.setRotation(0); /* Landscape orientation, flipped */
lv_disp_draw_buf_init(&draw_buf, buf, NULL, screenWidth * screenHeight / 10);
/*Initialize the display*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
/*Change the following line to your display resolution*/
disp_drv.hor_res = screenWidth;
disp_drv.ver_res = screenHeight;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
/*Initialize the (dummy) input device driver*/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
ui_init();
}
void loop() {
// if(Wire.available())
if(dataReceived)
{
Serial.println("Data Received");
dataReceived = false;
vProcessData();
memset(incoming, 0, sizeof(incoming));
}
lv_timer_handler(); /* let the GUI do its work */
delay(5);
}