A minimal Rust application for testing out the Adafruit 1.3” OLED Bonnet (SSD1306) with a Raspberry Pi (5).
This project demonstrates:
- Using linux-embedded-hal and rppal for
I2C
andGPIO
access. - Drawing on the OLED display with embedded-graphics and ssd1306.
- Handling button/joystick inputs.
- Exiting
SIGINT
cleanly via ctrlc.
- Plug the bonnet onto your Raspberry Pi's GPIO header.
- Confirm that the bonnet's SDA/SCL pins map to the PI's
I2C1
. - Typically, this is on pins 3 (SDA) and 5 (SCL).
- Run
sudo raspi-config
, go toInterface > Options > I2C
enable it, then reboot. - Confirm the device with:
$ sudo i2cdetect -y 1
# This should output something like:
# 0 1 2 3 4 5 6 7 8 9 a b c d e f
# 00: -- -- -- -- -- -- -- --
# 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
# 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 70: -- -- -- -- -- -- -- --
Important
The demo uses 0x3c
per default. You might need to adjust the code, if this differs.
- This bonnet has 7 GPIO-based inputs (2 buttons, 4-direction joystick, and pressing the joystick).
- In the demo, we assume these pins:
Button A -> GPIO 5
Button B -> GPIO 6
Joystick Left -> GPIO 27
Joystick Right -> GPIO 23
Joystick Up -> GPIO 17
Joystick Down -> GPIO 22
Joystick Press -> GPIO 4 # Not used in code
Note
Check Adafruit's documentation or pinout if your hardware differs for your setup.
- Rust
- Cargo
- I2C Tools (i2c-tools, libi2c-dev on Debian-based distros)
Make sure you can build Rust projects on your Pi or cross-compile from another machine. You can find the installation documentation for Rust and Cargo here.
- Clone this repository:
$ git clone https://github.com/adrior11/bonnet-demo-rs.git
- Build and Run:
$ cargo run
- Joystick: Move the circle around (left, right, up, down).
- Button A: Redraw the circle if needed.
- Button B: Clear the display.
- Press
Ctrl+C
in the terminal to trigger a cleanup routine that clears the display and shuts down the application.
.
├── ...
├── Cargo.toml # Project metadata & dependencies
└── src
├── main.rs # Main logic: sets up display, pins, main loop
└── position.rs # Position structure with movement logic
This project is available under the MIT License.