Drawing Graphics with an OLED Display
Okay, but first:
What the hell is “I2C”?
Section titled “What the hell is “I2C”?”I2C (pronounced “I-squared-C”) stands for Inter-Integrated Circuit. It’s basically a communication protocol that allows multiple electronic parts to talk to your tinyCore using just two wires!
Instead of needing a separate pin for every single button or light, I2C uses a “bus” system.
- SDA (Serial Data): The wire that actually sends the messages back and forth.
- SCL (Serial Clock): The wire that keeps the timing perfect like a metronome.
Because I2C allows multiple devices on the same two wires, each device has its own unique “address” (like a digital house number) so the tinyCore knows exactly who it’s talking to.
For this tutorial, we are using the classic 0.96 inch OLED Display. These are incredibly popular, super bright, and use I2C to receive drawing commands!
1. Wiring the Display
Section titled “1. Wiring the Display”Because I2C is a shared bus, we can actually wire this up to the exact same pins we used for the IMU!
- GND → GND on tinyCore
- VCC → 3.3V on tinyCore
- SCL → SCL on tinyCore
- SDA → SDA on tinyCore
Note: Double-check your specific display! Some manufacturers swap the order of the GND and VCC pins at the top.
Alternatively…
Section titled “Alternatively…”If you are using the OLED Display included with the tinyKit, you can use the QWIIC cable to connect it!
2. Install the Libraries
Section titled “2. Install the Libraries”To draw on this screen without having to manually calculate individual pixel memory addresses, we are going to use two helpful libraries from Adafruit.
- Open the Library Manager icon in your Arduino IDE.
- Search for “Adafruit SSD1306” and click
INSTALL. (If it asks to install missing dependencies like Adafruit BusIO, say yes!) - Next, search for “Adafruit GFX” and install that as well. This library gives us the math needed to draw circles, lines, and text.
3. Hello World (Text on Screen!)
Section titled “3. Hello World (Text on Screen!)”Let’s test our display by printing some simple text.
4. Interactive Physics: The IMU Digital Hourglass
Section titled “4. Interactive Physics: The IMU Digital Hourglass”Displaying static text is great, but your tinyCore has a built-in 6DOF IMU! Let’s combine the two and make an interactive digital hourglass.
When you tilt your tinyCore left, right, or upside down, the “sand” (pixels) on the screen will fall with gravity using the accelerometer data!
You’ll need the Adafruit_LSM6DSOX library installed (which you should already have from the IMU tutorial).
5. Troubleshooting
Section titled “5. Troubleshooting”My screen is completely black!
- Check your wiring. VCC and GND are easy to swap by accident.
- Check your I2C address. Most are
0x3C, but some cheap clones use0x3D. Try changing#define SCREEN_ADDRESSin the code. - Run the I2C Scanner code from the IMU tutorial to see if the tinyCore even detects the screen!
The code won’t compile!
- Ensure you have both the
Adafruit GFXandAdafruit SSD1306libraries installed. The screen library relies on the GFX library to do the math.
What’s Next?
Section titled “What’s Next?”Now that you have a visual output, you can build proper user interfaces!
Ready to try:
- Building a menu system with Reading a Button Press?
- Adding audio feedback to your menus with Controlling a Buzzer?