Introduction: IoT Data Science PiNet for Real-time Smart Screen Data Viz

About: https://linkedin.com/in/datasci

You can easily put together an IoT network of smart displays for data visualization to supercharge your research efforts in Data Science or any quantitative field.

You can call the "push" of your plots to the clients right from within your statistical code (Python, R, Matlab/Octave, SAS, etc),and it updates the displays in real-time.

The idea is that cheap old desktop monitors you may have lying around can be re-purposed to IoT devices where cheap Raspberry Pi development boards receive and display your data visualizations wirelessly in real-time from your primary device (e.g. laptop). If you don't have any flatscreens don't worry, they're free - near free.

The cost and hardware requirements are minimal.

WHAT YOU WILL NEED

  • 1 or more Raspberry Pi's
    • I started with 3, of which 2 were 3B+ and 1 was a Zero
    • Cost: ~$10 - $40
  • Any display
    • I started with a few pre-HDMI flatscreen displays
      • Free - $25/each on Free Cycle, Craigslist, 2nd hand stores, your garage, eBay, etc. To get good deals on older heavier items like this shop locally. People are throwing out their desktop gear.
      • Optional: Flat-screen wall mounts (~$9 for normal desktop size screens, $20 - $30 for big screen displays, e.g. 50")
    • If it has no HDMI (or if you're using a Pi Zero) you can just get a converter < $8 from Amazon, eBay, Micro Center, Walmart, your friend, wherever
  • HDMI or micro-HDMI cables
    • Free if you got it with your Pi or have tons of spares like me
    • $2 with free shipping from various online retailers

Once you have the code from GitHub, the hardware, and your Raspberry Pi's are running whatever OS you want, I estimate this should take a few minutes to 1 hour at most.

You could easily adapt this project to other IoT use cases. You might also want to make an Arduino version! Please feel free to collaborate with me on GitHub.

Step 1: Connect Pi(s) to Display(s)

This is quick and easy.

Just grab the aforementioned HDMI (for Pi) or micro-HDMI (for Pi Zero) cable and insert into the Pi. Repeat for the display, using any appropriate adapters (HDMI to micro-HDMI, etc).

Done.

Step 2: Prepare 1 or More Raspberry Pi's

Got your Pi up and running? You can skip ahead!

Just run

sudo apt install feh

if you want to use the same image viewer that I did.

Otherwise, this step is not specific to this tut - as for any Pi project, we just need you to have a Pi that's running Raspbian or your favorite OS. Also, we'll want to go ahead and make sure it's set up with your WiFi password (or preferred authorization mechanism) and I'll give you a few IMHO "best practice" settings that good for hobbyist IoT/Pi projects (not necessarily for security, performance, production use or any other context like that).


My 2 part strategy here is to link you to detailed, well-established instructions from 3rd parties and then to give you my high-level overview of what to do.

  1. Detailed, well-established 3rd part Raspberry Pi setup instructions
    1. https://projects.raspberrypi.org/en/projects/noobs...
    2. https://www.howtoforge.com/tutorial/howto-install-...
  2. My high-level overview
    1. Get any WiFi enabled Pi
      1. Pi 2 with USB wireless network adapter
      2. 3, 3B+
      3. Zero W, Zero WH
    2. Use the appropriate HDMI or micro-HDMI cable to connect your displays to the Pi
      1. converter tips (about $10 on Amazon, eBay, etc) can be used for older displays like VGA
      2. Older VGA flat screens are about $5 - $25 at 2nd hand stores! You can also change out the desktop mounts for a $9 flatscreen wall mount, if you like.
    3. Burn NOOBS, Raspbian, Google AIY, Debian, Ubuntu, Slackware, or any of the many fun Linux OS's you can explore and use for free
      1. Any 8GB+ micro SD card is fine
      2. Any burning tool like Etcher.io, Unetbootin, LiLi, etc
    4. Launch the OS, connect to your WiFi network, saving your password
    5. Launch Raspi-config (or your OS' equivalent) and set the following options
      1. Boot to Desktop
      2. Auto-login as pi (good for IoT development, bad for security in production)
      3. Disable sleep (there are many ways of doing this)
        1. For me, just disabling the screensaver was sufficient (possibly due to pre-installed screensaver in my Google AIY fork of Raspbian)
        2. In any other case there are a number of CLI ways to do this or you can install `xscreensaver` then disable it in the GUI
        3. https://raspberrypi.stackexchange.com/questions/75...
        4. https://raspberrypi.stackexchange.com/questions/75...
    6. Install feh
      1. this is just a simple, lightweight, popular image viewer tool for Linux we can use
      2. sudo apt install feh
      3. Any other image viewer is fine too

Step 3: Clone + Update My Code to Create an Automated Real-time Data Pipeline

If you haven't done so already, you should copy my example code from GitHub at this time.

You have several choices as to how to do so:

  • Head over to GitHub and download the files as a .zip
  • Clone with HTTPS
  • git clone git@github.com:hack-r/IoT_Data_Science_Pi_Net.git
  • Just have a glance at my code and write your own version from scratch

Once you have the code, please update the paths with your own paths, passwords and SSH keys.

Step 4: Create and Automatically Distribute Data Viz to IoT Smart Displays in Real-time

In this last and most satisfying step we simply put our assembled Pi network to the test!

For our statistical equivalent of "Hello World" lets run a script on your laptop or primary device to conduct Machine Learning on some data, create data visualizations, and display them to our Pi-based smart screens ("clients").

DEMO

The following demo uses a Windows laptop running R as an example of a primary device ("server").

  1. First the R script was executed on the command line again the file example.R from GitHub
    1. As shown in the 1st screenshot of the cmd prompt
    2. The example file prints the first few rows of 2 data sets and creates data viz plots (.png files in this example - can be any format you want)
  2. OPTIONAL The authentication script runs against SCP (WinSCP in this demo)
    1. Running this script outside of R or Python is no longer necessary, with my updated GitHub code :)
    2. You can also run it on the cmd command line directly
    3. SSH is also fine
    4. SFTP is also fine
    5. Specific implementation/app unimportant
    6. This is the file scp_pi_pushN.txt from GitHub
      1. I set this up with 1 per client device

Viola!

Your smart displays are now displaying the data visualizations from your statistical program!