4
votes

I want to send data from my ESP8266 device to an Arduino Uno board via UART.

The ESP8266 has been flashed with NodeMCU firmware (the build has the following timestamp: nodemcu-master-8-modules-2017-05-30-19-21-49-integer). The firmware has been built using only the following modules: file, gpio, net, node, tmr, uart, websocket, wifi. The ESP8266 board itself is an Adafruit Huzzah board.

The ESP board is powered via a Serial Cable from my laptop USB. The cable I am using is this one, which provides me 5V for powering my board and I know the USB on my Mac can supply the 500mA needed.

The Arduino is also powered via the other USB port on my computer.

The ESP board and the Arduino are connected as follows:

ESP8266
TX        RX    GND
|         |     |
|         |     |
10        11    |
RX        TX    GND
Arduino

The Adafruit Huzzah board claims that:

The TX pin is the output from the module and is 3.3V logic. The RX pin is the input into the module and is 5V compliant (there is a level shifter on this pin)

So there shouldn't be a need for a level converted between these two.

The code I am running on the ESP8266 board, as init.lua is:

uart.setup(0,115200,8,0,1)

tmr.alarm(0, 5000, 0, function()
  uart.write(0, "A", 19)
end)

The code I am running on the Arduino is:

#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 once I reset my ESP board is garbage:

⸮⸮⸮⸮⸮⸮Z,⸮}⸮߿⸮ߏ⸮\⸮⸮LYLYLYLYL⸮L⸮L⸮L⸮L⸮L (((((⸮$⸮$⸮$⸮$⸮$⸮$⸮4⸮0⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@⸮@ ((((⸮$:⸮&i(⸮⸮

After a short delay it starts printing out line upon line of garbage after this initial line. It's clear to me that, somewhere, there is a mismatch.

I've looked for previous questions on this matter, but the only one I could find that was the closest to my use stated simply that one ought to read the docs, which was not very helpful.

Does anyone know what is amiss here?

2
Hi i'm working on a project that in similar situation with you. Have you found the solution? I think that software serial not work properly on 115200 baud rate?Lorensius W. L. T

2 Answers

1
votes

You have to set a proper baud-rate. You can set the baud-rate on the bottom right corner of the serial monitor.

I prefer to use the standard debug baud rate of 9600.

0
votes

I believe those are two different problems. The first line of garbage after booting up actually belongs to esp8266's firmware, it's default baud rate is 74880 and if you open a serial monitor on that baud rate, you can see something like this:

ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d

The second problem is with the softwareSerial library. Based on this (and my own experience), maximum reliable baud rate seems to be around 28800 and you've set it up to high. I recommend decreasing the baud rate or switching to other libraries such as AltSoftSerial.