Source of this post -> HERE
aptitude install libopenjp2-7
aptitude install libtiff5
OLED display with Raspberry PI
Schematics:
The OLED should be connected as shown the in the below picture.
I2C Driver:
raspi-config Tool via Terminal
If you are using a terminal, you will need to:
- Run
sudo raspi-config
. - Use the down arrow to select
5 Interfacing Options
- Arrow down to
P4 SPI
. - Select
yes
when it asks you to enable SPI, - Also select
yes
if it asks about automatically loading the kernel module. - Use the right arrow to select the
button. - Select
yes
when it asks to reboot.
The system will reboot. When it comes back up, log in and enter the following command
>ls /dev/*spi*
The Pi should respond with
/dev/spidev0.0 /dev/spidev0.1
These represent SPI devices on chip enable pins 0 and 1, respectively. These pins are hardwired within the Pi. Ordinarily, this means the interface supports at most two peripherals, but there are cases where multiple devices can be daisy-chained, sharing a single chip enable signal.
Install i2c tools
root@raspberrypi:~# apt-get install i2c-tools
We have connected the OLED display to the /dev/i2c-1 of the Raspberry Pi.
In order to know what is the I2C Address of the device (Though I know it already, it might help some where). We need to scan the I2C bus and there is a command for that, its called i2cdetect. It can be used as follows.
In order to know what is the I2C Address of the device (Though I know it already, it might help some where). We need to scan the I2C bus and there is a command for that, its called i2cdetect. It can be used as follows.
Now we know that the I2C address of the device is 0x3C. But wait, we found that Address printed in the display as 0x78 and here it shows 0x3C, how is that possible? The answer is that the actual address of the device is 0X3C and you use address 0x78 or 0x79, for write or read. As an additional information the I2C bus allows devices to be plugged and unplugged without rebooting Pi. It’ll mess up some accesses, but I2C will recover.
OLED python Library
With the emergence of Pi board and the Linux distros along with it there are always more than one library available for each interface. Likewise for OLED display there are many libraries and many variants of libraries . For the OLED with SSD1306 I choose this library https://github.com/rm-hull/luma.oled .
This is library is already available as part of python repository or as they called cheese cake factory ;). Type the below command to install all the required dependencies for using the OLED display.
aptitude install libtiff5
aptitude install -y python-dev python-pip libfreetype6-dev libjpeg-dev build-essential
aptitude install python-dev python-pip libfreetype6-dev libjpeg-dev build-essential libopenjp2-7 libtiff5
pip install --upgrade luma.oled
pip3 install --upgrade luma.oled
Example code:
git clone https://github.com/codelectron/codelectron_projects cd codelectron_projects/Rpi/OLED python first.py
Now I will run the first python example first.py
Follow instructions on the original post ...
Nenhum comentário:
Postar um comentário