Author Archives: R-B

Tutorial 8: ESP8266 Internet clock

ESP8266 Internet Clock

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

Tutorial 7: ESP8266 and ILI9341 TFT LCD

Rainbow colors demo

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

Animated IoT clock that can’t be trusted

Animated IoT clock

An animated IoT clock shared by Tobozo Tagada does not use any RTC module orconnect to a NTP server to retrieve the time. It rather scans the open WiFi access points in its surrounding and extract the date/time from the “Date” HTTP header, if sent out by some. Trust this clock’s accuracy at your own risk. It uses WeMOS ESP8266 board and an OLED screen to display the time along with a pong animation in the background to “cut on the boringness of the clock”, as he said.

Expecting unknown networks to provide a HTTP header value and relying on it to estimate time is like counting on other people’s wealth to survive, hence the Hobo name.

The exclusive use of open access points removes the hassle of hardcoding SSID/password into the sketch but also compensates its lack of auth plus the fact that the optional NTP connexion attempt will always fail, unless the AP acts as.

The Pong animation with a bouncing rotating cube is there to cut on the boringness of the clock but also to demonstrate how this tiny OLED can animate fast (nearly 60fps).

Since it has trust issues, don’t trust this clock more than you would trust a stranger’s watch! The available space and power consumption won’t let it run more than a couple of hours on the LiPo anyway.

Animated IoT clock

Animated IoT clock

WiFi deauthentication attacker using ESP8266

Deauthentication attacker using ESP8266

The IEEE 802.11 (Wi-Fi) protocol contains a so-called deauthentication frame that are used as management frames to disconnect the links between stations and access points. Because management frames are often unencrypted, it is fairly easy to perform deauthentication attacks using a WiFi device by spoofing the MAC address of the access point. Alternatively, it can also be done by sending deauthentication frames to the access point with a clients’ MAC address as a destination. Spacehuhn has shared his ESP8266 based implementation of a deauthentication attacker on Github. It can disconnect any client from a network by repeatedly sending fake deauthentication frames. The attacker does not even need to be connected to the same network.

Deauthentication attacker using ESP8266

Deauthentication attacker using ESP8266

Basically it’s a device which performs a deauth attack. You select the clients you want to disconnect from their network and start the attack. As long as the attack is running, the selected devices are not able to connect to the network.

ESP8266 weather station with e-paper display

ESP8266 weather station with e-Paper display

A very cool-looking weather station using the ESP8266 WiFi module chip and a high resolution 7.4″ a-Si TFT active matrix Electronic Paper Display (EPD) module from Pervasive Displays shared by . The weather data are gathered from OpenWeatherMap service.

ESP8266 weather station with e-Paper display

ESP8266 weather station with e-Paper display

Most of the time the device stays in deep sleep mode consuming only 18 µA. While updating the weather power consumption varies from 80 to 150 mA. Update operation takes a few seconds, depending on WiFi router, DHCP server and internet connection speed. With 30 minute update interval 3000 mAh battery should last for a few months on one charge.

« Older Entries Recent Entries »