My project uses Arduino MKR zero board and ESP32 S3 dev kit 1. For serial communication, I tried to connect the RX pin of MKR to the TX pin of ESP32 and the TX pin of MKR to ESP32's RX pin, have a common ground.
As a primary stage, I tried to send a message "Hello World" from the MRK board to ESP32. The codes I used are given below,
code for MKRzero board:
void setup() {
Serial.begin(9600); // Set the baud rate to 9600
//while (!Serial);
}
void loop() {
// Send "Hello, World!" message via UART
Serial.println("Hello World");
// Other loop code
delay(1000);
}
code for ESP32 S3:
#define RX_PIN 14
#define TX_PIN 13
void setup() {
Serial.begin(115200); // Set the baud rate to 9600
// Configure RX and TX pins
Serial2.begin(9600, SERIAL_8N1, 13, 14); // Replace RX_PIN and TX_PIN with the appropriate pin numbers
}
void loop() {
//if (Serial2.available())
{
// Read the message from the MKR Zero
String receivedMessage = Serial2.readStringUntil('\n');
Serial.print("Received message: ");
Serial.println(receivedMessage);
}
// Other processing or actions with the received message
delay(1000);
}
with these codes, it is not giving the expected result. I am unsure what the issue is, whether with the code or the setup. If someone is familiar with this can you please help...
connections are (three wires used for connection)
RX (MKR) -- TX (ESP)
TX (MKR) -- RX (ESP)
GND(MKR) -- GND(ESP)
for the MKR code in the serial monitor, it's showing hello world and for the ESP code, in the serial monitor, it's showing "message received" only. not the hello world message.
example of communication between a MKRFOX and ESP32 may help
MKRFOX code
// Arduino MKRFOX hardware serial1 port Serial1 on Tx pin 14 Rx pin 13
// on the MKRFOX Serial is used for USB communications and Serial1 is a hardware serial port on Tx pin 14 Rx pin 13
// NOTE: MKRFOX uses 3.3V logic
// - if commected to UNO 5V logic use a voltage divider 2.2K to ground 1K to UNO Tx
// MKRFOX pin 14 is TX
// MKRFOX pin 13 is Rx
// for loopback test connect pin 13 to pin 14
void setup() {
Serial.begin(115200); // initialise serial monitor port
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial1.begin(115200); // initialise Serial1
Serial.println();
Serial.write("Arduino MKRFOX Serial1 test - for loopback test connect pin 13 to pin 14\n");
}
void loop() {
if (Serial1.available()) // read from Serial1 output to Serial
Serial.write(Serial1.read());
if (Serial.available()) { // read from Serial outut to Serial1
int inByte = Serial.read();
//Serial.write(inByte); // local echo if required
Serial1.write(inByte);
}
}
ESP32 code
// ESP32 Serial1 test - for loopback test connect pins 16 and 17
#define RXD1 16
#define TXD1 17
void setup() {
// initialize both serial ports:
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);
Serial.println();
Serial.println("\n\nESP32 serial1 test Rx pin 16 Tx pin 17");
Serial.write(" for loopback test connect pin 16 to pin 17\n");
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
//Serial.write(inByte);
Serial1.write(inByte);
}
}
for communication between the boards connect
MKRFOX pin 14 to ESP32 pin 16
MKRFOX pin 13 to ESP32 pin 17