EasyESP-1 – Embedded Lab http://embedded-lab.com/blog Embedded Systems tutorials, projects, and more ... Wed, 25 Nov 2020 03:49:55 +0000 en-US hourly 1 https://wordpress.org/?v=5.1.8 Tutorial 9: ESP8266 and WS2812B RGB LED (or NeoPixel) ring http://embedded-lab.com/blog/tutorial-9-esp8266-ws2812b-rgb-led-neopixel-ring/ http://embedded-lab.com/blog/tutorial-9-esp8266-ws2812b-rgb-led-neopixel-ring/#respond Thu, 18 May 2017 22:09:28 +0000 http://embedded-lab.com/blog/?p=13477 This tutorial describes how to interface a WS2812B RGB LED ring or Adafruit’s NeoPixel ring to ESP8266. The WS2812B is a smart RGB LED with a control circuit integrated in a 5050 SMD package. The RGB data transfer occurs through a single data input line using single NZR communication mode.

EasyESP-1 driving NeoPixel ring

EasyESP-1 driving NeoPixel ring

Connection between the NeoPixel ring and ESP8266 is through a single data wire. I am using EasyESP-1 here for illustration. The Data In (DI) line of the NeoPixel ring connects to D1 pin of EasyESP-1. VCC and GND pins go to 3.3V and GND terminals of EasyESP-1. I used a 40 RGB LED NeoPixel-compatible LED ring from Elecrow for this experiment.

setup

Wiring RGB LED ring to EasyESP-1

wiring

Power supply and data input pins on the back of Elecrow’s RGB LED ring

For programming the ESP8266 to drive the RGB ring, you will need to install Adafruit’s NeoPixel Library. The library comes with several examples which can be tested with the current setup with a very little modification in the code. Once the library is installed, open RGBWstrandtest example and modify the following two lines as follows:

#define PIN D1
#define NUM_LEDS 40

That’s all you need to change to run this example with the current setup of the EasyESP-1 and RGB LED ring.

Note that you must have your Arduino IDE setup to program ESP8266 according to the instructions posted in Tutorial 1: Setting up the Arduino IDE for EasyESP-1 prior to run this example.

Then upload the modified example code and see the output.

v

RGBWstrandtest output

Buy EasyESP-1 board

More tutorials

EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266
TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1
TUTORIAL 2: EASYESP-1 “HELLO WORLD” EXAMPLE
TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266
TUTORIAL 4: WORKING WITH ESP8266 WIFI SCAN CLASS
TUTORIAL 5: SETTING UP AN ESP8266 WEB SERVER
TUTORIAL 6: ESP8266 AND BME280 MAKE A LOCAL/REMOTE WEATHER STATION
TUTORIAL 7: ESP8266 AND ILI9341 TFT LCD
TUTORIAL 8: ESP8266 INTERNET CLOCK
]]>
http://embedded-lab.com/blog/tutorial-9-esp8266-ws2812b-rgb-led-neopixel-ring/feed/ 0
Heart rate monitoring over the internet using ESP8266 http://embedded-lab.com/blog/heart-rate-monitoring-internet-using-esp8266/ http://embedded-lab.com/blog/heart-rate-monitoring-internet-using-esp8266/#comments Sun, 26 Feb 2017 20:54:44 +0000 http://embedded-lab.com/blog/?p=13228 With the rapid development and maturing of internet-of-things (IoT) technology, the IoT-driven smart sensors and systems are changing business in multiple industries. In healthcare industry, it is gaining more attention lately because of its immense potential in reducing the cost of tracking health information, as well as in providing health care to people who were not able to receive it before. This project describes a simple remote heart rate monitoring system based on the ESP8266 platform and the Easy Pulse Plugin sensor module. The ESP8266 reads in the analog photoplethysmograph (PPG) output from the Easy Pulse sensor, computes the heart beat rate in real time, and post it to a Google spreadsheet for remote access. A TFT LCD is also installed to display the PPG waveform and pulse rate locally.

Pulse meter

IoT enabled pulse meter

Hardware

For just the IoT capability of this project, you only need an ESP8266 module and the Easy Pulse Plugin sensor. If you like to display the PPG waveform and pulse rate locally, you will also need an ILI9341-based TFT LCD. You would also need to read my Tutorial 7 on how to use an ILI9341 TFT display with ESP8266. For illustration of this project, I am using EasyESP-1 board. But you can do this with NodeMCU or any other ESP8266 breakout board that has adequate GPIOs to drive the TFT and access to the ESP8266 analog input.

Hardware required:

Easy Pulse sensor setup

Easy Pulse Plugin operates on the principle of Photoplethysmography, which is an optical technique of sensing blood volume changes in tissues by illuminating the skin surface with a light source and measuring the reflected or transmitted light using a photodetector. The photodetector output contains the cardiovascular pulse wave, which is synchronized with the beating of the heart. Easy Pulse Plugin provides all necessary instrumentation and amplification on board to detect the cardiovascular pulse signal from the fingertip. The most important characteristics of Easy Pulse Plugin is that it can be easily plugged into the left headers of Arduino Uno (or its compatible clone) board for easy interfacing, and the analog pulse signal can be fed to either A0 or A1 analog input through a 2-pin jumper selection. It can also be plugged into a breadboard for prototyping with other microcontroller platforms. You can buy this sensor at our Tindie Store as well as from Elecrow with worldwide shipping.

For this project, the jumper settings of Easy Pulse module are as follows (also see the following picture).

  • JP1 is set to 3.3V, which means the analog PPG output swing range is 3.3V max.
  • JP2 is set to A0, which means the analog PPG signal is available at A0 pin.
JP1 and JP2 shunt jumper settings for this project. The PPG signal is available at A0 header pin.

JP1 and JP2 shunt jumper settings for this project. The PPG signal is available at A0 header pin.

The Easy Pulse Plugin module is plugged into the breadboard area of EasyESP-1 board. The 3.3V, GND, and A0 pins are connected to the 3.3V, GND, and AN header pins of EasyESP-1 board, respectively. The TFT LCD connections are same as described in Tutorial 7, and are also shown below.

Connections between ILI9341 SPI TFT module and EasyESP-1

Connections between ILI9341 SPI TFT module and EasyESP-1

pulse1

Complete project hardware setup

Software

There are two parts of the software for this project. The first part involves writing the firmware for ESP8266 using Arduino IDE. This part covers analyzing the Easy Pulse sensor output, processing the PPG signal to compute the heart beat rate, displaying it on the local TFT display, and connecting to a Google script to post the heart beat rate to a spreadsheet over the internet. Posting the data to a Google spreadsheet follows the same technique as described by Anir in this tutorial. The second part of the software development involves writing the Google script that will receive the heart beat rate from ESP8266 and post it on a Google spreadsheet.

The ESP8266 software written in Arduino IDE can be downloaded from the following link.

Download ESP8266 Arduino Code

You need to install the following Arduino libraries prior to compile the above code.

TFT ILI9341 ESP library

HTTPSRedirect library from Sujay Phadke

Read HOW TO POST DATA TO GOOGLE SHEETS USING ESP8266 for more details on HTTPSRedirect library.

The ESP8266 digitizes the analog PPG signal using the ADC input channel. The sampling rate is 5 milliseconds. It acquires 600 samples at a time (in 3 seconds) and computes the instantaneous heart beat or pulse rate by detecting three consecutive peaks in the PPG waveform. The details of this algorithm of computing the heart beat rate is described in my previous project. The PPG waveform and so computed pulse rate are displayed on the TFT LCD. In order for the ESP8266 to post the data to Google sheet, you need to make the following changes to the ESP8266 program.

  1. Update the ssid and password in the code to match to your WiFi network.
  2. Also, you will also need to update the *GScriptId, which can only be obtained after publishing the required Google App Scripts, which is discussed below. So, you can’t upload this code to your ESP8266 until you have your GScriptId ready.
const char* ssid = "Your SSID"; 
const char* password = "Your Password";
const char *GScriptId = "Your GScriptid";
Google scripts

Next step is to prepare a spread sheet in your Google drive and create a Google App script to access it via URL. First, create a Google spreadsheet in your Google Drive and name it something, say IoTPulseDemo. Rename the current/active sheet to DataLogger. From the URL address bar of the sheet, copy the string between d/ and /edit and save it somewhere. This is your spreadsheet’s unique sharing key, which will be needed in the Google Apps scripts later. In the DataLogger sheet, type ID, Time, and Value in A1, B1, and C1 cells, respectively. See the screenshot posted below.

Preparing the spreadsheet

Preparing the spreadsheet

Next, to create a Google App Scripts, go to Tools > Script Editor from the Google Sheets. The Script Editor opens in a new tab. Then copy the Google App Script code from the following .txt file and paste it there. The code or script can be saved under any name.

Download Google App Script

It is important that the sheet name in the script should match to that you want to be populated.

    var dataLoggerSheet = ss.getSheetByName("DataLogger");

Similarly, you would also need to edit the spreadsheet sharing key in the script to match with yours (one you copied from the spreadsheet URL earlier).

var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/---Your-Google-Sheet-ID--Goes-Here---/edit");
Deploy the contents as Web app

Next step is to publish the script so that it is accessible through an URL. In order to do that, select Publish > Deploy as Web App from your gscript editor window. Make sure you allow the access to the app to “Anyone, even anonymous“, as shown below.

Deploy

Deploying the script as Web App

Note: Whenever you modify your code, you have to create a “New” Project version and publish it otherwise you will still be hitting the same old code.

Copy the Current web app URL and save it somewhere as we will need it for extracting the GScriptID. The web app URL would look like this:

https://script.google.com/macros/s/AKfycbwULslNgkwvNQfKcsXJPVygL9uO/exec

The string between s/ and /exec is your GScriptID. Copy this GScriptID and paste it to your ESP8266 Arduino code,

const char *GScriptId = "paste here";

Now your ESP8266 code is complete and can be uploaded to the ESP8266 module.

During script publishing, Google will ask to grant some of the permissions and you need to allow those.

Output

After uploading the firmware to ESP8266 and publishing the Web App, the heart rate monitoring project is ready to run. Wear the pulse sensor on the tip of your index finger and power the EasyESP-1 board. In the beginning, the ESP8266 runs the setup program that performs TFT LCD initializing and connecting to your WiFi network. You can open a serial monitor window on the Arduino IDE to check the progress. After the setup is complete, you will see a PPG waveform derived from 600 analog samples displayed on the TFT screen. The pulse rate in BPM is also shown. The ESP8266 accesses the Google App script via URL using the GScriptID to send the pulse rate. The Google script then posts the pulse rate and time stamp to DataLogger spreadsheet. If you open the spreadsheet on your Google drive, you will see it populated continuously as the ESP8266 sends the data.

Pulse2

Local display of PPG waveform and pulse rate

DataLogger sheet populates with pulse rate data and time stamp

DataLogger sheet populates with pulse rate data and time stamp

You can also use Google sheet chart feature to visualize the pulse rate variation over time.

Pulse rate tracking over time

Pulse rate tracking over time

]]>
http://embedded-lab.com/blog/heart-rate-monitoring-internet-using-esp8266/feed/ 4
Tutorial 8: ESP8266 Internet clock http://embedded-lab.com/blog/tutorial-8-esp8266-internet-clock/ http://embedded-lab.com/blog/tutorial-8-esp8266-internet-clock/#comments Wed, 08 Feb 2017 20:26:52 +0000 http://embedded-lab.com/blog/?p=13187 The National Institute of Standards and Technology (NIST) provides official time in the United States. NIST disseminates the time using several methods, including radio broadcasting over short-wave and long-wave frequencies, telephone dial-in services (ACTS), and Network Time Service (NTS) over the internet. This tutorial describes how to build an ESP8266-based internet clock that uses NIST’s NTS service to retrieve accurate time information. The time is displayed on a colorful TFT LCD (ILI9341 driven) in both analog clock dial and digital formats. The time is synchronized to the NIST server in every 2-minute interval.

ESP8266 Internet Clock

ESP8266 Internet Clock

Hardware

This project uses an ESP8266 module to connect to the NIST time server through a local home/office WiFi. I am using EasyESP-1 board for illustration. The time will be displayed on a 2.2″ ILI9341-driven TFT LCD. Please read Tutorial 7 for more details on how to interface the TFT LCD to EasyESP-1. The hardware setup for this project is same as for Tutorial 7.

Complete setup of LCD on the EasyESP-1 breadboard

Complete setup of LCD on the EasyESP-1 breadboard for Internet Clock

Software

As discussed in Tutorial 7, we will use the same TFT ILI9341 ESP library by Bodmer in this project too. The library comes with some really cool demo examples. This tutorial actually incorporates their TFT_Clock example for displaying time in an analog clock dial format. There are several examples available online showing how to implement Network Time Protocol (NTP) in Arduino to fetch time from NIST server. NIST operates several time servers for its Internet Time Service (ITS). The list of these time servers and their IP addresses can be found here. Note that NIST does not allow queries to any of their servers more frequently than once every 4 seconds. In this project, the queries are made once every two minutes. In between the queries, which is a 2-minute interval, the time is kept running locally using the delay() routine. You can download the complete ESP8266 Firmware for this project from the following link.

Download Internet Clock ILI9341 code

Important notes:

  • The time-fetching code was derived from Kev_MacD‘s instructables on Steampunk ESP8266 Internet connected Clock.
  • In the code, you need to change the network SSID and password to match to your network.
  • In addition, you also need to adjust the GMT offset for your location to get the correct local time. For example, the GMT offset for EST is -5 (int hours_Offset_From_GMT = -5;).
  • The display part of the code uses the TFT ILI9341 ESP library. You can read more about it in Tutorial 7.
  • The time is displayed in 12 hour format on analog dial as well as in 24 hour digital format .
Internet clock

ESP8266 Internet clock

Buy EasyESP-1 board

More tutorials

EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266
TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1
TUTORIAL 2: EASYESP-1 “HELLO WORLD” EXAMPLE
TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266
TUTORIAL 4: WORKING WITH ESP8266 WIFI SCAN CLASS
TUTORIAL 5: SETTING UP AN ESP8266 WEB SERVER
TUTORIAL 6: ESP8266 AND BME280 MAKE A LOCAL/REMOTE WEATHER STATION
TUTORIAL 7: ESP8266 AND ILI9341 TFT LCD
]]>
http://embedded-lab.com/blog/tutorial-8-esp8266-internet-clock/feed/ 4
Tutorial 7: ESP8266 and ILI9341 TFT LCD http://embedded-lab.com/blog/tutorial-7-esp8266-ili9341-tft-lcd/ http://embedded-lab.com/blog/tutorial-7-esp8266-ili9341-tft-lcd/#comments Wed, 08 Feb 2017 02:50:43 +0000 http://embedded-lab.com/blog/?p=13194 In tutorial 3, we discussed how to use an SSD1306-driven I2C OLED screen with EasyESP-1 for displaying basic text and graphics. We used a 0.96″ (along the diagonal) 128×64 monochrome pixels OLED display for illustration. Despite its small size, the readability was pretty good due to its high contrast, which makes it a very good, compact size display for general applications. The excitement of having a display screen in an ESP8266 project can be further enhanced by upgrading the choice of display to colorful TFT LCD. One such screen that is readily available in the market at affordable price is ILI9341 based TFT LCDs. This tutorial describes the method to connect such displays with ESP8266 using Arduino IDE.

Interfacing an ILI9341 TFT LCD

Interfacing an ILI9341 TFT LCD

Hardware

The datasheet of ILI9341 driver chip states:

ILI9341 is a 262,144-color single-chip SOC driver for a-TFT liquid crystal display with resolution of 240RGBx320 dots, comprising a 720-channel source driver, a 320-channel gate driver, 172,800 bytes GRAM for graphic display data of 240RGBx320 dots, and power supply circuit. ILI9341 supports parallel 8-/9-/16-/18-bit data bus MCU interface, 6-/16-/18-bit data bus RGB interface and 3-/4-line serial peripheral interface (SPI). The moving picture area can be specified in internal GRAM by window address function. The specified window area can be updated selectively, so that moving picture can be displayed simultaneously independent of still picture area.

You can find ILI9341-based TFT displays in various sizes on eBay and Aliexpress. The one I chose for this tutorial is 2.2″ length along the diagonal, 240×320 pixels resolution, supports SPI interface, and can be purchased for less than $10.

2.2" TFT LCD used in this tutorial

2.2″ TFT LCD used in this tutorial is bought from a Chinese store on Aliexpress

The connections between the TFT display and EasyESP-1 pins are as follows.

Connections between ILI9341 SPI TFT module and EasyESP-1

Connections between ILI9341 SPI TFT module and EasyESP-1

Note that we will be using the hardware SPI module of the ESP8266 to drive the TFT LCD. The SPI communication pins are multiplexed with I/O pins D5 (SCK), D6 (MISO), and D7 (MOSI). The chip select (CS) and Data/Command (DC) signal lines are configurable through software.

Complete setup of LCD on the EasyESP-1 breadboard

Complete setup of LCD on the EasyESP-1 breadboard

Software

For ILI9341-based TFT displays, there are some options for choosing the library for your application. The most common one is using Adafruit’s library for ILI9341 display. You will also need their GFX-library with this. There’s another one that I recently discovered named TFT ILI9341 ESP, and is more versatile than the Adafruit’s library. This is shared on github by Bodmer. We will use this library in this tutorial. So go ahead and download the TFT ILI9341 ESP library, and install it in your Arduino/libraries folder.

About this library (in Author’s words):

An Arduino IDE compatible graphics and fonts library for ESP8266 processors with a driver for the ILI9341 based TFT displays.

The library contains proportional fonts, different sizes can be enabled/disabled at compile time to optimise the use of FLASH memory. The library has been tested with the NodeMCU (ESP8266 based).

The library is based on the Adafruit GFX and Adafruit ILI9341 libraries and the aim is to retain compatibility. Significant additions have been made to the library to boost the speed for ESP8266 processors (it is typically 3 to 10 times faster) and to add new features. The new graphics functions include different size proportional fonts and formatting features. There are a significant number of example sketches to demonstrate the different features.

Configuration of the library font selections, pins used to interface with the TFT and other features is made by editting the User_Setup.h file in the library folder. Fonts and features can easily be disabled by commenting out lines.

As mentioned by the author, you need to open the User_Setup.h file inside the main library folder and modify the following two lines to match with our setup.

#define TFT_CS D2 // Chip select control pin
#define TFT_DC D1 // Data Command control pin

Now you are all set to try out tons of really cool built-in examples that come with the library. The following output corresponds to the TFT_Pie_Chart example.

Drawing a colorful Pi Chart on TFT screen

Drawing a colorful Pi Chart on TFT screen

There is an example (TFT_Rainbow_one_lib.ino) for showing different size text fonts with rainbow colors in the background that looks pretty cool.

Rainbow colors demo

Rainbow colors demo

fonts

Another example of printing texts with different font sizes and colors

My favorite example is TFT terminal, which implements a simple “Arduino IDE Serial Monitor” like serial receive terminal for monitoring debugging messages from another Arduino or ESP8266 board.

serialterminal

Serial receive terminal example

Buy EasyESP-1 board

More tutorials

EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266
TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1
TUTORIAL 2: EASYESP-1 “HELLO WORLD” EXAMPLE
TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266
TUTORIAL 4: WORKING WITH ESP8266 WIFI SCAN CLASS
TUTORIAL 5: SETTING UP AN ESP8266 WEB SERVER
TUTORIAL 6: ESP8266 AND BME280 MAKE A LOCAL/REMOTE WEATHER STATION
]]>
http://embedded-lab.com/blog/tutorial-7-esp8266-ili9341-tft-lcd/feed/ 2
Tutorial 6: ESP8266 and BME280 make a local/remote weather station http://embedded-lab.com/blog/tutorial-6-esp8266-bme280-make-localremote-weather-station/ http://embedded-lab.com/blog/tutorial-6-esp8266-bme280-make-localremote-weather-station/#comments Sun, 05 Feb 2017 21:21:45 +0000 http://embedded-lab.com/blog/?p=13152 In previous tutorials, we explored how to connect an SSD1306-based I2C OLED to ESP8266 for displaying texts and graphics, as well as to setup an ESP8266-based web server. This tutorial combines the knowledge gained before to make a standalone weather station that will display the local weather data on an OLED screen. In addition, the weather station will also run a web server that would allow a remote computer to access the weather data via web browser.

dsds

BME280 weather station

Hardware Setup

This project uses the EasyESP-1 board and the following hardware devices.

BME280 sensor module: BME280 is a fully integrated environmental unit from Bosch that combines sensors for pressure, humidity, and temperature in a tiny 8-pin metal-lid LGA package of size 2.5 x 2.5 x 0.93 mm³. Because of its compact size, ease of use (BME280 supports standard I2C and SPI interfaces), and availability of supporting open-source Arduino libraries, BME280 is very popular among weather enthusiasts. You can buy a BME280 sensor module in Grove form factor from Elecrow.

SSD1306 I2C OLED module: As described in Tutorial 3, the SSD1306 OLED controller supports both SPI and I2C interfaces. We will use an I2C version with a 0.96″ diagonal length and 128×64 monochrome pixels OLED Grove board. Despite its small size, the readability is pretty good due to its high contrast.

For this experiment, the 4-pin Grove connectors of BME280 and OLED modules are directly plugged into the two I2C ports on the EasyESP-1 board, as shown below. This connects the the SDA and SCK pins of BME280 and OLED modules to D2 and D1 pins of EasyESP-1, respectively.

Complete project setup

Complete project setup

BME280 and OLED connect to I2C Grove ports

BME280 and OLED connections to I2C Grove ports

Software

The ESP8266 firmware for this project is developed using Arduino IDE. You need to install the ESP8266 core to enable the Arduino IDE for ESP8266 programming. Instructions can be found here. You will also need the following Adafruit libraries for reading data from the BME280 sensor. The I2C address of BME280 sensor on Elecrow’s sensor board is 0x77, which is also the default address set in the Adafruit’s library.

Adafruit unified sensor library

Adafruit BME280 library

Besides, you also need Daniel Eichhorn‘s OLED library for ESP8266. Read Tutorial 3 for more details on this.

The complete code for this weather station project can be downloaded from the following link:

Download BME280 Weather Station Code

The code for a very basic HTML webpage with the BME280 sensor output and auto refresh meta tag is included in the code. Note that you need to edit the SSID name and password in the program to match with your WiFi network before uploading it to the EasyESP-1 board.

Output

After uploading the program to EasyESP-1, when the ESP8266 restarts it prints out on the serial monitor the local IP address that was allocated to it in the WiFi network. The BME280 sensor readings for temperature, pressure and humidity are displayed on the OLED screen. In order to access these data over the web server, you need to open a web browser on any computer, tablet, or smartphone connected to the same WiFi network and type in the ESP8266 IP address in the URL field and hit enter. On receiving a client request, the ESP8266 serves a webpage containing the BME sensor readings, as shown below.

BME280 local weather station

BME280 local weather station

Web

Weather data displayed on client’s browser

Buy EasyESP-1 board

Buy BME280 sensor module 

Buy SSD1306 I2C OLED module

More tutorials

EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266
TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1
TUTORIAL 2: EASYESP-1 “HELLO WORLD” EXAMPLE
TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266
TUTORIAL 4: WORKING WITH ESP8266 WIFI SCAN CLASS
TUTORIAL 5: SETTING UP AN ESP8266 WEB SERVER
]]>
http://embedded-lab.com/blog/tutorial-6-esp8266-bme280-make-localremote-weather-station/feed/ 2
Tutorial 5: Setting up an ESP8266 Web Server http://embedded-lab.com/blog/tutorial-5-setting-esp8266-web-server/ http://embedded-lab.com/blog/tutorial-5-setting-esp8266-web-server/#respond Sat, 04 Feb 2017 02:02:44 +0000 http://embedded-lab.com/blog/?p=13141 In this tutorial, we will explore how to setup an ESP8266 web server to serve an webpage that can be displayed on a client’s browser. The client can be any other computer, smartphone, or tablet connected to the same WiFi network. The webpage will also provide an user interface to allow you to toggle an I/O pin of the ESP8266 hardware.

ESP8266 Webserver setup tutorial

ESP8266 Webserver setup tutorial

Hardware Setup

There is nothing much to do in the hardware setup of this experiment. In your EasyESP-1 board, all you need to do is to connect the LD1 pin to D1 pin using a jumper cable. This will connect the LD1 LED on board to the D1 I/O pin of the ESP8266.

Setup

Hardware Setup

Software

As mentioned above, this tutorial illustrates how to create a standalone local web server using EasyESP-1. The web server will respond to a client’s request with a web page that will allow the user to toggle the LED connected to the D1 I/O pin. The first step to do that is to create a server object, which is done with the following statement.

WiFiServer server(80);

The server will respond to clients on port 80. You need to provide the credentials (network SSID and password) to connect to the chosen WiFi network. You can initiate the connection using WiFi.begin(ssid, password) function. Once connected to the network, you can find out the local IP address assigned to your ESP8266 using WiFi.localIP(). The complete code for this tutorial is posted below. The content of the webpage is defined in the string variable HTMLpage.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
 
ESP8266WebServer Webserver(80);
 
// Replace with your network credentials
const char* ssid = "your network ssid";
const char* password = "password";
 
String HTMLpage = "";
int LED = D1;
 
void setup(void){
  HTMLpage += "<head><title>Webserver Tutorial</title></head><h3>ESP8266 Webserver Demo (Toggle LED)</h3><p>LED <a href=\"ledON\"><button>ON</button></a>&nbsp;<a href=\"ledOFF\"><button>OFF</button></a></p>";
 
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");
 
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
 
  if (MDNS.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
 
  Webserver.on("/", [](){
    Webserver.send(200, "text/html", HTMLpage);
  });
  Webserver.on("/ledON", [](){
    Webserver.send(200, "text/html", HTMLpage+"<p>LED is ON</p>");
    digitalWrite(LED, HIGH);
    delay(1000);
  });
  Webserver.on("/ledOFF", [](){
    Webserver.send(200, "text/html", HTMLpage+"<p>LED is OFF</p>");
    digitalWrite(LED, LOW);
    delay(1000); 
  });
 
  Webserver.begin();
  Serial.println("HTTP Webserver started");
}
 
void loop(void){
  Webserver.handleClient();
}

Download Webserver Tutorial code

Output

After uploading the web server code posted above (make sure you typed in your network credentials), open a Serial Monitor window for the IP address assigned to your EasyESP-1 board. If the connection to the selected WiFi network is successful, you will see the following output on the Serial Monitor window. The IP address displayed here is the IP address of the ESP8266 web server.

Serial Monitor terminal

Serial Monitor terminal output

Now open a browser on any computer or tablet connected to the same WiFi network and type that IP address in the URL field and hit Go. You will see the web page served by the EasyESP-1 as follows.

WebServer1

Web server home page

Now if you press ON button, the browser will send that info to the server, and the ESP8266 will turn ON the LED connected to D1 pin. Similarly, clicking on OFF button will turn the LED OFF.

WebServer2 WebServer3

Toggling LED via web server

Toggling LED via web server

Buy EasyESP-1 board

More tutorials

EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266
TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1
TUTORIAL 2: EASYESP-1 “HELLO WORLD” EXAMPLE
TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266
TUTORIAL 4: WORKING WITH ESP8266 WIFI SCAN CLASS
]]>
http://embedded-lab.com/blog/tutorial-5-setting-esp8266-web-server/feed/ 0
Tutorial 4: Working with ESP8266 WiFi Scan Class http://embedded-lab.com/blog/tutorial-4-working-esp8266-wifi-scan-class/ http://embedded-lab.com/blog/tutorial-4-working-esp8266-wifi-scan-class/#comments Fri, 03 Feb 2017 20:06:55 +0000 http://embedded-lab.com/blog/?p=13112 Working with ESP8266 WiFi functionality using Arduino IDE has been made surprisingly simple by the availability of the versatile ESP8266WiFi library that allows user to configure the ESP8266 as a WiFi network scanner, a WiFi station (connected to a WiFi network), a soft access point (creating it’s own WiFi network), etc. In this tutorial, we will explore the features of the Scan Class of the ESP8266WiFi library. The Scan Class allows you to scan and list the available WiFi networks in the range. In order to try this feature, open an example code from File->Examples->ESP8266WiFi->WiFiScan.

In the example code,

int n = WiFi.scanNetworks();

returns the number of WiFi networks found within the range. You can also print out the names and Received Signal Strength Indication (RSSI) values in dBm using WiFi.SSID() and WiFi.RSSI() functions.

WiFi Scanner example

WiFi Scanner example

The complete WiFi Scan example code is posted below.

/*
 * This sketch demonstrates how to scan WiFi networks. 
 * The API is almost the same as with the WiFi Shield library, 
 * the most obvious difference being the different file you need to include:
 */
#include "ESP8266WiFi.h"

void setup() {
 Serial.begin(115200);

 // Set WiFi to station mode and disconnect from an AP if it was previously connected
 WiFi.mode(WIFI_STA);
 WiFi.disconnect();
 delay(100);

 Serial.println("Setup done");
}

void loop() {
 Serial.println("scan start");

 // WiFi.scanNetworks will return the number of networks found
 int n = WiFi.scanNetworks();
 Serial.println("scan done");
 if (n == 0)
 Serial.println("no networks found");
 else
 {
 Serial.print(n);
 Serial.println(" networks found");
 for (int i = 0; i < n; ++i)
 {
 // Print SSID and RSSI for each network found
 Serial.print(i + 1);
 Serial.print(": ");
 Serial.print(WiFi.SSID(i));
 Serial.print(" (");
 Serial.print(WiFi.RSSI(i));
 Serial.print(")");
 Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
 delay(10);
 }
 }
 Serial.println("");

 // Wait a bit before scanning again
 delay(10000);
}

Upload the example code to your EasyESP-1 board and open the Serial Monitor window. You will see the ESP8266 prints out the list of available WiFi networks on the screen, as shown below.

WiFi scanner output

WiFi scanner output

Buy EasyESP-1 board

More tutorials

EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266
TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1
TUTORIAL 2: EASYESP-1 “HELLO WORLD” EXAMPLE
TUTORIAL 3: CONNECTING AN OLED DISPLAY TO ESP8266

 

]]>
http://embedded-lab.com/blog/tutorial-4-working-esp8266-wifi-scan-class/feed/ 1
Tutorial 3: Connecting an OLED display to ESP8266 http://embedded-lab.com/blog/tutorial-3-connecting-oled-display-esp8266/ http://embedded-lab.com/blog/tutorial-3-connecting-oled-display-esp8266/#respond Thu, 02 Feb 2017 00:45:08 +0000 http://embedded-lab.com/blog/?p=13085 Whether you want to show sensor readings, implement a navigational user interface menu, or display diagnostic information during prototyping a project, a graphic OLED display is always a cool add-on to embedded systems. In this tutorial, we will learn how to interface an I2C monochromatic OLED screen to ESP8266 (we will use EasyESP-1 board) using Arduino IDE. The OLED display used in this tutorial is SSD1306-based that can be bought for ~$5 on eBay or Aliexpress. You can also get a similar I2C OLED display with a grove connector from Elecrow for plug-and-play interfacing with the EasyESP-1 board.

Interfacing an SSD1306-based I2C OLED to EasyESP-1

Interfacing an SSD1306-based I2C OLED to EasyESP-1

Buy EasyESP-1 board

Hardware Setup

The I2C OLED breakout board chosen for this tutorial consists of a 0.96″ diagonal length display with 128×64 monochrome pixels. Despite its small size, the readability is pretty good due to its high contrast. Individual pixels are turned on or off by the on-board SSD1306 controller chip that supports both SPI and I2C interface. This tutorial uses an OLED display with I2C interface and has only four signal lines, namely VCC, GND, SCL, and SDA. For this experiment, these pins are connected to 3.3V, GND, D1, and D2 pins on the EasyESP-1 board, respectively.

SSD1306 based 0.96" OLED display module

SSD1306 based 0.96″ OLED display module

Wiring OLED pins to the EasyESP-1 board

Wiring OLED pins to the EasyESP-1 board

If you would like to use a grove OLED module, it can be connected to one of the I2C port on the EasyESP-1 board, as shown below.

Connecting a grove OLED

Connecting a grove OLED to I2C connector on the EasyESP-1 board

Software

There are several libraries available to support the SSD1036-based OLEDs for Arduino platform. For ESP8266, I would suggest to use one written by Daniel Eichhorn from squix. It supports both I2C and SPI versions of SSD1306 based 128×64 pixel OLED displays on the Arduino/ESP8266 platform. The library is very versatile and supports drawing pixels, lines, rectangles, and text of different font sizes. You can download this from the following github link.

https://github.com/squix78/esp8266-oled-ssd1306

Installation and setup of an external user library to Arduino IDE is easy. First, download the zipped library folder to your machine. Then unzip it and move the unzipped library folder to your Documents/Arduino/libraries/ location. You need to restart the Arduino IDE in order to use it in your new application.

After installing the OLED library, it’s time to try some built-in examples that come with the library. Open File->Examples->ESP8266 Oled Driver for SSD1306 display-> SSD1306SimpleDemo.

fgf

Testing OLED examples

The example programs are configured for I2C version of SSD1306 OLED by default. So, the only thing that you need to modify in the example code is to assign the correct ESP8266 I/O pins for I2C communication. Note that the EasyESP-1 I2C ports use D2 for SDA and D1 for SCL. So find the following I2C initialization statement in the code and make the changes as

// Initialize the OLED display using Wire library
SSD1306 display(0x3c, D2, D1);

Next, compile the program and upload it to the EasyESP-1 board.

Output

The SSD1306SimpleDemo example cycles through all the basic features of the OLED library, like drawing pixels, rectangle, circles, texts, WiFi logo, etc.

Drawing concentric circles

Drawing concentric circles

OLED text output

OLED text output

You can also try running other examples in Daniel’s OLED library. There is one called SSD1306ClockDemo that displays an analog and digital clock on the LED screen. For this example, you will need to install the Arduino Time library.

Clock example

Clock example

Buy EasyESP-1 board

More tutorials

TUTORIAL 2: EASYESP-1 “HELLO WORLD” EXAMPLE
TUTORIAL 1: SETTING UP THE ARDUINO IDE FOR EASYESP-1
EASYESP-1: A RAPID PROTOTYPING AND DEVELOPMENT BOARD FOR ESP8266
]]>
http://embedded-lab.com/blog/tutorial-3-connecting-oled-display-esp8266/feed/ 0
Tutorial 2: EasyESP-1 “Hello World” Example http://embedded-lab.com/blog/tutorial-2-easyesp-1-hello-world-example/ http://embedded-lab.com/blog/tutorial-2-easyesp-1-hello-world-example/#respond Tue, 17 Jan 2017 19:33:11 +0000 http://embedded-lab.com/blog/?p=13015 After setting up the Arduino IDE to enable support for ESP8266, it’s time to write your first code for EasyESP-1 board. We will start with the classic hello world! example of electronics, a flashing LED. This is the best example to start with any new hardware platform as it gives us an opportunity to verify that the required software tools/drivers are installed properly and ready to rock.

Hardware Setup

In this example, we will connect the LD1 and D1 pins of J3 header together with a jumper wire as shown below. This will connect the LD1 LED near the bottom right corner of EasyESP-1 to the D1 I/O pin (or GPIO5) of ESP8266.

Connections for the “Hello World” example

Connections for the “Hello World” example

Software

Open a new window on Arduino IDE and select appropriate options for Boards, Serial Port, CPU frequency, and Upload speed. You need to choose NodeMCU 1.0 (ESP-12E Module) from Board menu, set CPU frequency to 80 MHz, Upload Speed to 115200, and match Serial Port to the one that your EasyESP-1 is connected to. Check out my previous tutorial “Getting started with EasyESP-1 using Arduino IDE” for more details on this. Your selected options are shown in the bottom tab of the Arduino IDE, make sure they match with the ones shown below.

IDE1

Arduino IDE option setup for EasyESP-1

As I described in the EasyESP-1 Introduction, EasyESP-1 uses the same I/O indexing as used by NodeMCU. This does not match with internal GPIO indexing. For example, pin D1 is actually mapped to internal GPIO5. In Arduino IDE, you can access this pin in both ways. For example, digitalWrite(D1, LOW) and digitalWrite(5, LOW) will both do the same thing, writes out logic ‘low’ to D1 pin. Next, copy the following code and paste it into your empty program window. The program is written to blink the LD1 LED at a rate of 1Hz. Save the code, verify it, and upload it to EasyESP-1 board in the same way as you do for Arduino.

/*
 Hello World example for EasyESP-1
 Blink the red LED (LD1) on the EasyESP-1 board at 1Hz
 */
 
#define LD1   D1  // Define LD1 as D1 I/O pin
// Alternatively, you can also define it as GPIO5
//#define LD1 5
 
void setup() {
  pinMode(LD1, OUTPUT); // Initialize LD1 as output
}
 
void loop() {
  digitalWrite(LD1, LOW);   // Turn ON LD1
  delay(500);               // Wait for 0.5 sec
  digitalWrite(LD1, HIGH);  // Turn it off
  delay(500);               // Wait for 0.5 sec
}

Output

If everything worked perfectly, you would see LD1 flashing at 1 Hz and with 50% duty cycle (i.e. on and off time are both 0.5 sec).

LD1 flashes at 1Hz rate

LD1 flashes at 1Hz rate

Buy EasyESP-1 board

]]>
http://embedded-lab.com/blog/tutorial-2-easyesp-1-hello-world-example/feed/ 0
Tutorial 1: Setting up the Arduino IDE for EasyESP-1 http://embedded-lab.com/blog/tutorial-1-setting-arduino-ide-easyesp-1/ http://embedded-lab.com/blog/tutorial-1-setting-arduino-ide-easyesp-1/#respond Tue, 17 Jan 2017 03:26:08 +0000 http://embedded-lab.com/blog/?p=13000 One of the simplest way to program the ESP8266 chip on board EasyESP-1 is using the Arduino IDE. Following steps describe how to enable the ESP8266 support in the Arduino environment.

Step 1 : Install Arduino IDE
The first step toward setting up the Arduino platform for programming EasyESP-1 is to download and install the Arduino IDE. Go to the Arduino website and download Arduino IDE 1.6.11.

Step 2: Install ESP8266 core package
Next step is to install the ESP8266 core for Arduino IDE. It is an add-on that allows to write sketches for ESP8266 using the Arduino IDE  and its libraries. The easiest way to install the ESP8266 core is by typing in http://arduino.esp8266.com/stable/package_esp8266com_index.json
into Additional Board Manager URLs field in the Arduino-> Preferences window (see figure below).

Adding ESP8266 support to Arduino IDE using Preferences window

Adding ESP8266 support to Arduino IDE using Preferences window

Click OK and then go to Boards Manager and install the ESP8266 core. It appears at the end of the list as esp8266 by ESP8266 Community (see figure below). Select 2.3.0 version from the dropdown list.

Installing ESP8266 core from Boards Manager

Installing ESP8266 core from Boards Manager

Step 3: Select the right board
Next you need to select NodeMCU 1.0 (ESP-12E Module) from Board menu.

Select NodeMCU 1.0 (ESP-12E Module)

Select NodeMCU 1.0 (ESP-12E Module)

Go to Tools and make sure the CPU Frequency is set to 80 MHz and Upload Speed to 115200. If not, change them to correct options.

CPU clock should be set to 80 MHz and Upload Speed to 115200

CPU clock should be set to 80 MHz and Upload Speed to 115200

Step 4: COM Port selection
Finally, you need to select the right COM port that your EasyESP board is connected to. Obviously, you need to connect the EasyESP-1 to the computer through a USB cable. If the driver for SiLabs CP2102 USB-UART device is installed properly, it will show up in the Arduino IDE Tools->Port list as a new serial port. In Windows machines it shows up as a new COMx port. The following figure shows how it appears on a MAC computer. You should select the matching serial port for the CP2102 device on EasyESP from the Port list.

Select the right serial port (MAC computer)

Select the right serial port (MAC computer)

Now you are all set to write and upload your first ESP8266 program using the Arduino IDE.

ESP8266 experimenting made easy with EasyESp-1

ESP8266 experimenting made easy with EasyESP-1

Buy EasyESP-1 board

]]>
http://embedded-lab.com/blog/tutorial-1-setting-arduino-ide-easyesp-1/feed/ 0