(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:
1 Answer 1
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);
.
But this doesn't work
is not a useful description of any problem ... what were you expecting to happen? ... what actually happens?print()
butwrite()
in your sketch. Otherwiseprint()
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?Serial.write(Reader.read());
HardwareSerial Reader();
should beHardwareSerial Reader;