by Floris Wouterlood – The Netherlands – January 24, 2021
The small footprint of the Wemos D1 mini ESP8266 microcontroller board and its on-board WiFi makes this tiny piece of electronics attractive for making small units that communicate via the internet with local or cloud-based servers. A fancy display is not necessary when the emphasis of a unit is on the IOT aspects because it serves in the configuration mainly as a secondary component. A display here is useful only for checking every now and then whether the unit runs as it is supposed to run and, preceding that, for testing purposes at the construction stage.
figure 1. Wiring diagram of the tiny weather station: Si7021 sensor, Wemos D1 mini board and Nokia 5510 LCD.
Here we discuss the design of a small environmental parameter reporting unit, say ‘tiny weather station’ that measures temperature and relative humidity. The unit is capable of sending data to a destination on the internet. The unit consists of a Si7021 breakout board, an ESP8266 Wemos D1 mini microcontroller and a Nokia 5510 LCD for the display of data. A 16×2 character LCD would do the data representation equally well as a Nokia but it is the graphical features of the Nokia that makes it more attractive than a numerical-only LCD. An OLED can be used as well but these displays tend to burn in during prolonged continuous operation. There are very good libraries available for the Nokia (Adafruit_PCD8544.h and Adafruit_GFX.h) that support the graphical and alphanumerical functionality. Like all LCDs the Nokia is very modest in its energy consumption and it has a long life expectancy.
Si7021 breakout board
The Si7021 breakout board (figure 1) features a low cost sensor that measures the ambient temperature and relative humidity with reasonable accuracy. In a previous post I have connected this device to an Arduino Nano.* It is 3.3V and 5V compliant and it communicates with the Arduino through the I2C protocol. This means that apart from power and GND there are two pins for communication: Clock (SCL) and Data (SDA). The designated I2C pins on an ESP8266 microcontroller board are pins D1 (SCL) and D2 (SDA). A pull-up resistor with a value of 4.7 kΩ is necessary between SCL and power and between SDA and power. Power comes from the 3V3 pin.
Wemos D1 mini
The D1 mini (figure 1) is a 3.3V,16-pin ESP8266 microcontroller board with dimensions 34×34 mm belonging to the big family of boards that feature a 32-bit L106 microprocessor core running at 80 MHz. Memory is 4 MB flash and 64 kB SDRAM. Architecture is modern and there is standard serial communication, I2C, SPI, a TCP/IP stack and WiFi. A particular feature that make ESP8266 microcontroller boards extra attractive is that they can be programmed in familiar C++ Arduino style instructions through the Arduino IDE.
Nokia 5510 LCD
The Nokia 5510 display (figure 1) features a 84*48 pixel liquid crystal monochrome screen with individually programmable pixels. It is a dedicated 3.3V device that has been implemented in numerous Arduino projects. The (switchable, pulse width manageable) background led illumination is controlled via a separate pin. The communication interface is SPI. Because the hardware SPI pins on the Wemos (D1, D2) are already reserved for the sensor board we use software SPI in this project.
1x Si7021 mini breakout board (also labeled SHT21-HTU21), 1x Wemos D1 mini microcontroller board, 1x Nokia 5510 LCD, 1x capacitative switch mini breakout board, 2x resistor 4.7 kΩ, 1x resistor 220 Ω, led, 2x prototyping breadboard, jump wires.
Figure 1 shows the pin-to-pin wiring of a Wemos D1 mini with its peripherals. The Si7021 is a dedicated I2C device that requires pins D1 (SCL) and D2 (SDA) of the Wemos D1 mini. A 4.7 k Ω resistor is obligatory between the SCL pin and 3.3V and between the SDA pin and 3.3V to keep these pins HIGH. In addition to the two signal wires there is a power supply pin to wire with 3.3V, and GND.
The Nokia display uses the SPI serial protocol that needs five wires to function: CLK, DIN (equal to MOSI), DC, CE and RST. As explained above the wiring is soft-SPI inspired; selected here are ‘standard’ pins D4 (CLK), D3 (DIN), D6 (DC), D7 (CE) and D0 (RST). Pin D8 is wired to a led. Note that a 220 Ω resistor is included in the wiring to the led. This is done to reduce the led’s light intensity – voltage reduction is not necessary. The back light power supply pin of the Nokia (BL) is wired via a capacitative touch button switch to the 3.3V pin of the Wemos D1. Do not forget to properly ground all electronic components.
Summary of the Nokia 5510 wiring: (see figure 1)
The standard Arduino IDE needs to be extended to support ESP8266 boards. This can be accomplished in the Arduino IDE by opening the menu File, Preferences and to add in the Preferences dialog screen in the Additional Boards manager URLs dialog window the following text: https://arduino.esp8266.com/stable/package_esp8266com_index.json
Next to ESP8266 board support the following libraries are necessary to compile the Arduino-style instructions for the Si7021 sensor and the Nokia 5510 LCD:
because we are using soft-SPI to control the Nokia display we need to define SPI pins
#define CLK D4
#define DIN D3
#define DC D6
#define CE D7
#define RST D0
and introduce the selected pins in the constructor:
Adafruit_PCD8544 display = Adafruit_PCD8544 (CLK, DIN, DC, CE, RST);
Now we can create a sketch with the following structure:
1. Initialize the Si7021 and the Nokia 5510
2. Read signal from the Si7021
3. Calculate from these data the ambient temperature and relative humidity
4. Display the temperature and relative humidity on screen, both graphically and numerically
5. (additional, optional): Convert temperature and relative humidity values to strings and send them to an Internet destination
The graphical display of data is accomplished via two 42 pixels wide, 42 pixels high ‘analogous’ gauges visible in the wiring diagram of figure 1. These gauges are built up in the Setup() part of the sketch through a call to a function named ‘draw_markers_split_window ()’. In the Loop () part of the sketch only the positions of the needles are redrawn, also by calling a function named ‘needle()’. Data acquisition itself is done in the Loop() section.
On the LCD, in each gauge the needle’s fixed pivot end is determined by coordinates ‘pivot_x’ and ‘pivot_y’. The free end is determined by coordinates ‘needle_x’ and ‘needle_y’. The calculation of the latter coordinates involves a swing angle of the needle with the horizontal. The fixed and free ends of a needle are connected via a display.drawLine instruction that includes at the end a ‘color’ parameter. This color is either 1 (pixel on = black) or 0 (pixel off = background).
Control of needle position is as follows. The two coordinates involved in the movement of any needle are needle_x’ and ‘needle_y’ (because the pivot has fixed coordinates. These needle coordinates are calculated via a formula that for the x-coordinate includes a cosine and for the y-coordinate a sine:
needle_x = (pivot_x + (needle_length)*cos(angle_needle));
needle_y = (pivot_y + (needle_length)*sin(angle_needle));
wherein angle_needle is calculated via:
angle_needle = ((360*0.01745331)-(temp_01*0.01745331));
as 1 degree = 0.01745331 radians, and where temp_01 is the recorded temperature
The (360* 0.01745331) part is introduced here because in the current design the needle movement is counterclockwise. The angle must be expressed in radians because the Arduino compiler only accepts radians.
Once a new needle position is calculated we need to erase the needle position calculated in the previous iteration of Loop (). This ‘erasing’ is done in each iteration through the following series of instructions:
1. Copy the values of the needle tip coordinates (‘needle_x’, ‘needle_y’) into variables ‘needle_x_old’ and ‘needle_y_old’,
2. Then calculate the values of coordinates ‘needle_x’ and ‘needle_y for the updated needle tip position,
3. Draw the ‘old’ needle using the values kept in ‘needle_x_old’ and ‘needle_y_old’ but use here color parameter ‘0’,
4. Draw the updated needle using ‘needle_x’ and ‘needle_y’ and, of course, color 1,
5. Redraw the pivot circle to prevent the pivot circle to become dented when the needle ‘moves’.
Of course there are two needles which doubles the number of variables (see sketch).
The body of the sketch is simple and follows the structure outlined above.
Figure 2 shows a working prototype of the tiny weather station. The Si7021 sensor provides temperature and humidity signal to pins D1 (SCL) and D2 (SCK) of the Wemos D1 mini, while pin D8 of the Wemos controls a led. The other pins are needed for communication with the Nokia 5510 display. The red external led functions as an activity indicator and can be regarded as a kind of luxury.
Backlight of the Nokia display is provided here by a capacitative touch switch (visible in figure 2) which is not connected to the microcontroller. This touch switch is a three-pin mini breakout board: pins marked Vcc, GND and I/O. The state of the I/O pin changes from LOW to HIGH when the switch is touched. The HIGH signal is directly conveyed to the BL pin of the display. When the switch is touched its I/O pin delivers a modest amount of current because the backlight leds burn less intense that when the BL wire is directly supplied from the 3.3 V rail or receives power via a push button. The capacitative touch switch here is ‘elegant luxury’, nice for IOT solutions.
Figure 2. Working prototype of the ‘tiny weather station’. The led and the touch switch are intentionally lighted to provide a nice picture.
Note: the libraries “SPI.h”, “Wire.h”, Adafruit_PCD8544.h” and “Adafruit_GFX.h” are required to compile this sketch. These libraries can be installed via Library manager in the Arduino IDE.
The downloadable zip file contains one sketch:
With the configuration explained in this paper the result will be display on the screen of the Nokia LCD similar to that in figure 2.
* Arduino sensors and devices (6): Bare Si7021 temperature and relative humidity sensor
Thesolaruniverse.wordpress.com – February 22, 2018