Qwiic Kit for Raspberry Pi Hookup Guide
This Tutorial is Retired!
View the updated tutorial: Qwiic Kit for Raspberry Pi V2 Hookup Guide
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.
language:python
oled = qwiic.QwiicMicroOLED()
oled.begin()
Clearing the Screen
Next, we are going to clear the screen. This actually will clear the entire buffer.
language:python
oled.clear(oled.ALL)
Then we can display the cleared screen. This will display what is in the buffer which at this point is nothing.
language:python
oled.display()
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
language:python
oled.set_font_type(1)
Setting Cursor Position
When we are ready to actually print to the screen we'll set the cursor to the top left.
language:python
oled.set_cursor(0,0)
Printing
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.
language:python
oled.print("Tmp:")
oled.print(int(tempf))
If we want, we can move the cursor to a different line, print more data, etc.
Displaying
Finally, we will want to display all of this to the screen.
language:python
oled.display()
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.