I'm trying to get telemetry data to be sent out Serial1 on the NodeMCU board. I read that TX is (by default) mapped to pin D4.

Ultimately, there will be a Raspberry that will be listening for these messages, but I don't have it yet. So to quickly test this, I connected an oscilloscope with Serial decoding to D4 and the GND of the probe to GND on the NodeMCU. The problem is I'm not getting any indication of activity out D4 when I run the following code:

Serial1.printf("some text");

Am I wiring the probe correctly? Am I missing another serial command in the sketch?

When I move to the rPI, do I GND both boards together, then write TX (D4) to RX on the rPI?


2 Answers 2


You can do Serial.swap() in setup() to swap Serial away from RX/TX pin. Serial is then on D7 as RX and D8 as TX (and you can wire some serial module there).

Bridge with jumper wire D4 pin with TX pin. the Serial1 output will go over the USB chip to Serial Monitor and you will see the prints to Serial1.

This will not disturb the flashing mode, because bootloader will still listen on standard Serial pins.


This code worked for me as Modbus slave

Required this library <ModbusRtu.h>

#include <ModbusRtu.h>
unsigned long TIME = 0;
unsigned long LASTTIME = 0;
unsigned long INTERVAL = 5000; 

int i = 0;
// data array for modbus network sharing
uint16_t au16data[16] = {
  3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, 11 };

 *  Modbus object declaration
 *  u8id : node id = 0 for master, = 1..247 for slave
 *  port : serial port
 *  u8txenpin : 0 for RS-232 and USB-FTDI 
 *               or any pin number > 1 for RS-485
Modbus slave(1,Serial,0); // this is slave @1 and RS-232 or USB-FTDI

void setup() {
  Serial.begin( 19200 ); // baud-rate at 19200
  Serial1.begin( 19200 );

void loop() {

  if ((millis() - TIME) > INTERVAL) { 

    if(i == 16){
      i = 0;

      for (int ii = 0; ii < 16; ii++)
        au16data[ii] = 0;

    au16data[i] = 1;

    TIME = millis();

  slave.poll( au16data, 16 );
  • I'm not sure how this answers the question.
    – StarCat
    Commented Mar 2, 2023 at 16:28
  • Because above mentioned type of wiring, I have done but I can't find the correct code library, after some research, I found a suitable library. So I share this platform to help others. Thank you! Commented Mar 3, 2023 at 4:23

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.