Programs for arduino mega with built-in wifi

Hi all,
I’m a newbie to Arduino and I’m looking for help with my project. I bought the Arduino Mega R3 with built-in wifi for my project.
I try to use Blynk to control the LED (Builtin LED) with 1 switch. And below is my code

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

  This is a simple demo of sending and receiving some data.
  Be sure to check out other examples!
 *************************************************************/

/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID           "TMPL6jbnasol1"
#define BLYNK_TEMPLATE_NAME         "Quickstart Template"
#define BLYNK_AUTH_TOKEN            "szG4S2cfzO9huqdv9Ybfu3jQf11T3opA"

/* 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[] = "iShange";
char pass[] = "1234567890";

BlynkTimer timer;

// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V1)
{
  // Set incoming value from pin V0 to a variable
  int value = param.asInt();
  if (value == 1) {
    digitalWrite(LED_BUILTIN, HIGH);
  }
  else {
    digitalWrite(LED_BUILTIN, LOW); 
  }
}

// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
  // Change Web Link Button message to "Congratulations!"
  Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
  Blynk.setProperty(V3, "onImageUrl",  "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
  Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}

void setup()
{
  // Debug console
  Serial.begin(115200);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  pinMode(LED_BUILTIN, OUTPUT);
}

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

I turn on switches 5, 6, and 7 on the board to upload the sketch and then turn off switch 7 to connect to the Blynk server, and it is successful (I put the switch to RXD0 and TXD0)
At the Blynk, I define the button is V1.
However, I can’t use this button on Blynk to turn on/off the Built-in LED. Could anyone help me to review if I missed any steps to configure the board or from the software?

Your comment here doesn’t match the code that follows…

One talks about V0, but the code relates to V1

You’ve said that your button widget is attached to V1, how is that datastream configured?
And how is your button widget configured?

And, which board type have you selected in the IDE?
The LED_BUILTIN command only works id you have the correct board type selected. Personally, I prefer to use the GPIO number of the LED rather than relying on LED_BUILTIN.

Pete.

the esp8266 on the Mega+WiFi doesn’t connect to pin headers of the Mega. to use a Blynk on Mega + WiFi, use the esp8266 as WiFi adapter. put AT commands firmware into the esp8266 and code for Mega

1 Like

Sorry, mismatch of comment and code, actually I’m using V1. I configure the datastream in Blynk is as following

  • Pin: V1, Date type: integer
  • min 0, max 1, default value is 0
    I select the board: Generic ESP8266 Module to upload this code. This is also my concern whether I need to upload to 8266 only or I have to upload to AVG 2560 as well to control the LED

Thank you, let me try this sample code. Could you please instruct me which board I should select to upload this code ?

You need to start by restoring the AT firmware to the ESP8266 portion of your board if you have overwritten it by uploading a sketch to it.

Is there a reason why you’ve chosen this hardware rather than a NodeMCU or ESP32 ?

Pete.

Thanks so much. It would be appreciated if you can share me how to restore the ESP8266.
I choose this model because this is my first time to develop this board, I have no idea about the models; and at my local store, I have not much options to use

I don’t know how to do that for this board. it isn’t a board that I would ever buy or use, as the Mega side of the board is under-powered and under resourced and the board itself represents the worst of both worlds as far as I’m concerned. Using an ESP8266 as a WiFi modem using AT commands is a clunky and inefficient system.

You’re far better using a fully featured ESP8266 based board such as the NodeMCU or Wemos D1 Mini/Pro.
If you need more than one Analog inputs or more than 5 GPIOs then using an ESP32 devkit board would be a better choice.
As you can buy an ESP32 board for around 5-10 USD it doesn’t make sense to use much else in my opinion.

Pete.

1 Like

I am inclined to agree with Peter on this topic because I do have 6 of those boards that I played with some years ago. I don’t think they ever really gained a lot of user uptake. There is a firmware called ESP-Link that I got to work sucessfully on the ESP8266-Mega set up but that firmware is no longer developed / supported by the person who originally wrote it. I can assure you that it is much easier to develop a solution using, say, an ESP8266 or ESP32 and port expanders. My original thinking was that the Mega would provide 5V IO level, extra IO pins and additonal ADC pins. However, experience has taught me it is easier to achieve those benefits with I2C port expanders.
I would never use the clunky AT commands. I would suggest you search the wider net for projects using the ESP-Mega board because I found some useful imformation from those using that board, that was in 2019 though!

1 Like

@bobcroft I created the WiFiEspAT library few years ago. it is ideal for Mega+WiFi board and works almost as good as the esp8266 WiFi library, but in the ATmega

Thanks for sharing that imformation. I’ll take a look at it when I get chance. It would be nice to find a use for the ESP-Mega boards I have instead of throwingthem in the bin.

I correctly solved this issue.
I restored the firmware for ESP8266 and used a sample code on Blynk to upload the Mega2560, and now it works properly. It’s a good beginning for further development.
Thanks for your support, guys.

1 Like