Raspberry Pi & SSD1306 OLED project
This project uses a Raspberry Pi B, a Wireless USB dongle and an SSD1306 OLED display to display the current weather and train times for selected locations. Optionally, add a rotary encoder and add your own menus!
- Raspberry Pi
- Compatible USB WiFi dongle
- SD Card (at least 8GB)
- Power supply
- SSD1306 OLED Display
- Jumper wires (7-10)
- (optional) Rotary encoder, soldering iron, wire, solder-sucker
- (temporarily) Screen + HDMI cable + keyboard (setup directly) OR ethernet cable + router + computer (setup via SSH)
Prepare your Pi if possible by using a fresh installation of the latest Raspbian. Burn this to your SD card and connect to your Pi using one of the following methods:
A. Connect up your ethernet cable between your Pi and router and log in to your Pi using SSH (Putty on Windows). If you can connect using avahi/Bonjour, the address you need is raspberrypi.local, otherwise find the Pi's IP address by logging in to your router.
NOTE: You will first need to place a blank file ssh on the /boot/ partition in order to enable SSH!
This is a new security measure in builds released since November 2016.
B. Connect keyboard and monitor to your Pi.
The default login username is pi and the password is raspberry. You can change this in the next step or by using the passwd command.
Run sudo raspi-config
to set up your Pi. Go through options 1-4 in turn, and it is considered safe to overclock a little (I used the Medium setting, but whatever works for you). In the Advanced options (7), enable SSH, SLI and I2C. Reboot and then update the pi: sudo apt-get update && sudo apt-get upgrade
Plug in your WiFi dongle and check it is recognised using lsusb
. Then check the interface appears with ifconfig
. You should have a wlan0 or similar but with no IP address. A good way to add a WiFi network is by using the interface wpa_cli
. This allows a number of commands to interact with your dongle. Search for WiFi networks using the commands scan
followed by (give it a few seconds) scan_results
. Add a new network: add_network
and note the number returned (the first time this will be 0, if not, change in the following commands). Use the commands set_network 0 ssid "YOUR_SSID"
and set_network 0 psk "YOUR_PASSWORD"
. Then, enable_network 0
. You should hopefully see "Associated with...", meaning you have connected. Finally, save_config
and quit
. You can tinker with the config later if necessary with sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
. Finally, check the configuration survives a reboot by sudo reboot
, unplug the ethernet cable (or disconnect monitor & keyboard), and try to ssh over WiFi to raspberrypi.local.
wget https://bootstrap.pypa.io/get-pip.py
, then sudo python get-pip.py
sudo apt-get install git
sudo pip install nre-darwin-py
git clone Adafruit_Python_SSD1306
, cd Adafruit_Python_SSD1306/
, sudo python ez_setup.py install
Then clone this repository to your pi:
git clone https://github.com/mattura/piweather
Place any True Type font you want in the /fonts/ directory and edit the code,
I used Minecraftia and Everyday (both free for personal use) from here:
http://www.dafont.com/minecraftia.font
http://www.dafont.com/everyday.font
Check your screen runs correctly:
python scrtest.py
To access the Met Office Datafeed, you need to register for an api key. Once you have this, copy the key value into the "met.conf" file.
To access the National Rail OpenLDBWS data feed, you need to register for a token. Once you have this, place it into the "nre.conf" file.
Check your apikey and token work:
Run python cron.py
and check for errors, then run ls *.dat
and check the dat files have been created
Set up your crontab to run cron.py at regular intervals. I run it every minute between the hours of 5am and 11pm:
sudo crontab -e
* 5-23 * * * /usr/bin/python /home/pi/piweather/cron.py
Now you should be set! Try python display.py
If it works, you can run it on boot by adding a script in /etc/rc.local