I recently bought an ATmega32U4 based Arduino Pro micro. I am using the Keyboard library and interfacing with my PC via USB.
I am trying to create a serial communication between the Arduino Pro micro and a NodeMCU via Rx, Tx pins (0, 1), but it isn't working i.e. not giving any output with the code below on the 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 the NodeMCU there is a simple script flashed which only writes on serial some characters in a delayed loop.
When using the SoftwareSerial library with the Pro micro, it is working fine i.e. I can read data sent by the NodeMCU on custom Rx, Tx pins (9, 10). I tried this because I thought since Pro micro is communicating with a PC, the original Rx and Tx pins are busy. But after some research I got to know that unlike other Arduino boards like the UNO, the Pro micro doesn't use those for communication over USB.
Although custom serial using SoftwareSerial library is working, it is too slow and unreliable i.e. it takes 2-3 seconds to pass a string of length 10. Also its unreliable because on sending bigger length strings, the strings arrive incomplete or sometimes the 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, it solves my issue.
This is my circuit diagram:
Serial
device is usually the USB serial connection, whether or not that is controlled by pins 0/1. For pins 0/1 with a native USB connection you need to useSerial1
. I think. It's been a while since I used an Arduino with native USB...