So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By latam
#91562 Hi there!
I'm doing a project using a NodeMCU board for WI-FI connection with a mobile app. The NodeMCU is connected through a serial port to a microcontroller PIC18F8550 which does all the logic process and controls the sensors.
I've programmed what the PIC and the NodeMCU have to do in separate ways. Then I checked with an Arduino if the data was sent from the PIC and if the PIC received it back properly through the serial port, and it was ok. After that, I did the same with the NodeMCU (instead of the PIC), and it worked fine.
But when I put them both together, it didn't work.
So I took a step back and tried a basic serial communication between the PIC and the NodeMCU, and here is where I'm stuck.
The PIC has two IR sensors, when one of them is activated, a character is sent to the NodeMCU. As the NodeMCU's serialEvent() doesn’t work (I tried a few codes but none of them worked), I did a hardware interruption in pinD7 connected through a wire with the RX pin, so when the NodeMCU receives something, it interrupts the main code and reads the character (I need to use an interruption for serial communication because the main code sometimes stops in a http request waiting for an answer, so if I put the reading sentence in the main code, it won't read anything).
First, I activate one of the PIC's sensors, the PIC sends the character, the interruption calls the function and the NodeMCU reads the character well. The issue comes always in the second attempt. I try to activate again one of the sensors (either the same or the other one) and the NodeMCU resets itself. I've read that it could be a WDT rst and that maybe the issue is because of the loop. I've tried a few things I've seen on this forum and other websites, but none of them worked so far. Then I've read that it could be the reset pin, but it's not connected to anything.

The PIC sends the character only one time. It sends a "L1" or a "D1".
The NodeMCU code is the following one:
Code: Select all#include<ESP8266WiFi.h>
void ICACHE_RAM_ATTR PuertoSerial ();
int x = 0;
String cadena = "";
#define LED2 D6
#define LED3 D5
#define INTER D7

void PuertoSerial () {
  if (Serial.available())
  {
    String dato = Serial.readStringUntil('1');
    cadena.concat(dato);
  }
}

void setup()
{
  Serial.begin(115200);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  pinMode(INTER, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(INTER), PuertoSerial, FALLING);
}

void loop()
{
  if (cadena == "L")
  {
    digitalWrite(LED3, HIGH); delay(100); digitalWrite(LED3, LOW);
    Serial.println("N");
    delay(1);
    cadena = "";
  }
  else if (cadena == "D")
  {
    digitalWrite(LED2, HIGH); delay(100); digitalWrite(LED2, LOW);
    Serial.println("P");
    delay(1);
    cadena = "";
  }
  delay(0);
}


And the exception that resets the NodeMCU the second time is this one:
Code: Select all ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld


Does anyone have any idea of how to solve this?
Thanks in advance!