ESP32 to ESP32 UART Link — Esp32 Devkit C V4 simulation

Two ESP32 DevKit boards exchange serial-monitor text over UART, with pin 17 of the sender wired to pin 16 of the receiver and a shared ground.

An interactive Esp32 Devkit C V4 circuit simulation you can run free in your browser on Velxio, by emmanuelbanaheneadamnor.

Sketch code

#include <Arduino.h>

HardwareSerial SensorSerial(2);

unsigned long lastBeat = 0;

void setup() {
  Serial.begin(115200);
  SensorSerial.begin(115200, SERIAL_8N1, 16, 17);
  Serial.println("READY");
}

void loop() {
  // Heartbeat: proves this board's firmware is really running
  if (millis() - lastBeat >= 2000) {
    lastBeat = millis();
    Serial.print("alive ");
    Serial.println(millis() / 1000);
    SensorSerial.print("ping ");
    SensorSerial.println(millis() / 1000);   // sent to the other board every 2 s
  }

  // Typed characters go out to the other board
  if (Serial.available()) {
    SensorSerial.write(Serial.read());
  }

  // Anything arriving from the other board is printed with a >> marker
  if (SensorSerial.available()) {
    Serial.print(">> ");
    while (SensorSerial.available()) {
      Serial.write(SensorSerial.read());
    }
    Serial.println();
  }
}

More projects by emmanuelbanaheneadamnor