Introduction: Efficient and Cheap: Display With STM32L4

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects.

Today, we’ll talk about three subjects that I absolutely adore: an LCD display that spends little energy, STM32 with Core Arduino, and Arduino Mega Pro Mini. This is an infallible trio for the Internet of Things. I’ll then introduce you to the HT1621 six-digit LCD display and create an example control with a code that works on both the Arduino Mega Pro Mini and the STM32 L432KC. A noteworthy detail is that the source code for the two microcontrollers is exactly the same. I won’t change the pinning either. It’s absolutely fantastic!

Step 1: Introduction

The HT1621 LCD display has a screen commonly used in multimeters, electronic scales, electronic clocks, thermometers, and electronic measuring devices.

• It has 6 digits with 7 segments

• It uses 3-wire SPI communication

• It has a backlight that’s suitable for dark environments

• Its operating voltage is 4.7 ~ 5.2V

• It consumes 4mA with a backlight

Note that it has more than SIX digits, THREE decimal points, and a battery meter with THREE bars.

Step 2: Library for Use

We will use the ANXZHU github user library, which is quite simple. It can be seen in the original version in the link below:

The library name is a tad strange, so I decided to rename it (files, classes, builders, etc.). Its original name is "A6seglcd”. I replaced this name with "lcdlib".

Step 3: Library

Add library "lcdlib".

Access the link and download the library.

Unzip the file and paste it into the libraries folder of the Arduino IDE.

C: / Program Files (x86) / Arduino / libraries

Step 4: Demonstration

Arduino mega assembly

Step 5: Demonstration

SMT32 assembly

Step 6: STM32 NUCLEO-L432KC

I want to highlight here that the STM32-L432KC doesn’t have a serial USB converter. Instead, it has a full USB, which uses STMicroelectronics ST-link protocol. Thus, it is quite sophisticated and enables very efficient debugging if you are using IR or Microvision. And being an Arduino Core (MBED, using Microsoft's native tool), it uses highly professional compilers. Do I need to say anything else?

Step 7: Arduino Mega 2560 PRO MINI

I also love this, as it is a "pure" and "real" Arduino. It's a Mega, with a lot of IOs. But it’s Mini, so it fits anywhere. I like IO everywhere. With this, I like to connect Led, SPI, i2c, etc. In this respect, this Mega is wonderful.

Step 8: Assembly

In our assembly, the row of the male pin is on the inner side, while the female pin is on the outermost side, facilitating our work and connection with a protoboard. We make the SPI connection, remembering that the Arduino Mega and this Arduino Nano clone have the same pinning, which is the STM32-L432KC.

Step 9: Program

We will make a very simple program, where we’ll write various symbols (letters, numbers, and points) on the display.

Remember that this program works on both the Arduino Mega Pro Mini and the STM32 L432KC.

Step 10: Libraries and Variables

We’ll then include the library responsible for communication and instantiate the control of the display. The "const char" function exposes an array table. It is through these vectors that you will make the reference of the character that prints on the display.

#include<lcdlib.h> //biblioteca para controle do display

lcdlib lcd; //instancia do controlador do display

/*0,   1,   2,   3,   4,   5,  6,   7,    8,   9,   A,   b,   C,   c,   d,   E,   F,   H,   h,   L,   n,   N,   P,   r,   t,   U,   -,    bat,  pf,'      ',*/
const char num[]={0x7D,0x60,0x3E,0x7A,0x63,0x5B,0x5F,0x70,0x7F,0x7B,0x77,0x4F,0x1D,0x0E,0x6E,0x1F,0x17,0x67,0x47,0x0D,0x46,0x75, 0x37, 0x06,0x0F,0x6D,0x02,0x80,0xFF, 0x00 };
/*indice num [i]  0    1    2    3    4    5   6    7     8    9   10   11   12   13   14   15   16   17   18   19   20   21    22   23   24   25   26   27   28     29  */

Step 11: Setup

To start Setup, we’ll define the pins, do the initial setup, and set the display cleaning. We determined that the display shows "Hello," and after a certain delay, the display message is cleared.

void setup()
{,3,4,5); //[ cs wr data led+] definição dos pinos lcd.conf(); //configuração inicial lcd.clr(); //limpa o display //escreve HELLO lcd.display(10, num[17]); lcd.display(8, num[15]); lcd.display(6, num[19]); lcd.display(4, num[19]); lcd.display(2, num[0]); //fim HELLO delay(1000); lcd.clr(); //limpa o display }

Step 12: Loop

Here, we create a function called "writeLoop,” which will write the word LOOP on the display, then write all the symbols of our arrray. We also have the "writeBattery" function, which prints the battery markers.

Finally, we have the "lcd.dispnum" command that writes the floating point value.

Step 13: Download the Files