Usage of the SSD1306 OLED Display
First install the I2C driver:
You don’t need to install I2C, if you using the SD-card image from our website.
The new Raspbian distro already have the I2C driver installed but they are disabled by default. To enable it all you need to do is comment out a line by putting # in front. At the prompt type:
1 |
sudo nano /etc/modprobe.d/raspi-blacklist.conf |
then add a # on the 3rd line
# blacklist spi and i2c by default (many users don't need them)
#blacklist spi-bcm2708
#blacklist i2c-bcm2708
—Added a # to the start of the line
blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804
Press CTRL X then y to save and exit.
Next edit the modules file by:
1 |
sudo nano /etc/modules |
Add i2c-dev to a new line:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
i2c-dev
—Add this text
Press CTRL X then y to save and exit.
Now install the i2c-tools package by:
1 |
sudo apt-get install i2c-tools |
If you get a 404 error do an update first:
1 |
sudo apt-get update |
then run the install the i2c-tools again.
Note : The installation could take a few minutes to do, depend on how busy the server is.
Now add a new user to the i2c group:
1 |
sudo adduser pi i2c |
Reboot the machine by:
1 |
sudo shutdown -r now |
After the reboot test to see any device connected by:
1 |
sudo i2cdetect -y 0 |
If your board is the Rev 2 type this:
1 |
sudo i2cdetect -y 1 |
You should see something like this:
1 2 3 4 5 6 7 8 9 |
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: -- -- -- -- -- -- -- -- |
Now install the SSD1306 python library:
Before using the library you will need to make sure you have a few dependencies installed.
First install the Python Imaging Library and smbus library by executing:
1 |
sudo apt-get install python-imaging python-smbus |
Now to download and install the SSD1306 python library code and examples, execute the following commands:
1 |
sudo apt-get install git |
1 |
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git |
1 |
cd Adafruit_Python_SSD1306 |
1 |
sudo python setup.py install |
Inside the examples subdirectory you’ll find python scripts which demonstrate the usage of the library.
EduBoard OLED examples
To download our ready made examples, follow the next few steps.
Navigate to the Adafruit_Python_SSD1306 folder using the following command:
Only if you not already there.
1 |
cd Adafruit_Python_SSD1306 |
Download our examples using the command:
1 |
wget http://eduboard.co.uk/Download/EduBoard_examples.zip |
GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.
Extract the content using the following command: (unzip content)
1 |
unzip EduBoard_examples.zip |
Once extracted, remove the .ZIP file using the following command:
1 |
rm EduBoard_examples.zip |
Change the directory using the following command:
1 |
cd EduBoard_examples |
The terminal prompt should look like this:
pi@raspberrypi ~/Adafruit_Python_SSD1306/EduBoard_examples $
You can now run the IP script using the command:
(ip.py
has default fonts, will run straight away. The rest of the script has modified fonts, which will be detailed in the next tutorial)
1 |
sudo python ip.py |
To clear the display, run the reset.py
script using the following command:
1 |
sudo python reset.py |
(Library used: Adafruit)