Hi,
There are ESP8266 (NodeMCU) and Arduino UNO. Both devices are connected via the UART bus.
I have problems with the transfer of data from UNO to ESP (data does not come at all).
Wiring:
RX - TX / TX - RX
Since ESP and UNO have different logic (3.3V / 5V). I made a resistive voltage divider on the TX line from UNO, consisting of 3 resistors, with 1k values.
Similar wiring diagram:
Code Arduino UNO:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(2500);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("<220>");
delay(2500);
Serial.println("<225>");
delay(2500);
}
Code ESP8266:
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];
char Message[numChars] = { 0 };
boolean newData = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW); // HIGH
delay(500);
digitalWrite(LED_BUILTIN, HIGH); // LOW
}
void loop() {
// put your main code here, to run repeatedly:
recvWithStartEndMarkers();
if (newData == true) {
digitalWrite(LED_BUILTIN, LOW);
strcpy(tempChars, receivedChars);
parseData();
msgData();
newData = false;
}
}
void recvWithStartEndMarkers()
{
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
// RAPI Message Protocol
void parseData()
{ // split the data into its parts
char* strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempChars, ","); // get the first part - the string
strcpy(Message, strtokIndx); // copy it to messageFromPC
//Serial.println(Message);
}
// Message Protocol
void msgData()
{
if(strcmp("220", Message) == 0) {
digitalWrite(LED_BUILTIN, LOW); // ON
} else if(strcmp("225", Message) == 0) {
digitalWrite(LED_BUILTIN, HIGH); // OFF
}
}
I see that the RX LED flashes on UNO, which means that the data is sent to ESP, but the ESP itself does not respond to them. I also tried to send data from ESP to UNO, everything works fine here because there are no voltage dividers.
I thought the problem was in the code, perhaps ESP does not understand this data.
I tried to just send the numbers without any brackets and respond to any incoming data by igniting the LED.
Arduino UNO:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(2500);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("220");
delay(2500);
Serial.println("225");
delay(2500);
}
ESP8266:
int incomingByte = 0;
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(1500);
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
digitalWrite(LED_BUILTIN, LOW);
}
}
It brought no results. What could be the problem?
P.s boards are not connected to a PC, so the COM port cannot be the cause of the problem.

