Professional Documents
Culture Documents
In this lesson you'll learn how to display the demo code of the [U8g2 library] (https://github.com/olikraus/u8g2) on your
screen.
Course material
At the bottom of this page you'll find the course material button. This button allows you to download the code, circuit
diagram and other files relevant to this Arduino tutorial.
The ST7920 is a so-called LCD which stands for Liquid Crystal Display. This screen is made up of segments that can be
turned on or off. These segments are placed as an '8' in some screens like a digital clock, in others as pixels.
With LCD it looks like the boxes can become black. Technically this is not true. The light is transmitted differently making it
appear black. More details on Wikipedia
Type LCD
Format 128x64 pixels
Screen diagonal 2.9 inch
Dimensions 93x70mm
Power supply 2.7 to 5.5V
Color blue/white or green/black
U8g2 library
The U8g2 library is specially made to easily control monochrome displays in an universal way. U8g2 allows you to draw
graphic elements such as lines, rectangles, circles on the screen. Text is also no problem.
An overview of all available functions can be found on the U8g2 reference page. Currently U8g2 supports over 200
different displays. The big advantage is that you don't have to find out how to control each individual display.
If the pin overlay does not not fit exactly, check your printer settings to see if the magnification is set to 100%.
The circuit
Step 1 - breadboard
We start by supplying the breadboard with 5V on the + rail (red) and GND on the - rail (blue). For this we connect
the '5V' on the :KnSgtg:Arduino:: to the breadboard. We do the same for the GND .
Circuit step 1
Circuit step 2
Circuit step 3
If we make the PSB pin high, the display expects parallel data, with LOW serial. In our case we have to make the PSB pin
LOW by connecting it to the - rail .
Circuit step 4
Step 5 - SPI
The last step is to connect the data lines for the SPI communication. SPI uses three different lines:
We will use 'Pin 13' on the Arduino (orange line) as serial clock 'SCK'. On the display it is labeled as pin E .
For the Master In Slave Out MOSI of the SPI protocol we connect Arduino pin 11 (blue line) to the RW pin (read / write) on
the display.
en.benewake.com OPEN
The last step is to connect the CS (chip select) wire. On the display it is labeled RS which stands for Register Select and it
will be connected to pin 10 on the Arduino.
Circuit step 5
Arduino Code
As indicated earlier, we use the U8g2 library. We will first install this via:
Search for U8g2 and press install for the U8g2 by Oliver library
If you scroll down a bit you will see a lot of definitions of displays that resemble:
en.benewake.com OPEN
3 //U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);
For our display this line is the one we're going to use
1 U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);
Remove the // in front so it isn't commented. You can see exactly the Arduino pins to which we previously connected the
data lines.
If you are not sure which port to use, try them all until you can successfully upload your code.
The top left shows a round button with a checkmark. By pressing this button you tell the IDE to verify your code for
possible errors. The IDE only checks if it can read your code. It does not check if you have written correct code for what
you are trying to program.
en.benewake.com OPEN
If everything works the IDE shows the Compiling completed message. You can now upload your code by pressing the
round button with the arrow to the right. The uploading is complete when the Avrdude done. Thank you. messages
appears. Your program will immediately start after uploading.
Challenge 🚀
Another Arduino tutorial finished! Here is a challenge:
🎓 Look at the functions in the code and experiment by tweaking things. For example, see if you can give the shapes other
sizes.
Good luck!
Course material
Code on Github
Subscribe
en.benewake.com OPEN
My name is Bas van Dijk, entrepreneur, software developer and maker. With Bas on Tech I
share video tutorials with a wide
variety of tech subjects i.e. Arduino and 3D printing.
Years ago, I bought my first Arduino with one goal: show text on an LCD as soon as
possible. It took me many Google searches
and digging through various resources, but I finally
managed to make it work. I was over the moon by something as simple as an
LCD with some text.
With Bas on Tech I want to share my knowledge so others can experience this happiness as
well. I've chosen to make short, yet
powerful YouTube videos with a the same structure and one
subject per video. Each video is accompanied by the source code
and a shopping list.
Copyright © 2018-2022 Bas on Tech / arduino-tutorials.net is part of Bas on Tech