Simple Text Menu for ST7920 Graphic LCD

 Posted by:   Posted on:    7 comments
Graphic LCD displays are a good addition for any project where you want to display some data. They look better than the old fashioned 7 segment displays and even alphanumeric LCDs, but more than that, you can use them to build user interfaces and menus. In a previous post, I wrote code for displaying text on a ST7920 128x64 graphic LCD. To save space, I wrote my code from scratch, instead of using a library that draws text in graphic mode and takes up a lot of memory on small microcontrollers. This time, I will continue to add features to the initial Arduino sketch in order to create a simple menu. This menu still uses text mode for displaying items. In this way, you are forced to display a maximum of four items at a time (the display has 4 rows of 16 characters). For highlighting menu items, we'll have to switch to graphics mode and draw rectangles on the screen. I will show you how the graphics RAM of ST7920 is organized and how you can set any pixel you want. The nice thing about ST7920 is that text pixels and graphics pixels are never at the same state. Therefore, if you have written text on a row and afterwards you fill the entire pixels on that row, the text pixels will be cleared ("RGB Controller" is written in text mode, then all pixels from that row are filled - see photo below).

Simple Text Menu for ST7920 Graphic LCD

C Code for Text Mode on ST7920 Graphic LCD

 Posted by:   Posted on:    16 comments
Graphic LCD displays are a good addition for any project where you want to display some data. They look better than the old fashioned 7 segment displays and even alphanumeric LCDs, but more than that, you can use them to build user interfaces and menus. If you interface a graphic LCD with an Arduino or compatible AVR development board, you probably heard about u8g2 library. This is a monochrome graphics display library which supports a lot of LCD controllers and screens of different sizes. It is very easy to use and comes with a lot of functions and display fonts. But this comes with a price. Text is drawn on LCD in graphics mode (this is how it renders different fonts). Combine this with the fact that in serial mode, some LCD controllers are write only. Therefore, the library must keep a part or the entire display data in RAM. This is not a bad thing, but unless you are developing some application where graphics is generated programmatically (something like a game), rather static user interfaces can be written to LCD from a ROM memory and don't need to be kept in RAM all time. And if you're creating a hardware project, you don't usually need to support different LCD controllers, as you'll not replace the LCD.

With this in mind and wanting to learn how to control a graphic LCD, I started to develop my own code. It turned out to be simpler than I thought. Simple code also means simple porting to other platforms. So I started this project with a ST7920 128x64 graphic LCD. I chose ST7920 because it supports serial protocol (SPI) and is 3.3V and 5V compatible. When I bought it I thought I could directly interface it with an OpenWRT router.

C Code for Text Mode on ST7920 Graphic LCD

Ultrasonic Tape Measure with HC-SR04 Sensor

 Posted by:   Posted on:    No comments
The wide availability and low price of microcontrollers makes it possible to update older analog designs to create reliable digital devices that are better and have more features. This time, using an ultrasonic sensor controlled by a microcontroller you can build an electronic distance calculator that can be used as an alternative to a tape measure for distances between 2 and 400 cm. I chose an ATmega development board (Arduino compatible) with an alphanumeric LCD to calculate and display data from the ultrasonic sensor.

The measuring device can be built entirely from ready made breakout boards and it can be powered from a 9V battery. With ATmega as its core, the device can have many features. The software supports current measurement hold and EEPROM storage. Stored measurement can be then displayed at a push of a button. The mode of operation is continuous. Measurements are performed each at 100 ms intervals and displayed on the LCD as long as the device is powered. You can pause the measurement by pressing the button assigned to HOLD function.

The device in the below photo can be built inside a case as long as the sensor's transmitter and receiver are passed through holes in the case. You will also need some holes for the display and buttons.

Ultrasonic Tape Measure with HC-SR04 Sensor