Introduction: Connect to Blynk Using ESP8266 As Arduino Uno Wifi Shield (Mac Only)

About: Mechanical Engineering student at the University of Michigan

This is a tutorial to show you how to connect to Blynk using an ESP8266 - 01 as an Arduino Uno wifi shield. This tutorial is very detailed to help out those who are very new to this stuff.

-

Hardware needed:

Arduino Uno

Male to male jumper cables

Male to female jumper cables (if you don't have a breadboard adapter)

Solderless breadboard

USB 2.0 cable type A/B to connect the Arduino Uno to your Mac

ESP8266-01

Optional, but recommended:

Breadboard adapter (not required but it does make connecting the ESP8266 to the breadboard much easier

link to purchase: https://www.tindie.com/products/rajbex/esp8266-bre...

-

-

Software needed:

For easy access, move or download the following software to the desktop of your Mac. It can be moved later.

Arduino IDE

link: https://www.arduino.cc/en/main/software

Most recent Blynk library

link: https://github.com/blynkkk/blynk-library/releases

pySerial

link: http://sourceforge.net/projects/pyserial/files/py...

esptool

link: https://github.com/themadinventor/esptool

Sdk1.0.0 v0.22 ESP8266 firmware

link: http://esp8266.ru/download/esp8266-firmware/AT22S...

Blynk app on iphone or android

Step 1: Download Arduino IDE

Click the link provided in the intro and click what is in the red box. Make sure you move it to your desktop.

Step 2: Download Most Recent Blynk Library

Click the link provided in the intro and click what is in the red box. Make sure you move it to your desktop.

Step 3: Download PySerial

Click the link provided in the intro and click what is in the red box. Make sure you move it to your desktop. Once it's there, double click the "pyserial-2.7.tar.gz" file and it will create a pyserial-2.7 folder.

Step 4: Download Esptool

Click the link provided in the intro and click what is in the red box. Make sure you move it to your desktop.

Step 5: Download Sdk1.0.0 V0.22 ESP8266 Firmware

This will download just by clicking the link in the intro page. Make sure you move it to your desktop.

Step 6: Prepare Esptool for Flashing

Open the "esptool-master" folder and move the "AT22SDK100-2015-03-20-boot1.2.bin" file into it. Then, rename it to "AT22SDK10020150320boot12.bin". This step is very important. If you don't rename the file, you will get an error later on.

Step 7: Installing PySerial

Step1: Open your Mac Terminal (you can find Terminal in a spotlight search), then type "cd". Next, drag the "pyserial-2.7" folder into the terminal window and hit enter. The window should look something like:

~ Home$ cd /Users/Home/Desktop/pyserial-2.7
:pyserial-2.7 Home$

Step 2: Copy this text, "sudo python setup.py install" into Terminal and hit enter. It will ask you for your password. The window should now look something like:

~ Home$ cd /Users/Home/Desktop/pyserial-2.7

:pyserial-2.7 Home$ sudo python setup.py install

Password:

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'use_2to3'

warnings.warn(msg)

running install

running build

running build_py

running build_scripts

running install_lib

running install_scripts

changing mode of /usr/local/bin/miniterm.py to 755

running install_egg_info

Removing /Library/Python/2.7/site-packages/pyserial-2.7-py2.7.egg-info

Writing /Library/Python/2.7/site-packages/pyserial-2.7-py2.7.egg-info

:pyserial-2.7 Home$

Congrats! You just installed pySerial!

Step 8: Add the Blynk Library to Your Arduino IDE

Step 1: Open the Arduino IDE (a blank sketch will open)

Step 2: Follow the steps in the first picture to get to "Add .zip Library..."

Step 3: Click "Add .zip Library...", then double click "Desktop" (assuming that is where you saved the Blynk Library), then double click "Blynk_v0". There will be a list of five files.

Step 4: Single click the first library ("Blynk") then click "Choose" to add it to your libraries. Repeat Step 3 until you have also added "BlynkESP8266_HardSer", "SimpleTimer", and "Time".

*You should then get the message shown in Picture 2 each time you add a library.

Step 9: Prepare the Code for the Arduino

Step 1: Open a new sketch

Step 2: Replace the existing code with the code below and save. DON'T upload it yet, though. Leave this window open. We will come back to it later.

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space #include <ESP8266_HardSer.h>

#include <BlynkSimpleShieldEsp8266_HardSer.h>

// Set ESP8266 Serial object #define EspSerial Serial

ESP8266 wifi(EspSerial);

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

void setup() { // Set console baud rate Serial.begin(9600); delay(10); // Set ESP8266 baud rate EspSerial.begin(115200); delay(10);

Blynk.begin(auth, wifi, "???", "???"); }

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

Step 10: Wiring the Arduino and ESP8266

The above wiring scheme shows how to wire the Arduino and ESP8266. If you do not have a breadboard adapter, then you can use male to female jumper cables to connect to pinouts from the ESP8266 shown above.

**Make sure you power the ESP8266 with 3.3V. 5V kills it, be careful!

-

-

Overview of connections:

ESP8266:____________ Arduino:

GND -------------------------- GND

GP2 -------------------------- Not connected (open)

GP0 -------------------------- GND

RXD -------------------------- RX

TXD -------------------------- TX

CHPD ------------------------ 3.3V

RST -------------------------- Not connected (open)

VCC -------------------------- 3.3V

Step 11: Connecting Your Arduino to Your Mac

Step 1: Connect your Arduino to your Mac using your USB 2.0 cable.

Step 2: Go to the tools tab, then go to port. Next, select your device address. It should be the bottom one. Your device address will be different.

Step 12: Flashing the ESP8266

Step 1: Upload a blank sketch to your Arduino.

Step 2: Open your Mac Terminal (you can find Terminal in a spotlight search), then type "cd". Next, drag the "esptool-master" folder into the terminal window and hit enter. The window should look something like:

~ Home$ cd /Users/Home/Desktop/esptool-master

:esptool-master Home$

Step 2: Copy this text, "sudo ./esptool.py --port /dev/tty.??? write_flash 0x00000 AT22SDK10020150320boot12.bin" into Terminal. Replace the ??? with your device address you found in the previous step. You only replace the ??? with the characters after "cu." and before (Arduino Uno). For example, mine is /dev/cu.usbmodemfd121 (Arduino Uno), so I replaced the ??? with "usbmodemfd121". Make sure the device address is copied exactly. When I first did this, I was off by one letter and it took me a while to figure it out. Now, hit enter. It will ask you for your password. The window should now look something like:

~ Home$ cd /Users/Home/Desktop/esptool-master

:esptool-master Home$ sudo ./esptool.py --port /dev/tty.usbmodemfd121 write_flash 0x00000
AT22SDK10020150320boot12.bin Password: Connecting... Erasing flash... Wrote 520192 bytes at 0x00000000 in 49.8 seconds (83.5 kbit/s)... Leaving... :esptool-master Home$

Step 13: Upload Your Code to the Arduino

Step 1: Disconnect the ESP8266 GP0 pin from ground.

Step 2: Open your Blynk app on your phone.

Step 3: First, create an account, create a new project, and hit the gear button. Next, press the auth (long array of characters) and email it to yourself. Go to the "char auth[ ] = "???";" line of your code. Replace the ??? with your new auth characters.

Step 4: Go to the "Blynk.begin(auth, wifi, "???", "???");" line of your code. Replace the first ??? with your wifi name. Replace the second ??? with your wifi password.

Step 5: Click the upload button.

Step 6: Disconnect and reverse the RX and TX Arduino pins (so that the RXD pin of the ESP8266 is connected to the TX pin of the Arduino and the TXD pin of the ESP8266 is connected to the RX pin of the Arduino).

Step 14: Check Your Connection

Step 1: Open the serial monitor.

Step 2: Change the baud rate to 115200 if it is not that already (at bottom right corner of the serial monitor, there is a drop down menu to change it). You should get something similar to the response below.

[520] Connecting to ____

ATE0

AT+CWMODE?

AT+CWJAP="____","_____"

AT+CIFSR

[7611] IP: +CIFSR:STAIP,"___.___._.___"

+CIFSR:STAMAC,"__:__:__:__:__"

OK

AT+CIPMUX=0

[7633] Connected to WiFi

AT+CIPCLOSE

AT+CIPSTART="TCP","blynk-cloud.com",8442

AT+CIPSEND=37

[1] ________ [12901] Ready (ping: 14ms).

Now, you can go back to the Blynk app, press the dotted background, add a button, and connect it to digital pin: D13. Then, press the play button.

The LED next to pin 13 on your Arduino should turn on when you press the button.

If it does, CONGRATS! You have now connected to Blynk and can create your own projects.

Happy Blynking!!