Lab 2 - I2C Serial Display Driver
Creating a Device Driver Library for a Small OLED Display
Summary
Create a Reusable Code Library to Interface a Small Display with the RP2040 / Pi-Pico
I. Construct a test circuit on a breadboard. See the wiring suggestion below.
II. Download the partially complete code libraries below.
Create a new code project folder, add the libraries to your src folder and configure the cmake list as shown.
Test the wiring and code base by generating random noise frames on the screen with the given starting main.c
code.
III. Experiment with the character drawing functions. When you are comfortable add a function to draw strings as prototyped below.
Make a test program that calls your new string draw function.
IV. Add three geometry drawing functions for rectangle outlines, filled rectangles and lines.
Make a test program that calls all of your new geometry drawing functions.
Equipment and Supplies
- Rasperry Pi Pico with Headers pinout diagram
- SSD1306 128x96 OLED Display Module SSD1306 Display Driver Datasheet
- 20kΩ Resistor [x2]
- USB Micro Cable
- Breadboard
- Cables and 22ga wire as needed
Wiring
- This is a low power system, you may power everything from the USB cable.
- Use the V3.3 pin to supply your breadboard power rail from the Pi Pico.
(Avoid 3.3 Enable right near Gnd! Pulling power from 3.3 Enable will destroy the voltage regulator!)
- Connect SDA and SCL (both from the same I2C channel) to the corresponding pins on the display .
- Both SDA and SCL lines should be connected to the 3.3V line with separate 20kΩ pull up resistors.
(Note that 22kΩ is used in the reference image below.)
Part II Code Files
CMakeLists.txt
Make the following changes to include the extra source files and library links.
...
# List all source files
add_executable(${program_name}
src/main.c
src/display-ssd1306.c
src/font_8x8.c
)
...
# Add pico_stdlib library which aggregates commonly used features
# added hardware_i2c for serial library
target_link_libraries(${program_name} pico_stdlib hardware_i2c)
...
main.c
A simple demonstration of random 'static' noise at 100 frames per second.
#include "display-ssd1306.h"
int main() {
display_setup_pico_pins();
display_initialize_ssd1306();
display_send_clear_frame();
//random white noise at ~100 frames per second
while (true) {
display_send_random_frame();
sleep_ms(10);
}
}