I’m always on the lookout for cheap electronics on eBay and AliExpress. Following on from my previous tutorial on HD44780 screens, this time, I found a small OLED display.
I bought one of these from eBay for less than £5 plus postage. It is a 0.96″, 128×64 pixel OLED display. These things are really tiny, but useful if you’re after something to display status information. They run from the I2C bus, this one using address 0x3C. This means that all the other addresses are available for you to use to get I2C sensor readings from or to drive other displays. You can even change the address on these displays to allow you to use multiple of the same device.
I did a quick Google to find out how to use it with the Raspberry Pi. I used some of the instructions on this page but found them to be out of date, so I ended up doing things slightly differently.
First of all, make sure your Pi has some essential packages. Most are pre-installed, but you’ll get updates this way:
sudo apt-get install build-essential python-dev python-pip python-imaging python-smbus git
Then, grab the Adafruit library from GitHub:
git clone https://github.com/adafruit/Adafruit_Python_SSD1306
Install the library for python3:
cd Adafruit_Python_SSD1306 sudo python3 setup.py install
Now take a look at the examples:
cd examples python3 animate.py
In the examples, I changed the “disp =” statement to use the line with a 128×64 display running on I2C.
The example scripts provided by Adafruit are:
- Animated text rolling across the screen.
- Representation of some buttons (which is weird because it’s not a touch screen!).
- A PPM image translated onto the screen.
- Some geometric shapes.
- Some stats from the Pi – the IP address, disk & memory usage and CPU load.
You can see how these scripts work in the video below. Pardon the shaky cam work, I’ve lost my little tripod!
All the scripts are pretty easy to understand and modify.
I’ve seen these used to display the time, Pi information such as that in the example screen and even as a status display for different robot modes, so they are really versatile.
Addendum: Also worth a look is this other Python library called luma-oled. Thanks to Brian Welsby for that!