Send data via UART from ESP8266 (NodeMCU) to Arduino
I want to send data from my ESP8266 device to Arduino Uno board via UART.
ESP8266 has been minimized with NodeMCU firmware (build has the following timestamp:) nodemcu-master-8-modules-2017-05-30-19-21-49-integer
. Firmware has been built using only the following modules: file, gpio, net, node, tmr, uart, websocket, wifi
. The ESP8266 board is an Adafruit Huzzah board.
The ESP board is powered via a serial cable from my USB port. The cable I'm using is this one that gives me 5V to power my board and I know the USB on my Mac can supply 500mA,
The Arduino is also powered by another USB port on my computer.
The ESP board and Arduino are connected as follows:
ESP8266
TX RX GND
| | |
| | |
10 11 |
RX TX GND
Arduino
The Adafruit Huzzah board states that:
The TX pin is the output of the module and has 3.3V logic. The RX pin is the input to the module and corresponds to 5V (there is a level shift on this pin)
Thus, there should be no need for a level conversion between the two.
The code I'm running on the ESP8266 board because init.lua
:
uart.setup(0,115200,8,0,1)
tmr.alarm(0, 5000, 0, function()
uart.write(0, "A", 19)
end)
The code I'm running on Arduino:
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
MeetAndroid meetAndroid;
SoftwareSerial sSerial(rxPin, txPin);
uint8_t lastByte;
uint8_t serialBuffer[64];
int count = 0;
int onboardLed = 13;
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(115200);
sSerial.begin(115200);
pinMode(onboardLed, OUTPUT);
digitalWrite(onboardLed, HIGH);
}
void loop() {
while (sSerial.available() > 0) {
serialBuffer[count] = sSerial.read();
count++;
}
for (int i = 0; i < count; i++) {
Serial.println(serialBuffer[i]);
}
}
What I see on the Serial Monitor in Arduino when I reset my ESP board is garbage:
⸮⸮⸮⸮⸮⸮Z,⸮}⸮߿⸮ߏ⸮\⸮⸮LYLYLYLYL⸮L⸮L⸮L⸮L⸮L (((((⸮$⸮$⸮$⸮$⸮$⸮$⸮4⸮0⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@ ((((⸮$:⸮&i(⸮⸮
After a little delay, it starts printing a line by line of garbage after that initial line. It's clear to me that there is a discrepancy somewhere.
I've searched for previous questions on this, but the only one I could find that came closest to my use simply stated that the docs should be read , which was not very helpful.
Does anyone know what is wrong here?
You must set the correct baud rate. You can set the baud rate in the lower right corner of the serial monitor.
I prefer to use the standard debug speed of 9600.