Hi there,
I'm trying to connect two ESP32 DOIT DevKit V1 boards (AliExpress) through a serial connection. My intention is for the master board to send a command over serial to the slave board, which would then start its Bluetooth functionality. This would allow a device to connect and stream audio to an external DAC via I2S.
With the test code below, I was simulating this, but it doesn't work as expected. I only see "Master -> hello" on the slave's serial monitor, but nothing appears on the master's serial monitor. However, if I change the code to use a string instead of the structured data, it works perfectly.
Any clues as to what I might be doing wrong here?
Physical Wiring:
Master TX (GPIO17) → Slave RX (GPIO16)
Master RX (GPIO16) ← Slave TX (GPIO17)
GND → GND
Master code
HardwareSerial CommSerial(2);
const int MASTER_RX_PIN = 16;
const int MASTER_TX_PIN = 17;
unsigned long last_ms = 0;
const int interval_ms = 1000;
typedef struct struct_message {
byte command;
char device_name[50];
} struct_message;
void setup() {
Serial.begin(9600);
CommSerial.begin(9600, SERIAL_8N1, MASTER_RX_PIN, MASTER_TX_PIN);
}
void loop(){
if (millis() - last_ms > interval_ms) {
last_ms = millis();
SendBTCommands(1, "Master -> hello");
}
handleBTIncomingDate();
}
void SendBTCommands(byte cmd, const char* name) {
struct_message myMessage;
myMessage.command = cmd;
strcpy(myMessage.device_name, name);
CommSerial.write((byte*)&myMessage, sizeof(myMessage));
}
void handleBTIncomingDate() {
if (CommSerial.available()) {
struct_message rx_msg_struct;
uint8_t incomingData[sizeof(rx_msg_struct)];
size_t rx_msg_length;
rx_msg_length = CommSerial.readBytesUntil('\n', incomingData, sizeof(incomingData));
if (rx_msg_length == sizeof(incomingData)) { // got a msg from a sensor
memcpy(&rx_msg_struct, incomingData, sizeof(rx_msg_struct));
Serial.println(rx_msg_struct.device_name);
}
}
}
Slave code
HardwareSerial CommSerial(2);
const int SLAVE_RX_PIN = 16;
const int SLAVE_TX_PIN = 17;
unsigned long last_ms = 0;
const int interval_ms = 1000;
typedef struct struct_message {
byte command;
char device_name[50];
} struct_message;
void setup() {
Serial.begin(9600);
CommSerial.begin(9600, SERIAL_8N1, SLAVE_RX_PIN, SLAVE_TX_PIN);
}
void loop(){
if (millis() - last_ms > interval_ms) {
last_ms = millis();
CommSerial.println("Slave -> hello");
}
handleBTIncomingDate();
}
void SendBTCommands(byte cmd, const char* name) {
struct_message myMessage;
myMessage.command = cmd;
strcpy(myMessage.device_name, name);
CommSerial.write((byte*)&myMessage, sizeof(myMessage));
}
void handleBTIncomingDate() {
if (CommSerial.available()) {
struct_message rx_msg_struct;
uint8_t incomingData[sizeof(rx_msg_struct)];
size_t rx_msg_length;
rx_msg_length = CommSerial.readBytesUntil('\n', incomingData, sizeof(incomingData));
if (rx_msg_length == sizeof(incomingData)) { // got a msg from a sensor
memcpy(&rx_msg_struct, incomingData, sizeof(rx_msg_struct));
Serial.println(rx_msg_struct.device_name);
}
}
}

