Arduino Nano and ESP8266 - Device goes offline

Im Controlling a model Train with an arduino Nano and an esp8266 Module I use a relay-Module to control the lights and the smoke Generator, then in have l298 Module to control speed and direction of the locomotive and i’m using two step down dc-dc converter to power the arduino and the esp

everythig works fine until some time (about 2 min from restart but it varies) the device gets disconnected (like i would shut down the router or Switch of the power from the esp).
i already soldered a capacitor between vcc and ground from the esp.

if im running the Serial Monitor it tells me that the ping is something about 70ms is that enough?

At the Moment im using this sketch to test the communiaction


/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This example shows how to use ESP8266 Shield (with AT commands)
  to connect your project to Blynk.

  WARNING!
    It's rather tricky to get it working, please read this article:
    https://github.com/blynkkk/blynk-library/wiki/ESP8266-with-AT-firmware

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "X";

// Your WiFi credentials.
// Set password to "" for open networks.


char ssid[] = "X";
char pass[] = "X";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(10, 11); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
  Blynk.run();
}

I already made a Topic from this Project and the same Problem some weeks ago Moderator Edit - I merged this back into your initial post, nobody answered me so I’m trying again

I read that it is not recommended to use an arduino nano/uno to use with an esp8266 bc of the Software Serial. Now i’m using a arduino mega with Serial2.
Problem is, that the Arduino connects with blynk and after some time (from about 10 sec to 2 min) it disconnects. I dont know why, but sometimes it works perfectly.
could flooding cause this problem?
this is what the serial monitor tells me

[19] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.8 on Arduino Mega

[604] Connecting to AndroidAP
[3806] AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK
[4896] Failed to enable MUX
[14947] Failed to connect WiFi
[23904] Ready (ping: 85ms).

and after some time it disconnects. But sometimes I have this error:

[102041] Ready (ping: 85ms).
[148498] Ready (ping: 85ms).
[153549] Login timeout
[169151] Ready (ping: 85ms).
[174202] Login timeout
[194942] Ready (ping: 85ms).

I know that it can cause this error when there is some sketch in void loop, but at time moment im just using the simplest sketch from blynk:

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This example shows how to use ESP8266 Shield (with AT commands)
  to connect your project to Blynk.

  WARNING!
    It's rather tricky to get it working, please read this article:
    https://github.com/blynkkk/blynk-library/wiki/ESP8266-with-AT-firmware

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";

// Your WiFi credentials.
// Set password to "" for open networks.

char ssid[] = "AndroidAP";
char pass[] = "XX";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial2

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(10, 11); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
  Blynk.run();
}

It is possible that no one bothered to answer as your issue is likely non Blynk related… probably a case of simply running into power brownout issues with the ESP… it uses more current with the WiFi then the Arduino’s 3.3v regulators are really meant to supply… this is mentioned repeatedly throughout this forum with “ESP as shield” use cases.

Use separate 5v and 3.3v power for all of your accessories… just make sure all devices share the same GND pin.

Google for further info on power issues.

I know that I cant power the esp with the Arduino. That’s why im using these two step down converter in the top left of the picture above… but I tried to power everything with Laboratory Power supplies and connected the GND pins. didn’t work…

OK… was too much to take in at once without downloading and zooming in so I didn’t notice.:stuck_out_tongue_winking_eye:

Since you can connect and you have reportedly good power, then perhaps a network issue?

I’m using an Android Phone Hotspot as an Network connection, (4G internet access) that should work or not?
Do I need to have a min. ping value?

The other thing is what I think about, that the motors (and motor-wires) generate an inductive field that could disturb the ESP (and the wifi connection)… is that possible?

Yes, what ping times are you seeing?

it’s not great…

Well, if you can reliably connect each time, and is just the longevity of the connection, then possibly not the issue??

But that is hard to say, it’s your network setup, not mine :stuck_out_tongue_winking_eye: I run a basic WiFi router and get 15-20ms pings

They will affect power more… you could wire up some capaciters and diodes to help prevent issues.

Although your Motor Controller should already have some of that?

Blynk will cope with ping times of several hundred ms.

thisa is the ping times I have:

What do you mean with that?

@p_wiedmer Try the 0.5.0 Blynk Library… and possibly find a newer firmware for your ESP

This has been fairly stable for me… once I figured out some WiFi interference issues. I usually get a day or two before my connection routines initiate a reboot due disconnection… I think 0.4.8 was more forgiving of network issues… but I am still testing that…

image

I’m doing something similar (but with an RC car) and I use the Wemos D1 Mini which I program directly without using an Arduino. This appears to be working much stable. I also connect to the server using my phone as hotspot, so I can drive anywhere.

I’d recommend getting one or two Wemos chips and trying that instead of Arduino combined with ESP as shield.

2 Likes

The ping times of 85ms will be fine.

I tried it once with a normal router at home bc here at work I don’t have access to the wifi. Then I didn’t have a much lower ping value than now. But is there an other point that can cause high ping values?

I will try to update the esp firmware and the blynk lib, that will take me some time, cause I never did that.

will the diodes and capacitor reduce the inducticve/magnetic field? I’m not sure, the power itself is not the problem i think and as you said the motorshield is already armed with diodes an capacitors

Okay i already ordered a NodeMCU, I’m waiting to receive it i think this will work too, but i wanted to fix now
i think everything would work if i would not control a locomotive but instead some relays, leds etc. which is not that dynamic as a model train and uses much less data in the same time… if you know what i mean.

Not really, not in the sense you are referring too, but unless you are resting your ESP right on the motors :stuck_out_tongue_winking_eye: I think that is a non-issue.

Yes I do, but but the same principle applies. Blynk is very lightweight and I have absolutely no issues whatsoever controlling my car. Instead of smoke it has a Servo for steering and a battery, but still…

no that’s not the case, but the circuit path from the pwm-pins from the arduino to the motor shield, is right underneath the esp, but that shouldn’t cause a problem right?

Your guess is as good as mine on that… I do know that I have seen connection issues due interference… but hard to say exactly how and where it is from.

You will have to move things around to test. Unfortunately you can’t use WiFi.RSSI() with an ESP in AT shield mode… at least I haven’t been able to get it to work.