Testing OLED display

This section of the tutorial is optional and designed for those who want to test the OLED display connected to their microcontroller. While you don’t need an OLED for your weather station, it’s helpful and convenient for showing stuff like temperature and humidity readings. If you’ve got one, this test will help you make sure it’s working properly.

OLED display library

The first step is to download the library for the display, and save it to a location on your computer that you are familiar with. To upload the library onto the microcontroller, open the terminal and run ampy --port COMX --baud 115200 put x:\location\ssd1306.py, where “X” should be switched with the port number, and “x:\location\” with the actual location of the ssd1306.py file.

Alert

Before uploading the library via ampy in the terminal, ensure to close the session in MobaXTerm, as only one program can use the connection to the microcontroller at a time.
Oled library

To check if the library is successfully uploaded, connect to the microcontroller via MobaXTerm. In the command prompt, run import os, than os.listdir(). You should see “['boot.py', 'ssd1306.py']˙ ” in the next line.

Oled library check

Showing text on display

1from machine import Pin, SoftI2C 
2import ssd1306 
3i2c = SoftI2C(scl=Pin(15), sda=Pin(4))
4rst = Pin(16, Pin.OUT) 
5rst.value(1) 
6oled = ssd1306.SSD1306_I2C(128, 64, i2c) 
7oled.fill(0) 
8oled.text('Hello World', 0, 0)
9oled.show()

Tip

Notice in the third line that the SCL and SDA pins of my microcontroller are 15 and 4. If you have a different microcontroller, it’s possible that the pins are not the same. Check your microcontroller’s documentation to see its SCL and SDA pins.
Testing display

Take a look at your microcontroller’s display. You should see “Hello World” displayed on it.