I just recently bought a ESP8266 wifi shield that I intend to use with my Leonardo. I have some experience with arduino but I am running into some issues with my program. I ran the ESP8266 shield demo and connected to my wireless network, then I began integrating a simple RGB LED control to start with a small project. I found some code from an example and added some modifications. I placed three buttons in my Blynk app to control the RGB LED.
As I mentioned earlier my shield is successfully connected to my wifi and stacked on my leonardo, because the blue LED is solid. But the blynk app says the arduino Leonardo is not in the network. So I know something is missing in my code but I am not sure. Like I said earlier, I am just using three buttons on the blynk app to control and RGB LED from my Leonardo with and ESP8266 shield. I know my loop code needs to read the virtual switches but I am also unsure on how to do that.
Any help/guidance would be greatly appreciated. Thank you all in advance!
I blanked out my wifi information, but here is my code:
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
/*Defines*/
//IO PINS
#define RED_LED_PIN 2
#define GREEN_LED_PIN 3
#define BLUE_LED_PIN 4
//RED LED
#define RED_LED_ON digitalWrite(RED_LED_PIN,HIGH)
#define RED_LED_OFF digitalWrite(RED_LED_PIN,LOW)
//GREEN LED
#define GREEN_LED_ON digitalWrite(GREEN_LED_PIN,HIGH)
#define GREEN_LED_OFF digitalWrite(GREEN_LED_PIN,LOW)
//BLUE LED
#define BLUE_LED_ON digitalWrite(BLUE_LED_PIN,HIGH)
#define BLUE_LED_OFF digitalWrite(BLUE_LED_PIN,LOW)
//YELLOW LED
#define YELLOW_LED_ON RED_LED_ON;GREEN_LED_ON
#define YELLOW_LED_OFF RED_LED_OFF;GREEN_LED_OFF
//MAGENTA LED
#define MAGENTA_LED_ON RED_LED_ON;BLUE_LED_ON
#define MAGENTA_LED_OFF RED_LED_OFF;BLUE_LED_OFF
//CYAN LED
#define CYAN_LED_ON BLUE_LED_ON;GREEN_LED_ON
#define CYAN_LED_OFF BLUE_LED_OFF;GREEN_LED_OFF
//WHITE LED
#define WHITE_LED_ON RED_LED_ON;GREEN_LED_ON;BLUE_LED_ON
#define WHITE_LED_OFF RED_LED_OFF;GREEN_LED_OFF;BLUE_LED_OFF
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "************************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********k";
char pass[] = "*******";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
void setup()
{
// Set console baud rate
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
//Set LED output pins
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(BLUE_LED_PIN, OUTPUT);
Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
Blynk.run();
if(RED_LED_PIN==1)
{
RED_LED_ON;
}
else if(GREEN_LED_PIN==1)
{
GREEN_LED_ON;
}
else if(BLUE_LED_PIN==1)
{
BLUE_LED_ON;
}
else
{
WHITE_LED_OFF;
}
}
Look up SimpleTimer and BLYNK_WRITE() in the docs.
BLYNK_WRITE(Vx) Writes a 1 to Virtual pin x if you assign a Button to Vx and press the button for ON (0 for OFF). Probably best to start with your buttons in Switch mode and then work up to Push mode.
You should open SM before you upload your sketch.
Nightmare scenario. If you search the forum for “echo” you will see loads of Blynkers with similar problems.
Until you fix it there is no way forward with the Leonardo.
Is the esp8266 able to stack directly onto the Leonardo? Because I don’t know how the shield could stack on top and still cross the TX and RX pins. I currently have the pins 8 and 9 of the leonardo level shifted to 3.3V and connected to the SW_TX and SW_RX of the shield.
As for the echo problem, you’re saying I should update the firmware?
I find the sparkfun documentation to be uncharacteristically poor for this product.
It was also my understanding that this shield runs on 3.3V and requires a lot of current. So I also tried powering the shield externally on a breadboard instead of stacking it on my leonardo. I put 3.3V from a voltage regulator to VIN and it did not power up. The only way I could get it to power up was from a 5V regulator to the 5V pin. I tied the board gnd to the power supply -.
Could you provide me with any clarification on this subject as well?
From your OP I believe you tested the shield demo.
It might be that the AT firmware is not suitable for Blynk but Blynk and Sparkfun are partners (not for this shield though) so you would hope it ships with suitable AT firmware.
If you are using pins 8 and 9 I think you need to change your sketch to Software serial from hardware serial and change (2, 3) in the sketch to (8, 9) (could be 9, 8).
I wouldn’t change the AT firmware at this stage and see how you go with the correct sketch.
This is my code with all excess removed, serial monitor still shows failed to disable echo [1531]:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
void setup()
{
// Set console baud rate
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();
}
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX
I just received this on the serial monitor:
[1538] Failed to disable Echo
[10469] Ready (ping: 22ms).
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(8, 9); // RX, TX
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
void setup()
{
// Set console baud rate
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();
}