DIY Raspberry Pi 4 minimal OLED stats Display
Today I will explain you how to add an OLED display to the Raspberry Pi 4 for a minimalistic appearance.
What you need is ?
- Raspberry Pi 4
- Micro SD Card
- OLED Display
- M3 hex nut 4 mm
- M3 spacer 10 mm
- Fan (30mm) 5v
- 3d printed Fan holder
- wire
- Soldering iron and good quality lead
3D Print the Fan holder
I have a ender 3 Pro I started to print on normal setup. Download the file here.
Wiring
wiring is straightforward, and it is simple.
Connection:
- OLED display to Pi 4
- SDA to SDA
- SCL to SCL
- VCC to 5V
- GND to GND
Next, we need to add wire and solder to the particular GPIO pin you can also use header pin instead I am using ribbon cable for aesthetic look.
Assembly:
Add the M3 metal spacer on each holder, also install the fan and make sure there is no wire tangle between the heatsink. Use some adhesive tape such 3M double sided tape and attach the OLED on the front of the fan.
Setting up the OLED Display
Once your pi is booted up, switch to headless mode by running through headless mode setup. Make sure you enable SSH in the settings.
Open the SSH connection on the terminal you can use windows power shell or putty. First enable I2C connection in the settings by typing.
sudo raspi-config
Go to Interface Options → I2C → Select Yes to enable the I2C.
And Reboot.
Now you need to install the dependence in this step many people face Module error because of not installing the dependence properly. Create a python3 virtual environment so that we wont be facing or popping up error.
To create a virtual python package copy and past the following code and then run the BBIO bash command.
cd Desktop
mkdir OLED && cd OLED #to create a folder
python3 -m venv oled #to create the environment
source oled/bin/activate #to activate the environment
Additionally, make sure the python-smbus and i2c-tools libraries are both installed. They should be by default, but it's worthwhile double-checking using the instructions below:
sudo pip3 install Adafruit_BBIO
sudo apt-get install python-smbus
sudo apt-get install i2c-tools
sudo python -m pip install --upgrade pip setuptools wheel
sudo pip install Adafruit-SSD1306
After that check the I2C address is properly mapped.
sudo i2cdetect -y 1
It should something similar like on the above figure. It say 3c which mapped on 0x3c address. If nothing appears here, check your display connections and make sure I2C communication is enabled on your Pi.
I have attached a example script which taken from Orginal Adafruit library from the Github. Download the script and past it on OLED folder. By Right clicking and select save as.
Now go to the OLED directory and run the code by call the script name
sudo python3 stats.py
Now you can see the OLED started up and showing information such as IP , CPU info ,etc.
Right now it can only run, after reboot it wont show the info. To enable permanently open bash.rc
sudo nano /etc/rc.local
Add the script directory path just before the exit 0 line, enter the following command:
sudo python3 /home/pi/Desktop/oled.py &
CTRL + O to write the command and CTRL + X to exit the terminal
Reboot the Pi 4 and now you can see the display light up on every reboot.
End of experiment
Result: Pass