Skip to content

I2C-Controlled OLED Example

This example demonstrates how to interface a small 128x64 OLED module with the KNEO Pi using the I2C protocol.

The OLED module used in this example is a 128x64 display driven by the SSD1306 controller, which is commonly used in many low-resolution I2C-based displays.

Important

  • The chosen module is for demonstration purposes only; we do not promote or provide purchasing information for specific hardware.
  • The example provided below is specifically tailored for this controller and may not work with modules using different controllers.

The example code is sourced from the repository: ssd1306_linux .
This implementation utilizes Linux i2c-dev interface and requires no modification to work on the KNEO Pi.

Hardware Connection

Connect the I2C OLED module to the KNEO Pi as follows:

Module Pin KNEO Pi Pin Function
GND GND / pin-9 Ground
VCC 3.3V / pin-1 Power Supply
SCK I2C_0 SCL / pin-5 I2C Clock
SDA I2C_0 SDA / pin-3 I2C Data

Info

This example uses the i2c-0 bus for communication

Running the Example

Clone the repository and navigate to the project directory:

git clone https://github.com/kneron/kneopi-examples.git
cd kneopi-examples
cd peripherals/C/i2c_oled

Build the example using the provided Makefile:

make

Run the example with the following command:

  • init the OLED once
    • resolution 128x64
      ./ssd1306_bin -I 128x64
      
  • clear display

    • clear 1st line
      ./ssd1306_bin -c0
      
    • clear 4th line
      ./ssd1306_bin -c3
      
    • clear whole screen
      ./ssd1306_bin -c
      
  • display on/off

    • turn off display
      ./ssd1306_bin -d 0
      
    • turn on display
      ./ssd1306_bin -d 1
      
  • inverting display

    • normal OLED (0 is off, 1 is on)
      ./ssd1306_bin -i 0
      
    • invert OLED (0 is on, 1 is off)
      ./ssd1306_bin -i 1
      
  • print words

    • write line "Hello World"
      ./ssd1306_bin -l "Hello World"
      
    • write message "alpha\nbravo\ncharlie\ndelta" (please place \n for next line)
      ./ssd1306_bin -m "alpha\nbravo\ncharlie\ndelta"
      
  • I2C device address (default is /dev/i2c-0)

    • using /dev/i2c-0
      ./ssd1306_bin -n 0
      
  • rotate display

    • normal orientation
      ./ssd1306_bin -r 0
      
    • turn 180 orientation
      ./ssd1306_bin -r 180
      
  • set cursor location

    • set XY cursor 8,1(x is column, 8 columns skipping, y is row, 2nd line)
      ./ssd1306_bin -x 8 -y 1
      

Additional Information

For detailed usage and further customization, please refer to the official guide at ssd1306_linux github repository .