SparkFun ESP8266 Thing Development Workshop (2015)
SparkFun ESP8266 Thing Development Workshop (2015)
Table of Contents
Copyright
Preface
1. Preparing Development Environment
1.1 SparkFun ESP8266 Thing
1.2 Electronics Components
1.2.1 Arduino Starter Kit
1.2.2 Fritzing
1.2.3 Cooking-Hacks: Arduino Starter Kit
1.2.4 Arduino Sidekick Basic kit v2
1.2.5 Grove - Starter Kit for Arduino
1.2.6 DFRobot - Arduino Kit for Beginner v3
1.3 Development Tools
1.4 Testing
2. Setting Up SparkFun ESP8266 Thing
2.1 Getting Started
2.2 Installing Arduino Software
2.3 Connecting SparkFun ESP8266 Thing board to Computer
2.4 Hello SparkFun ESP8266 Thing: Blinking LED
2.5 Updating Program
3. GPIO Programming
3.1 Getting Started
3.2 Wiring
3.3 Writing a Program
3.4 Testing
4. UART
4.1 Getting Started
4.2 Wiring
4.3 Writing a Program
4.4 Testing
5. PWM and Analog Input
5.1 Getting Started
5.2 Demo Analog Output (PWM) : RGB LED
5.2.1 Wiring
5.2.2 Writing Program
5.2.3 Testing
5.3 Demo Analog Input: Working with Potentiometer
5.3.1 Wiring
5.3.2 Writing Program
5.3.3 Testing
6. Working with I2C
6.1 Getting Started
6.2 Writing Program
6.3 Writing Program
6.4 Testing
7. SPI
7.1 Getting Started
7.2 Wiring
7.3 Writing a Program
7.4 Testing
8. Connecting to a Network
8.1 Getting Started
8.2 Scanning WiFi Networks
8.3 Building a Simple Internet of Things
Source Code
Contact
Preface
This book was written to help anyone want to get started with SparkFun ESP8266 Thing board development. It
describes the basic elements of SparkFun ESP8266 Thing development using Arduino software.
Agus Kurniawan
Depok, August 2015
1.2.2 Fritzing
Store website: http://shop.fritzing.org/ .
You can buy Fritzing Starter Kit with Arduino UNO or Fritzing Starter Kit with Arduino
Mega.
1.4 Testing
For testing, I used SparkFun ESP8266 Thing on Windows 10, OS X and Ubuntu.
This chapter explains how to work on setting up SpakFun ESP8266 Thing board.
Then, click menu File -> Prefernces (Windows/Linux) or Arduino -> Preferences (OS X)
so you should see Preferences dialog.
Add http://arduino.esp8266.com/stable/package_esp8266com_index.json on
Additional Boards Manager URLs . If you have the list on there, just add ; for new list
item,
Then, you should see Boards Manager dialog. Find esp8266 board and install it.
After installed, you can see a list of ESP8266 Modules target on Arduino IDE such
as SparkFun ESP8266 Thing.
Now you can write the program for SparkFun ESP8266 Thing.
Then, connect power adapter (maximum 5V DC) to SparkFun ESP8266 Thing power via
microUSB. I recommended to connect it to your computer. Turn on the board. After
connected, you may get lighting on blue LED. Now you can connect serial adapter to your
computer.
After connected, you can see serial adapter as COMx on Windows, /dev/cu.usbserial* on
OSX or /dev/ttyAMA* or /dev/tty* (check it on your Linux platform).
Change 13 pin to 5.
Save and compile by pressing Verify icon. To upload program to SparkFun ESP8266
Thing board, you can click Upload icon.
If success, you can see blinking LED on SparkFun ESP8266 Thing board.
If you get error messages as follows,
warning: espcomm_sync failed
error: espcomm_open failed
You can set GPIO0 to GND
3. GPIO Programming
In this chapter Im going to explain how to work with GPIO on SparkFun ESP8266 Thing
and write a program for demo.
In this chapter, we build a program to illustrate how SparkFun ESP8266 Thing GPIO
work. We need a LED and a pushbutton.
Lets start!.
3.2 Wiring
Connect LED to pin 13 on SparkFun ESP8266 Thing and pushbutton to pin 4 The
following is a sample of wiring.
3.4 Testing
Now you can upload and run this program to SparkFun ESP8266 Thing board. For
testing, try to press pushbutton. You should see a lighting LED.
4. UART
In this chapter Im going to explain how to access UART on SparkFun ESP8266 Thing
board.
4.2 Wiring
In this scenario, we use the same wiring from chapter 3. We will show pressed state from
push button on Serial.
4.4 Testing
Now you can upload and run program. Dont forget to set board target with SparkFun
ESP8266 Thing. Read section 2.4 to upload the program.
To see the UART output, open Serial Monitor tool from Arduino IDE. Set baud 115200
and Carriage return.
You should see the UART output. A sample output can seen in Figure below.
This chapter explains how to work with SparkFun ESP8266 Thing Analog I/O.
In this chapter, we try to access SparkFun ESP8266 Thing Analog I/O using Arduino
software. There are two scenarios for our cases:
Controlling RGB LED
Reading Analog input using Potentiometer
Lets start.
Note:
Pin 1: Red
Pin 2: Common pin
Pin 3: Green
Pin 4: Blue
5.2.1 Wiring
For our testing, we configure the following PWM pins.
RGB LED pin 1 (red) is connected to SparkFun ESP8266 Thing pin 4
RGB LED pin 2 is connected to SparkFun ESP8266 Thing 3V3 (VCC +3.3V)
RGB LED pin 3 (green) is connected to SparkFun ESP8266 Thing pin 13
RGB LED pin 4 (blue) is connected to SparkFun ESP8266 Thing pin 12
Here is a sample implementation with SparkFun ESP8266 Thing and RGB Led.
To display a certain color, we must combine colors from red, green, blue. SparkFun
ESP8266 Thing provides API for PWM like Arduino API such as analogWrite() and
analogRead() but analog value from 0 to 1023.
Lets start to build a program. Firstly, open Arduino Software. Then, write these scripts.
int redPin = 4;
int greenPin = 13;
int bluePin = 12;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(115200);
}
void loop()
{
setColor(0, 1023, 1023); // red
Serial.println("red");
delay(1000);
setColor(1023, 0, 1023); // green
Serial.println("green");
delay(1000);
setColor(1023, 1023, 0); // blue
Serial.println("blue");
delay(1000);
setColor(0, 0, 1023); // yellow
Serial.println("yellow");
delay(1000);
setColor(700, 1023, 700); // purple
Serial.println("purple");
delay(1000);
setColor(1023, 0, 0); // aqua
Serial.println("aqua");
delay(1000);
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
5.2.3 Testing
Upload and run the program. You should see several color on RGB LED.
The following is a sample demo on RGB LED.
If you connect to SparkFun ESP8266 Thing board via Serial monitor tool from Arduino,
you should get program output, shown in Figure below.
5.3.1 Wiring
To understand Potentiometer, you see its scheme in Figure below.
You can connect VCC to SparkFun ESP8266 Thing board on 3V3 pin (VCC +3.3V). Vout
to SparkFun ESP8266 Thing board Analog input ADC (A0). In addition, GND
to SparkFun ESP8266 Thing board GND. The following is hardware implementation. I
use slide potentiometer.
5.3.3 Testing
Upload and run this program. If success, you can see analog value using Serial Monitor
tool from Arduino IDE.
In this chapter we learn how to work with I2C on SparkFun ESP8266 Thing board using
Arduino program.
For testing, I used PCF8591 AD/DA Converter module with sensor and actuator devices.
You can find it on the following online store:
Amazon, http://www.amazon.com/PCF8591-Converter-Module-DigitalConversion/dp/B00BXX4UWC/
eBay, http://www.ebay.com
Dealextreme, http://www.dx.com/p/pcf8591-ad-da-analog-to-digital-digital-to-
analog-converter-module-w-dupont-cable-deep-blue-336384
Aliexpress, http://www.aliexpress.com/
In addition, you can find this device on your local electronics store/online store.
This module has mini form model too, for instance, you can find it on Amazon,
http://www.amazon.com/WaveShare-PCF8591T-Converter-EvaluationDevelopment/dp/B00KM6X2OI/ .
This module use PCF8591 IC and you can read the datasheet on the following URLs.
http://www.electrodragon.com/w/images/e/ed/PCF8591.pdf
http://www.nxp.com/documents/data_sheet/PCF8591.pdf
In this chapter, we build a program to access sensor via I2C using Arduino software
on SparkFun ESP8266 Thing board.
ADC3=Wire.read();
Serial.print("potentiometer=");
Serial.println(ADC3);
delay(500);
}
6.4 Testing
Now you can upload and run the program to SparkFun ESP8266 Thing board board.
If success, open Serial monitor tool and connect to SparkFun ESP8266 Thing to see the
program output. The following is a sample output.
7. SPI
In this chapter Im going to explain how to work with SPI on SparkFun ESP8266 Thing
board.
You can see these SPI pins on SparkFun ESP8266 Thing board, shown in Figure below.
We can only use one SPI on SparkFun ESP8266 Thing board with SPI master mode. We
develop program based SPI using SPI library, https://www.arduino.cc/en/Reference/SPI .
In this chapter, we build a SPI Loopback app. Lets start!.
7.2 Wiring
To develop SPI loopback, we can connect MOSI pin to MISO pin. This means you
connect pin 13 to pin 12 using cable.
The following is a sample of wiring.
7.4 Testing
Now you can upload program to SparkFun ESP8266 Thing board. If done, open Serial
Monitor tool from Arduino. You should see received data from SPI.
8. Connecting to a Network
In this chapter Im going to explain how to connect a network from SparkFun ESP8266
Thing.
Change baudrate with 115200. Then, compile and upload the program into SparkFun
ESP8266 Thing board.
#include "ESP8266WiFi.h"
void setup() {
Serial.begin(115200);
After that, open Serial Monitor. You should see a list of WiFi hotspot.
// Match the request
int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
Serial.println("invalid request");
client.stop();
return;
}
// Set GPIO2 according to the request
digitalWrite(5, val);
client.flush();
Now you compile and upload the program into SparkFun ESP8266 Thing board. Then,
open Serial Monitor. You should see IP Address of SparkFun ESP8266 Thing board.
To test, you can open a browser and navigate to http://<board_ip>/gpio/1 to turn on LED.
You should see a lighting LED on board. Otherwise, you can navigate
to http://<board_ip>/gpio/0 to turn off LED.
Source Code
Contact