Qwiic Kit for Raspberry Pi Hookup Guide

Contributors: M-Short, bboyho
Favorited Favorite 1

Displaying Data to Your OLED

Next, we are going to look at the Qwiic micro OLED screen. The OLED module should have the same functions as our OLED Arduino library, but they might look a bit different. Let's start with a few basic commands...

Initializing the Micro OLED

We start by defining our OLED screen like we did with our sensors at the top of the code as well as run the initilization.

oled = qwiic.QwiicMicroOLED()

Clearing the Screen

Next, we are going to clear the screen. This actually will clear the entire buffer.


Then we can display the cleared screen. This will display what is in the buffer which at this point is nothing.


Font Size

Next, we can set the font type. The module comes with 4 different fonts. Unless you just need to display 2-3 digits, I recommend sticking with font 0 or font 1 as they will give you enough room to display a few lines of information. This is the end of the commands we'll use to setup the screen at the beginning of the code


Setting Cursor Position

When we are ready to actually print to the screen we'll set the cursor to the top left.



Then we can print some text. When we print the temperature, we don't want to print all the decimal places, partly because the limit of the screen size. The "int" command takes the tempf variable and gives us an integer and then we can print that.


If we want, we can move the cursor to a different line, print more data, etc.


Finally, we will want to display all of this to the screen.


Also, keep in mind you might want to add delays when using an OLED screen so that the information isn't flickering too fast. In this case, we already have a 1 second delay each time through the loop so we should be fine.

Because we already have the variables setup, we just need to pick a few we think would be useful and print them to our OLED display. We can get about 3 lines of code here comfortably, but you might want to change the font type and just display temperature so that you can view it from more than 12 inches away.