Microcontroller crashing?

Hey guys, so i currently have an Arduino and a WeMoS D1 Mini connected to each other, using the WeMoS as wifi access point, i have the two devices connected as follows:

Arduino WeMoS
5V 5V
GND GND
1 (TX) 5 (RX)

As i only need to send data from the Arduino to the WeMoS to send online i don't have the RX of the Arduino connected to the TX from the WeMoS.

The issue i'm having is that after ~30 seconds, the WeMoS stops receiving anything from the softwareserial that's listening to pin 5, disconnects from the MQTT broker and thus stops transmitting data to the server. When resetting it manually, it does re-connect to the MQTT broker for a few seconds and then disconnects again, but never transmits nor receives data over the softwareserial.

I double checked if my Arduino maybe stopped sending data but it does this every 5 seconds constantly so the problem is not on the Arduino board.

Any guidance is appreciated!
Cheers

How are you powering the Arduino?

Through a regular cable (USB-B to USB-A)
Not the barrel jack, the Arduino does function as it should with everything connected to it, and the WeMoS is only a wifi access point.

What firmware do you have on the WeMos? If it's a custom sketch, please post it here.

Make sure you have a voltage divider on the Arduino TX as the WeMOS is a 3.3V device.

What output do you get from the WeMOS? Any stack dump on the Serial console? That's often a great help in debugging and finding crashes.

pert:
What firmware do you have on the WeMos? If it's a custom sketch, please post it here.

The regular, didnt install any, it's the stock firmware

wvmarle:
Make sure you have a voltage divider on the Arduino TX as the WeMOS is a 3.3V device.

What output do you get from the WeMOS? Any stack dump on the Serial console? That's often a great help in debugging and finding crashes.

Nothing, no stack dumps or any errors, it just stops working, do you think powering through 3.3v instead would fix the issue? It works fine on another device, which hss a different purpose. However that one is the newer LOLIN model.

Anyone else?

Hi,

Make sure you have a voltage divider on the Arduino TX as the WeMOS is a 3.3V device.

This suggestion sounds like a good start.

Tom.. :slight_smile:

TomGeorge:
Hi,

This suggestion sounds like a good start.

Tom.. :slight_smile:

So i decided to power the WeMoS on its own to rule out the powering issues, and when they are not connected through any power cables, just data, and both are powered with their own USB cable, it still crashes.

Here's the code on my MicroController, the Arduino simply writes data to the Serial (tx).

#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <MQTT.h>

const char ssid[] = "XXX";
const char pass[] = "XXX";

SoftwareSerial mySerial(5, 4);

WiFiClient net;
MQTTClient client;

unsigned long lastMillis = 0;

void connect() {
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
  }

  Serial.print("\nconnecting...");
  if (!client.connect("XXX", "XXX", "XXX")) {
    delay(3000);
    return;
  }

  Serial.println("\nconnected!");
}

void setup() {
  Serial.begin(19200);
  mySerial.begin(9600);
  WiFi.begin(ssid, pass);

  client.begin("XXX", net);

  connect();
  delay(1000);
}

void loop() {
  client.loop();
  delay(10);

  if (!client.connected()) {
    connect();
    Serial.println("Reconnecting");
  }
  
  if (mySerial.available()) {
    String data = mySerial.readString();
    data.remove(1);
    Serial.println("I received " + data);

    if (data == "0" or data == "1" or data == "2" or data == "3" or data == "4" or data == "5" or data == "6") {
      client.publish("XXX", data);
    }
  }
}
    String data = mySerial.readString();

This may be your problem.
If an incomplete string comes in, this function times out after 1,000 ms.
The ESPs WDT times out and resets the module after 250 ms.

Use something like this, non-blocking, just reads the character when it's available:

char buffer[20];
uint8_t pos;

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c == '\n') {
      // string complete. Handle it.

    }
    pos++;
    if (pos == 20) {
      // string too long!
    }
  }
}

GSerum:
So i decided to power the WeMoS on its own to rule out the powering issues, and when they are not connected through any power cables, just data, and both are powered with their own USB cable, it still crashes.

That is not what the suggestion is, the Arduino is 5V logic, the WeMOS is 3.3V logic.
Have you tried a potential divider on the Arduino Tx to drop the 5V logic signal the WeMOS 3.3V logic?
I hope the gnds of both controllers are connected together.
Thanks.. Tom... :slight_smile:

TomGeorge:
Have you tried a potential divider on the Arduino Tx to drop the 5V logic signal the WeMOS 3.3V logic?

That is not normally a cause of the ESP crashing. It's more likely a cause of the ESP burning. So that means it's not crash and burn, but crash or burn :slight_smile:

Crashing (stopping to communicate but recovering just fine after a reset) points to a software issue or power supply issue. As OP hasn't mentioned motors or other common troublemakers I'm expecting the first. Blocking functions like Serial.readString() are a very common cause of an ESP crashing.

wvmarle:

    String data = mySerial.readString();

This may be your problem.
If an incomplete string comes in, this function times out after 1,000 ms.
The ESPs WDT times out and resets the module after 250 ms.

Use something like this, non-blocking, just reads the character when it's available:

char buffer[20];

uint8_t pos;

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c == '\n') {
      // string complete. Handle it.

}
    pos++;
    if (pos == 20) {
      // string too long!
    }
  }
}

That did it, cheers!