Arduino Pro micro Serial communication problem with Node MCU

I recently bought an ATmega32U4 based Arduino pro micro. I am using Keyboard library and interfacing with my PC via USB. I am trying to create a serial communication between Arduino pro micro and Node MCU via Rx, Tx pins(0, 1), but it isn't working i.e. not giving any output with below code on pro micro

#include <Keyboard.h>
int incomingByte;
unsigned long lastTime;

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

void loop() {
  if (Serial.available() > 0) {
    lastTime = millis();
    String payload = "";

    while (1) {
      if (millis() - lastTime > 1000)
        break;

      incomingByte = Serial.read();
      Serial.println(incomingByte);
  }
}

On node mcu there is a simple script flashed which only writes on serial, some characters in a delayed loop.

When using SoftwareSerial library with pro micro, it is working fine i.e. I can read data sent by node mcu on custom Rx Tx pins (9, 10). I tried this because I thought since pro micro is communicating with PC, original Rx and Tx pins are busy. But on some research I got to know that unlike other Arduino boards like UNO, pro micro doesn't use those for communication over USB.

Although custom serial using SoftwareSerial library is working but it is too slow and unreliable i.e. takes 2-3 seconds to pass a string of length 10. Also its unreliable because on sending bigger length string, string comes incomplete or sometimes data gets corrupted (characters shuffle).

Again this is not my main concern, if I can use original Rx Tx pins as usual on any other Arduino boards, solves my issue.

This is my circuit diagram:

Do you have a logic analyzer or oscilloscope?

If not use some other means to confirm signals are on the lines. e.g. a low power LED, or use another pin with a external interrupt. This will confirm whether you use the right pins for transmitting.

If that works try some other baud rates. You should at least get some characters. Try sending many different characters to increase the chance you receive a visible character. The baud rates are derived from the external clocks. Most baud rates cannot be created without error. With higher baud rates the error gets larger. If the boards have different crystal frequencies then some baud rates have a larger errors between them.

Thanks for your interest Klaus_K. Sorry I don't have logic analyzer or oscilloscope but surely I can use a led for testing. However since reception with SoftwareSerial on pro micro works fine, I hope it confirms that I am using the right pins for transmitting(from node MCU).

I am using baud rate of 115200 on both the boards and my pro micro has 16 MHz external oscillator. I had used pro minis before (16MHz and 115200 baud rate), and those worked fine with node MCU in similar manner. I hope there is some issue with pro micro side.

I'll test it with led and let you know the result ASAP.

The Pro Micro has two serial (UATR) connections.
One that is used for serial messages via USB, this is "Serial".
The second via the board's pins RX / TX, this is "Serial1".

As you use these RX / TX pins to exchange serial messages with Node MCU, change every "Serial" to "Serial1", like for example:
Serial.begin(115200);
to
Serial1.begin(115200);
and
incomingByte = Serial.read();
to
incomingByte = Serial1.read();

More information here:

1 Like

Rishabh8721:
Sorry I don't have logic analyzer or oscilloscope but surely I can use a led for testing.

Even though I have an oscilloscope, I just got myself a cheap 8channel 24MHz USB logic analyzer for testing. I can highly recommend you get one. They are around $10/Euro on Amazon.
There is a open source software called PulseView that makes a good impression. It is easy to use. Have a look at the following page.

https://sigrok.org/

PulseView comes with a couple of example traces to test the environment and decoders e.g. for I2C, CAN ... . So, you can test the software first without hardware.

Because the logic analyzer is streaming over USB and has no buffer memory, sometimes I had to start the capture a few times to catch the signal but for that money it is amazing.
The mini-USB cable that came with mine was crap, but I had a spare one anyway.
I had issues with the USB3 port on my laptop but the USB2 worked without any issues.

Klaus_K:
Even though I have an oscilloscope, I just got myself a cheap 8channel 24MHz USB logic analyzer for testing. I can highly recommend you get one. They are around $10/Euro on Amazon.

Thanks Klaus_K for suggesting, I will definitely try to get one soon.

uxomm:
As you use these RX / TX pins to exchange serial messages with Node MCU, change every "Serial" to "Serial1", like for example:
Serial.begin(115200);
to
Serial1.begin(115200);

Luckily I found out that last night and that worked too. Thanks for your inputs uxomm.

The Rx and Tx (0 and 1) pins on Arduino Pro Micro are defined with Serial1 so replacing Serial with Serial1 worked out for me. Thanks to all for your interest. Here is updated and working code:-

#include <Keyboard.h>
int incomingByte;
unsigned long lastTime;

void setup() {
  Serial1.begin(115200);
  Keyboard.begin();
}

void loop() {
  if (Serial1.available() > 0) {
    lastTime = millis();
    String payload = "";

    while (1) {
      if (millis() - lastTime > 1000)
        break;

      incomingByte = Serial.read();
      Serial.println(incomingByte);
  }
}

I've not used Serial1 in Serial.println because you won't get to see output in serial monitor with Serial1.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.