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:
Run the example with the following command:
- init the OLED once
- resolution 128x64
-
clear display
- clear 1st line
- clear 4th line
- clear whole screen
-
display on/off
- turn off display
- turn on display
-
inverting display
- normal OLED (0 is off, 1 is on)
- invert OLED (0 is on, 1 is off)
-
print words
- write line "Hello World"
- write message "alpha\nbravo\ncharlie\ndelta" (please place \n for next line)
-
I2C device address (default is /dev/i2c-0)
- using /dev/i2c-0
-
rotate display
- normal orientation
- turn 180 orientation
-
set cursor location
- set XY cursor 8,1(x is column, 8 columns skipping, y is row, 2nd line)
Additional Information
For detailed usage and further customization, please refer to the official guide at ssd1306_linux github repository .