ESP32 boards are more powerful and come with interesting onboard features. ESP32 boards are slightly more expensive and may differ between the different flavours:
For our needs the ESP8266 ESP-12E boards suffice.
The following components were used:
The ESP8266 chip offers WLAN capabilities that Arduino boards do not offer. ESP-12E is the “12E” generation chip that is most common. “12F” has improved WLAN antenna design.
In code you typically use logical pin names like “5” for “GPIO5”. You can also use aliases (if defined in the board description file) like “D1” in this case. “SCL” is most likely not defined as an alias so you can’t use that. Physical pin numbers refer to the physical pins of the ESP8266 chip soldered on the breakout circuit board and are not used in code.
The Vin pin can be used to power a microcontroller from an external power source. If powered via USB, the Vin pin often connects directly to the USB +5V rail. Sometimes there is a diode in between as protection (resulting in a 0.5V voltage drop on the Vin pin) .
To power peripheral boards (Vcc and Gnd are often needed), you often borrow +5Vdc 500mA max from the Vin pin of a microcontroller when powered via USB.
NodeMCU ESP8266 ESP-12E ‘Lolin V3’ boards only offer +1.5Vdc on the Vin pin when powered via USB. Use the pin labelled ‘VV’ in white silkscreen text on the circuit board for +5Vdc instead.
Two-wire one-way communication bus using CL (= clock) and DA (= data) lines. Needs Vcc and GND to power slave boards.
Four-wire two-way communication bus using:
CLK = clock
MOSI = master out slave in = master send
MISO = master in slave out = master receive
CS = chip select
Needs Vcc and GND to power slave boards.
ESP8266 boards have two SPI buses. Most code examples use the GPIO12-15 bus.
A direct internet connection is required.
ArduinoIDE > Files > Preferences
Enter the following ‘Additional Boards Manager URL’:
After completing the above steps , go to Tools > Board > Board Manager…
Navigate to esp8266 and install the software for Arduino.
You can now upload code examples to NodeMCU ESP-12 boards.
Note: rename code example files to *.INO
Blinks the built-in LED.
Most Arduino boards have a built-in onboard LED and a matching pin alias “LED_BUILTIN” you can use in code. NodeMCU ESP12 boards use GPIO2 / D4 or GPIO16 / D0.
You can change the port assignment for the “LED_BUILTIN” alias in the Arduino IDE on the fly. This needs to be set before (compiling and) uploading code to the board:
Remember NodeMCU ESP8266 boards use active low port logic as ports can only source 12mA of current but can sink much higher currents. Single color LEDs typically draw 1.2Vdc and 20mA of current. So when you send “HIGH” or “1” the pin will be internally pulled down to ground voltage level and current will start to flow into the pin.
Same as before, but now we connect to the WLAN and run a web server. Check for the IP address of the ESP8266 board on your internet router and connect to the web page running on that IP address to toggle to LED status.
We use a 16×2 character display connected to an LCD I2C backpack module. This module provides I2C / SPI two wire communication for 1602 to 2004 character LCD displays. This is used to save on the number of pins required to drive a typical Hitachi HD44780 character LCD display.
Most 16×2 LCD displays operate on 5Vdc, some may operate on 3Vdc.
GND connects to ESP8266 pin GND
VCC connects to ESP8266 pin Vin for 5V or 3V3 for 3V
SDA connects to ESP8266 pin GPIO4
SCL connects to ESP8266 pin GPIO5
The default address for I2C / SPI communication is 0x27. You can change the address using A01 A1 A2 solder pads:
Important: The library LiquidCrystal_I2C suitable for ESP8266 boards can be found here:
Download as ZIP and exrtact to folder “C:\Users\\<username>\My Documents\Arduino\libraries\LiquidCrystal_I2C\”
This utility discovers I2C addresses on the I2C bus and reports them in plain text over the serial port.
LCD Custom Character Generator:
You can use this to generate a custom character:
You can use custom characters to build big numbers that cover two rows of a LCD character display:
A slightly different font:
Numbers only. Relatively simple to use. Feel free to replace library references to LiquidCrystal.h with LiquidCrystal_I2C.h
displayLargeNumber(number to display, column position first digit) displayLargeInt(integer to display, column position first digit, number of digits to display for fixed length, display leading zeros true/false) clearLargeNumber(column position topleft corner)
Complete font. First attempt at storing in a very efficient lookup table. Special case for wider-than-usual characters e.g. M,N,Q,V,W. Plain code; not an Arduino library on Github.
Here someone created a 2×3, 3×3 and 4×4 font set for 20×4 character LCD displays. Contains preview images of what the fonts look like on an LCD screen, which is essential.
Contains 4 fonts with numbers only (Trek, Tron, Nasa, Serif). Code is easy to read. Library is available in Arduino Library Manager search. Does not contain wider-than-usual characters. Feel free to replace library references to LiquidCrystal.h with LiquidCrystal_I2C.h
The Bosch BMW280 sensor measures temperature, humidity and barometric pressure (which can be used to calculate altitude based on a reference barometric pressure at sealevel value). Trends in barometric pressure are used to predict weather (rain/clouds versus sun/clear).
Note: most boards offer only I2C communication with SPI only available on slightly more expensive boards.
Sensors are quite accurate. Temperature is typically consistently 1.5 deg Celcius higher than actual due to internal heating of the integrated circuit. Simply compensate for this in code.
Using I2C communication:
Important: Adafruit_Sensor.h = Tools > Manage Libraries > Search > “adafruit” and select “Adafruit Unified Sensor by Adafruit”
To change the address, use the solder jumpers:
This example fetches internet time and date using the time.h library at certain intervals:
Note: timezone value is the UTC offset e.g. Brisbane is UTC+10
My own set of BigFont libraries:
Test using Arduino Uno 16×2 LCD keypad shield.
Test using ESP8266 16×2 LCD over I2C and NTP for date/time.
Using my own font libraries: BigFont01_I2C, BigFont02_I2C, etc.
BME280 and I2C 16×2 character display combined: