Introduction: Raspberry Pi Vital Monitor Via OLED
Hi guys,
I was recently working on my linux machine and it started going slow. First thing that came to my mind was 'looks like we are running out of RAM'. I opened up cpu and RAM monitor to confirm my hypothesis. That's when thought of making a vital monitor for headless raspberry pi hit me and an idea was born.
Lets get started.
Step 1: A Complete Video
This video explains all steps in 5 mins. Take a look.
Step 2: Required Items
Following is the list of required items-
- Raspberry pi + wifi dongle or Raspberry pi 3,
- Raspberry pi power supply,
- 16 GB microSD card,
- microSD card reader,
- 126x64 SPI OLED display and
- Female to female jumper wires.
You will also need a laptop or a PC for setting up raspberry pi and accessing it.
Step 3: Flash Raspbian to Your MicroSD Card.
Description- First thing we need to do is flash raspbian on a microSD card. So head to www.raspberrypi.org and download latest version of raspbian and extract it from zip file. Now insert an empty microSD card in microSD card reader. Connect microSD card reader to your laptop or PC. Bring up etcher application and burn extracted raspbian image on your microSD card.
Step 4: Configure Raspbian for Wifi and Ssh
Description- To configure wifi, open up a terminal on linux machine and become root user, cd into raspbian's root directory. If you are on windows machine, open up raspbian's root directory as administrator. Modify file /etc/network/interfaces as shown in first image i.e. change lines for wlan0 to
auto wlan0iface wlan0 inet dhcp
This will allow your router to assign a random IP address to your raspberry pi but we haven't specified ssid and password for your router right, /etc/wpa_supplicant/wpa_supplicant.conf file lets us do exactly that. Look at second image.
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid='-----' psk="--------" key_mgmt=WPA-PSK }
To enable ssh which we will use to securely access headless raspberry pi. Create an empty file called 'ssh' in boot directory of raspbian.
Finally, unmount microSD card from your machine and take it out from card reader to put it in Raspberry pi.
Step 5: Connect OLED to Raspberry Pi
Description- Connect SPI OLED display to your raspberry pi according to attached image.
Step 6: Finding IP Address of Raspberry Pi
Description- Once OLED is connected to raspberry pi, power on raspberry pi. As we have enabled dhcp, router will assign a random IP address depending on availability to raspberry pi. To securely access headless raspberry pi we will use ssh, for which we will need IP address of raspberry pi. To find IP address of raspberry pi use application like angry IP scanner which scans your network for active devices. Attached image shows angry IP scanner showing IP address of raspberry pi.
Step 7: Enable SPI Interface on Your Raspberry Pi
Description- Once you have IP address of raspberry pi, ssh into your raspberry pi. First thing to do is enable SPI interface.
Steps-
- Once you are in Raspberry pi using 'ssh pi@---.---.---.---', type 'sudo raspi-config' to get a menu,
- Select 'Interfacing Options',
- Select 'SPI',
- It will ask 'Would you like SPI interface to be enabled' select 'yes',
- A confirmation image will appear,
- Exit the menu and
- Reboot your raspberry pi using 'sudo reboot'.
Step 8: Getting Git Repos
Description- Once rebooted, ssh into rasp pi one more time. Now we need to download two git repos, first is from raspberry pi guy which does handling of SPI interface and second is mine which enables the OLED vital monitor.
steps-
- Clone raspberry pi guys repo using 'git clone https://github.com/the-raspberry-pi-guy/OLED ',
- Once done you will see a directory called OLED in your home directory, go inside OLED directory using 'cd',
- You will find a file called OLEDinstall.sh, run it using 'sh OLEDinstall.sh',
- Now clone my git repo using 'git clone https://github.com/jayraj4021/Raspberry-pi-vital-...',
- Once done you will find a directory called Raspberry-pi-vital-monitor-via-OLED, cd into it to find a file called OLEDMem_cpu.py that's our master file.
- Copy OLEDMem_cpu.py file to python_examples directory in OLED directory.
- Run this python script using 'sudo python /home/pi/OLED/python-examples/OLEDMem_cpu.py --sleep_time 1',
- Script will error out saying 'mpstat: not found', to resolve it install package names sysstat using 'sudo apt-get install sysstat'
- On running OLEDMem_cpu.py one more time you should see a beautiful OLED screen with your raspberry pi's stats on it.
I have also included an rc.local file in git repo, you can replace it with file of same name in /etc directory to turn this monitor on every time raspberry pi boots automatically.
That's it folks, I hope you liked it. Let me know your experiance. BYE.