1

(I use ESP32 dev kits with Arduino api.)

My dev kit 1 is running my firmware; and I want to measure the current it draws, therefore I don't like to plug the USB in.

As I need to read the logs from the dev kit 1, I want to plug another dev kit that collects the log from the first through the UART.

The dev kit 1 firmware is as it is, but on the dev kit 2, I wrote such a thing:

#include <Arduino.h>
#include <Hardware.h>

HardwareSerial Reader();

void setup() {
    Serial.begin(115200);
    Reader.begin(115200, SERIAL_8N1, 16, 17); 

}

void loop() {
    while(Reader.available()) { 
        Serial.print(Reader.read());
    }
}

The wiring is as follows:

Dev kit 1 Wiring Dev kit 2 (sniffer)
TXD <=> RXD (16)
RXD <=> TXD (17)
GND <=> GND

But this doesn't work, that is I can't see anything on the dev kit 2 serial on my computer. Any idea?

[UPDATE] As suggested by @juraj, I simply wire TX to TX, RX to RX and GND to GND and removed the Serial.begin(115200) from the firmware running on dev kit 1. Dev kit 2 firmware is as simple as:


void setup() {
  Serial.begin(115200);
  //Serial.printf("Serial2 logger RX (%d)<=>TX & TX(%d)<=>RX @ 115200 bauds", RX, TX); Serial.println();
}

void loop() {
  static unsigned lastHeartbeat = 0;

  const unsigned now =millis();
  if (now-lastHeartbeat > 4000) {
    lastHeartbeat = now;
    Serial.println("Heartbeat");
  }
}

Note that on dev kit 1, I commented out the line Serial.begin(115200).

No kit 1 logs appears on my computer.

The wiring of this setup:

enter image description here

7
  • But this doesn't work is not a useful description of any problem ... what were you expecting to happen? ... what actually happens?
    – jsotola
    Commented Mar 10, 2022 at 17:48
  • As you just want to forward the serial data, don't use print() but write() in your sketch. Otherwise print() will interpret the data before sending and you just want to forward the raw data. With TXD and RXD I guess you mean (depending on the notation) TX0 and RX0 (or U0_TXD and U0_RXD), so GPIO1 and GPIO3 on the firmware board?
    – chrisl
    Commented Mar 10, 2022 at 17:52
  • 1
    Serial.write(Reader.read());
    – Juraj
    Commented Mar 10, 2022 at 18:16
  • 2
    if you just wire RX to RX and TX to TX the CH340 on the dev board will read it directly and send to USB. upload Blink or any other sketch without Serial.begin into the esp32
    – Juraj
    Commented Mar 10, 2022 at 18:19
  • 1
    HardwareSerial Reader(); should be HardwareSerial Reader;
    – Majenko
    Commented Mar 10, 2022 at 18:49

1 Answer 1

0

I finally managed to make it work.

The final wiring:

Kit 1 kit 2
The firmware to spy The firmare that spys
RXD 17
TXD 16
GND GND

The spying firmware uses Serial2


#define USE_READER true


#if USE_READER
#define USE_SERIAL2 true

#if USE_SERIAL2
    #define TX 17
    #define RX 16
    #define Reader Serial2
#else
    #include "SoftwareSerial.h"
    #define TX 12
    #define RX 13
    SoftwareSerial Reader;
#endif
#endif

void setup() {
  Serial.begin(115200);

#if USE_READER
  Serial.printf("Serial logger RX (%d)<=>TX & TX(%d)<=>RX @ 115200 bauds", RX, TX); Serial.println();

  #if USE_SERIAL2
  Reader.begin(115200);
  #else
  Reader.begin(115200, SWSERIAL_8N1, RX, TX, false);
  #endif
  #endif
}

void loop() {
  static unsigned lastHeartbeat = 0;

  const unsigned now =millis();
  if (now-lastHeartbeat > 4000) {
    lastHeartbeat = now;
    Serial.println("Heartbeat");
  }

  #if USE_READER
  if (Reader.available()) {
    
    Serial.write(Reader.read());  
  }
  else {
    #endif
    
    //Serial.print(".");
    delay(500);
    
    #if USE_READER
  }
  #endif
}

The spied firmware

You leave it as it is. Don't remove Serial.begin(115200);.

The breadboard photo:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.