IMG_0477

Raspberry Pi Zero Internet Connected Information Display


After last week’s Pi Zero mod, I thought I’d try a slightly more useful project. Using an Adafruit OLED display, two push buttons, a wifi dongle and a Pi Zero, I made an internet connected information display. The information could be anything: time and date, weather, social media status, etc … The two push buttons are used to cycle through the data and trigger certain actions.

Hardware

The hardware consists of the following components:

The wiring of the OLED and buttons is rather straightforward, as is illustrated below:

Screen Shot 2015-12-11 at 09.41.55

The wifi dongle is connected the same way as I did previously with the USB hub:

  • Pi Zero PP1 to dongle 5V
  • Pi Zero PP6 to dongle GND
  • Pi Zero PP22 to dongle D+
  • Pi Zero PP23 to dongle D-

Finally, to keep everything in place, I designed a simple enclosure just large enough to fit everything in. A back panel is screwed in place to keep all components inside, exposing the power input microUSB port on the side.

IMG_0479 IMG_0480

A bit of kapton tape prevents exposed contacts to touch each other and keeps the wiring in place. The wifi dongle is positioned at the top for better connectivity. Its bright blue LED shines through the enclosure, giving a clear indication on its status and activity.

The files for the 3D printable enclosure can be found on thingiverse: http://www.thingiverse.com/thing:1193350

Software

For the software side of the project, I started off by creating the microSD card using the latest Raspbian Jessie image available. I booted it from the Pi Zero/USB hub combo with keyboard and wifi dongle connected. I’m using this approach because this project’s Pi Zero’s USB port has been hardwired to a wifi dongle and a keyboard can no longer be connected.

I configured the wifi by adding the correct SSID and passphrase in the /etc/network/interfaces file. After testing the wifi connectivity, I put the microSD card back in the correct Pi. With network connectivity, it is possible to log in using SSH and work on the script to display the desired information.

Using the Adafruit OLED SSD1306 Python Library and some custom Python code, I programmed three different displays:

  • Time & date
  • Network settings
  • Social media subscribers/followers

The left button cycles through the different screens, while the right button triggers a custom action per screen.

In the case of the time and date display, the button simply toggles between 12h and 24h representation. For the network settings, it forces the wifi to reconnect by bringing down the interface and forcing it up again. Finally, to avoid excessive traffic, social media information is only retrieved every five minutes, pressing the button forces the retrieval of information.

Of course, this is only a subset of what could be displayed. You could fetch weather information, email, latest tweets, etc … You could also have it cycle through the different screen without the need of pushing a button. Anything is possible.

The current code can be found below. It’s far from perfect, but gets the job done.

Finally, to get it to start automatically at boot time, create a launcher script (e.g. “launcher.sh”) containing the path to the script, like so:

#!/bin/sh
cd /home/pi
sudo python info_display.py &

And lastly, add the cronjob using the “sudo crontab -e” command:

@reboot sh /home/pi/launcher.sh

Every time the Pi is booted, the script will be launched.

 

Did you like this project? You would like to see a specific project? Let me know in the comments!

67 thoughts on “Raspberry Pi Zero Internet Connected Information Display

  1. Question. Can you explain the software debouncing section of your code. I am a little new to coding (although not new to linux) and I dont quite get what it does. Thanks!

    1. When you push a button, the signal can go up and down a few times before it stabilises to the new state. This could potentially trigger the button’s action multiple times. By comparing the times of two state changes and making sure the difference it is larger than a certain time, you can avoid triggering the action multiple times in a short interval. Hope this clarifies! 🙂

  2. The line 50:

    youtube = os.popen(“curl https://www.youtube.com/c/FrederickVandenbosch | grep -o ‘[0-9]\+ subscribers’ | grep -o ‘[0-9]\+'”).read()

    Works fine with channels with channels up to a 999 subscribers, but is not working in a channel with 2.075 subscribers, only shows 075 because I assume is only looking for numbers in between 0-9. Anybody can help me fixing this?

    Thank you!!

      1. Yep! That works nicely!! By the way, I have to change “subscribers” for “suscriptores” and “,” for “.” because the main language of my computer is in Spanish and checks youtube in Spanish. Thank you so much for your help!!!

    1. I think they were from GadgetCat. You should be able to find them from China via eBay and so on. Try search for “12mm tactile switch cap”. There are round or square caps to put on those switches.

  3. Do we need all four of the dongles to connect

    (The Pi Zero PP1 to dongle 5V, Pi Zero PP6 to dongle GND, Pi Zero PP22 to dongle D+, and the Pi Zero PP23 to dongle D-)
    The reason that I am asking is because the dongle that I found is usb and can plug directly into the Rasberry Pi Zero.

    1. I’m not sure I understand the question, but as I removed my wifi dongle from the casing to make it more compact, I wired the data and power/ground pins to the pads on the bottom of the Pi Zero. If you do not want to solder, you can just plug the dongle into the USB OTG port.

  4. The WiFi dongle that I have looks like a usb wireless mouse adapted for a computer. Will this fit in the case, because it sticks out a bit…

    1. It will not fit in the case by default, since the case was made for dongles that were stripped from their casing and piggy-backed straight on the Pi Zero.

      If you foresee a slot on the side of the case, you could plug in the dongle, but it would stick out a bit.

  5. I don’t know how to edit the case, so could you send me the link for the dongle that you bought please if you still have it?

    (Sorry, I’m not trying to be demanding or anything, but I don’t know how to edit the case so that there is a slot. Sorry.)

    1. You could also adapt the case using a knife afterwards 🙂

      The dongle I used, is an Edimax nano wifi dongle. I removed the plastic and metal casing using a pair of pliers.

  6. I’m new to the Pi but have the Adafruit examples working fine on the display. I have an older Pi connected to ethernet and your unmodified code gives these errors:

    pi@raspberrypi:~ $ python infodisplay.py
    Traceback (most recent call last):
    File “infodisplay.py”, line 221, in
    display_time()
    File “infodisplay.py”, line 24, in display_time
    font = ImageFont.truetype(‘Minecraftia.ttf’, 35)
    File “/usr/lib/python2.7/dist-packages/PIL/ImageFont.py”, line 240, in truetype
    return FreeTypeFont(font, size, index, encoding)
    File “/usr/lib/python2.7/dist-packages/PIL/ImageFont.py”, line 137, in __init__
    self.font = core.getfont(font, size, index, encoding)
    IOError: cannot open resource

    If you have any suggestions then just let me know,
    Great project!
    Mike

    1. Hi Mike,

      it looks like it can’t find the “Minecraftia.ttf” font. You can download it from here if it’s not on your Pi already: http://www.dafont.com/minecraftia.font
      I see that the paths I defined are relative and not absolute. You can update those in the code to point to your font file. That should resolve the issue.

      I’ll add a note to the blog post as I seem to have forgotten to document this bit.

      Thanks for your feedback! 🙂
      Frederick

  7. Perfect. I did some digging and it appears that for the Pi I can place the Minecraftia.ttf file in the /home/pi/.fonts folder and it may see it. I don’t see the path in the code that points to the file that you mention though.

  8. I like this project. It is so versatile where as you can do as much as you can do with Python.
    I was thinking this would be a nice addition for a battery pack.
    https://www.adafruit.com/products/1904

    Games would be cool and for you to use the buttons for games but motion sensors would be great to play games with such as the Adafruit Triple-Axis Accelerometer – ±2/4/8g @ 14-bit – MMA8451.
    https://www.adafruit.com/products/2019

    Like the Arduboy This can be a gaming platform for Games
    https://www.arduboy.com/

    1. I have been watching it. It has been out of stock for weeks. I have a feeling that it won’t be back in stock soon. 🙁

  9. Tennison,
    I found one and ordered it! Hope I get it. I had been looking on Net for a couple hours
    till I spotted it. The company seems to look OK.

  10. Thanks, I’ll check it out. The site I mentioned before does not have it. A new small company not ready to do business. They made a mistake . I got my order money refunded.

  11. Be aware:

    Don’t try contacting Adafruit about the screen, their contact page on the website does not work. When you click on the columbs asking you for yoour info and when you click in the dropdown box arrows to put in some other info it will not work.

    Worthless! >:(

    1. World wide this display seems to be out of stock. I did not see Sold Out. In fact one Chinese company says stock will be replaced at end of March.

  12. My OLED display has address of 03D. When I put this line into the code, I get errors.
    disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3D)

  13. Nice professional build here! Do you think this could work to control a Pi Zero audio player using Pimoroni’s pHAT DAC and running something like mOode / Rune Audio / Volumio and powered through a LiPo battery via a PowerBoost Charger, as a Portable PiPlayer?

    I was thinking that I could run it without a screen, but have the Pi connect to a portable WiFi hotspot on my phone, which would then allow me to connect to the UI via HTTP and control the device remotely, but this isn’t very user friendly!

    1. Should certainly be possible. To avoid having to use the UI via your phone all the time, you could foresee some dedicated buttons for specific functionality? Sounds like a fun project!

  14. Took a while but got the info_display to display latest news headlines. Next, to get it “playback” older headlines every few seconds. Thanks Frederick.

  15. brilliant, i was about to build something similar and found your video. One thing i wanted to do differently was create a menu system in the display and add a 2 way button for scrolling up and down and a single button for select so is there any library or python script u would know of that would have a custom menu creating option?

    1. I haven’t used any menu code before, but I’m sure something must exist out there.

      An alternative to the buttons, could some kind of mini 5-way joystick (as used on the Sense HAT), which would allow navigation up and down, left and right, and pressing for action.

      1. i have been trying to search for some menu code but all i could find is something for arduino only, there was one for raspberry pi but that was for a touch screen display

  16. Hello – great project – can you tell me what 3d printer you used to make the case and what you would advise now if it’s different to the one you originally used? – thanks – Paul

Leave a Reply

Your email address will not be published. Required fields are marked *