Atmega2560+ESP8622 Blynk problem

Hello im currently pulling my hair!

I've used like a week to get this working.

I bought this atmega2560 with buildin ESP8266 WiFi module. I used a lot of time to figure out how to use it and how the DIP switches work and what they connect to.
I finally got the hang of it and is no longer confusing to understand how it works.

BUT...

I'm getting frustrated to properly set up a sketch that actually works.

First I spend a lot of time to get it working with Arduino IoT cloud and found out it can't be done.

So I moved on to use BLYNK, and I almost had success.

All guides on how to set it up is too old because Blynk seems to have updated alot.

The best video I have found is this one:

But again you can't follow it 100% you need to find some new libraries, and the code doesnt work out of the box.

After a lot of fiddling around by mixing new and old libraries and sketches I suddenly got it working!!! And it was connected both to my Blynk app and Blynk website.

At this point I finally felt some relief.

Then the next part came, try to figure out how the sketch works to costumize it for my use. And here it went downhill fast.

It seems like no matter what changes I made to the sketch nothing seems to change.

All of a sudden I got too far into deeper water that I decided to delete everything take a break and start over with a fresh mind.

Now I connect to the god damn server again! And I can't remember exactly what I did because I tried so many different things that I lost track of it.

I can get the Blynk logo appear in the serial monitor and see it says connected to WiFi OK with IP address and everything. But that's it. Blynk will just sit there and say waiting for device to connect.

I really need someone with some expertise to help me out.

you have two options:

  1. put the Blynk firmware into the esp8266
  2. put AT firmware into esp8266 and use my WiFiEspAT library with the Blynk library as usual

EDIT:
3 options

  1. use AT firmware with the ESP8266 library provided by Blynk

Okay before I saw your answer I got it working, and it actually works as I thought it should.

Here is a short resume of what I did.

From Blynk website I used the Quickstart guide to get the setup sketch.

I copied it into Arduino IDE, choose LOLIN(WEMOS) D2 R1 & mini board.

Set the DIP switches 5,6,7 to ON

Uploaded the sketch.

Switched DIP 5,6,7 back to OFF

That's it.

It connected immediately.

Now I try get the serial communication to work correctly between the ESP modul and atmega2560.

I got them to connect to each other but the problem is that I can't seem to send the correct values.

I use the Serial3 port on the atmega, but it keeps sending randoms values between 40 and 53. I read it has something to with it being floating or something so it is the byte size it keeps printing or something, I didn't quite understand it.

for Serial3 did you switch the RX/TX switch on the board?

Yes the configuration is correct. I kinda solved the random numbers issue not only using Serial.print and Serial.read, but instead added "if (Serial3.available())" etc.

I have another problem handling data between Blynk, atmega and ESP.

ex.
ATMEGA2560 Send Sketch:

    case NFAULT:
    if( now - previousTime >= eventInterval){

//send message from ATMEGA2560 TX3 pin to RX0 on ESP8266
    Serial3.print(-1);

    previousTime = now;

TX3
|
|
|
|
|
|
V
RX0 ESP8622 Receive Sketch:

void myTimerEvent()
{
  int inByte = Serial.parseInt();

  Blynk.virtualWrite(V0, inByte);
}

WIFI
|
|
|
|
|
|
V
BLYNK

Now the problem is if I add a funktion so the value goes from -1 to 1 if I push a button, it changes slower and slower the more time that passes by.

Also if I instead uses -20 the value will keep changing between -20 , 0 , 20 , 2 for every second without me touching anything.

I suspect it has something to do with my way of handling Serial communication.

it is not necessary to write two sketches. put a firmware into the esp8266 and write a Blynk sketch for the Mega.
the DIP switches will fall apart if you switch them frequently

I have tried with firmware method and it won't work. It doesn't connect to the server.

which of the 3 methods I listed previously?

I followed these steps and used the latest firmware.

The problem is when I try to use the example sketch:

/*************************************************************

  You’ll need:
   - Blynk IoT app (download from App Store or Google Play)
   - ESP8266 board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID           "TMPxxxxxx"
#define BLYNK_TEMPLATE_NAME         "Device"
#define BLYNK_AUTH_TOKEN            "YourAuthToken"

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


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

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

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  // You can also specify server:
  //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

I set the DIP switches 1-2-3-4 ON, choose the Atmega2560 board and when uploading sketch, I get the error that <ESP8266WiFi.h> isn't found.

However if I choose LOLIN(WEMOS) D2 R1 & MINI board it doesn't give the error and attempts to upload but of course it would fail because it can't find the ESP module because the DIP switches is set wrong.

So therefore the only way I can make it work is to set the DIP switches 5-6-7 ON and upload the example sketch to the ESP.

Another thing I have tried is of course uploade the firmware to the ESP and then using the old 0.6.1 version of the Blynk library were instead of using in the example sketch <ESP8266WiFi.h> it uses <ESP8266_Lib.h>
Then I can set the DIP switches 1-2-3-4 ON and upload this sketch to the Atmega2560 and it will work.

//  LIBRARY-Blynk

//====================================================
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h> // insert this library 
#include <BlynkSimpleShieldEsp8266.h>
//====================================================

//  Initialitation
//====================================================
char auth[] = "2626aXgFo0b3_bDAQURC_FE66OsAG-8A";
char ssid[] = "haha";
char pass[] = "cumakamu";
#define EspSerial Serial3
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);



//====================================================


void setup()
{

  Serial.begin(115200);
  Serial3.begin(115200);

  delay(10);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

 // Blynk.begin(auth, wifi, ssid, pass);                          //Reguler server
  Blynk.begin(auth, wifi, ssid, pass,"blynk-cloud.com", 8080);    //Local server
}

void loop()
{
  Blynk.run();
  if ( Serial3.available() )   {
    Serial.write( Serial3.read() );
  }
  if ( Serial.available() )       {
    Serial3.write( Serial.read() );
  }

}

Like in the YouTube video I linked previously.

But even though the ESP connects to the internet, it won't connect to the server.

your ESP8266_Lib example is for old Blynk. do you see the difference between it and the esp8266 example?

What do you mean? Yes I see it includes different libraries if that's what you mean, also the new example uses template name and ID.

But if I can't even upload the new example to the atmega because if the ESP8266 library the rest of the sketch doesn't matter anyway.

Maybe you have a way to make it work?

the blynk esp8266 library is in the release zip
https://github.com/blynkkk/blynk-library/releases/download/v1.3.2/Blynk_Release_v1.3.2.zip

I can't try, pretty sure I have it though, and it doesn't contain anything called ESP8266WiFi.h

ESP8266WiFi is the WiFi library bundled with the esp8266 core. so you use it in the esp8266 sketch.

the ESP8266_Lib works in Mega and communicates with the AT firmware in the esp8266.

Okay so in the new example sketch, I need to replace ESP8266WiFi.h with ESP8266_Lib.h?

Her is what I've done:

Making sure to have the boardURL for the ESP8266:

Added the library you linked me:

Choose ESP8266 in Blynk:

Copied the sketch:

Choose Atmega2560 pressed upload and that's it I can't get any further:

Tried replacing ESP8266WiFi.h with ESP8266_Lib.h:

If I however change it back to ESP5266WiFi.h and try to upload the sketch to the ESP8266 directly there is no problem:

And it connects without a problem:

Next thing I try is the Blynk firmware method. I Flash the latest Blynk firmware to the ESP8266:
ESP Firmware

Then when using the old 0.6.1 version of the Blynk library and upload the old sketch from the youtube video to the atmega2560 it works no problem, but as you can see it only connects to Wifi not the Blynk server and thats it:

I can also upload the sketch with the new version 1.3.2 of Blynk, I just need to add Template ID and Name.
But again it doesn't connect to the server. Only the wifi connection.

This is as far as I can get.
I don't think I can explain it any better what I've tried.

^^^

Are you even looking at the screenshots?!

I flashed the blynk firmware to the ESP8266, done.
THEN I copied the sketch from Blynk website and tried uploading it to the Atmega2560 but it keeps failing. I can't upload the Blynk sketch to the atmega because it keeps asking for ESP8266WiFi.h you would see that if you looked at the screenshots.

So let me say it one more time I CANT UPLOAD THE SKETCH TO THE ATMEGA2560.

Sorry to sound a bit angry but I'm kinda frustrated.

Let's take a step back. Try repeating the exact steps you want me to do and I try it.

I didn't see anything about you using NCP. I listed the options and I expected you write "I want 1)"