OLED Display

From Waveshare Wiki
Jump to: navigation, search

JetBot User Guide

I2C Interface

  • As Jetson Nano onboards 2-ch I2C interface, OLED on the JetBot is controlled by I2C interface. We can check the I2C device by i2ctool. The last parameter of the command is 1, which indicates that the device being viewed is i2c bus 1. If the parameter is 0, the device we checked is bus0.
  • Ubuntu install i2c-tools.
sudo apt install i2c-tools #Install I2C tools
sudo i2cdetect -y -r l #Scan the currently connected I2C device address
#Among them, the last parameter 1 means that the device of i2c bus 1 is viewed; if the parameter is 0, the device of bus 0 is viewed.

OLED DISPLAY01.png

  • Where 0x3C is the i2C device address of the OLED. Since the initial project of JetBot used a 0.91inch OLED screen of SSD1306, the OLED function library provided is Adafruit_SSD1306. You can find the control program of the screen in the file jetbot/jetbot/app/stats.py.

OLED Display

  • In order not to conflict with the original OLED, we can connect another 0.91 inch OLED to the I2C0 interface of the Jetson Nano for testing.
Vcc (OLED) -> 3V3 (Jetson)
GND (OLED) -> GND (Jetson)
SDA (OLED) -> I2C0_SDA (Jetson)
SDL (OLED) -> I2C0_SDL (Jetson)
  • After connecting, check the device mounted on i2c bus 0, you can see that a 0x3C device is recognized.

OLED DISPLAY02.png

  • As the controller is the same as the screen format, we can directly use Adafruit_SSD1306 function library to control OLED. So we can try to write a program to display the string on OLED.

OLED DISPLAY03.png

  • The main code is:

OLED DISPLAY04.png

  • At the beginning, import needs to use every function, for instance, time for controlling the sleeping time. PIL picture library and Adafruit__SSD1306.
  • Note that the cable we connect is I2C0 bus, so the i2c_bus parameter is 0.
OLED = Adafruit_SSD1306.SSD1306_128_32(rst = None, i2c_bus = 0, gpio = 1)   
  • Initialize the screen and clear it,
OLED.begin()
OLED.clear()
OLED.display()
  • Set font as default font.
font = ImageFont.load_default()  
  • Set the screen length and width, and create a canvas.
width = OLED.width
height = OLED.height
image = Image.new( "1", (width, height))
  • Set the refresh area and write a string, here is the drawing function of the PIL graphics library.
Draw = ImageDraw.Draw(image)
Draw.rectangle((0, 0, width, height), outline = 0, fill = 0)
Draw.text((0, 0), "OLED testing", font=font, fill=255)
  • Finally, refresh the memory to the screen.
OLED.image(image)
OLED.display()
  • Disclaimer: Adafruit_SS1306 is a driver for small size OLED screens provided by Adafruit Electronics. If you are interested, you can find out for yourself.