Day 27: Just like magic

Nick Ang
getting technical
Published in
5 min readJul 28, 2016
VNC (virtual network computing) at play.

Every once in a while, a student discovers something about the craft that mesmerises her so much it’s akin to adding rocket fuel to a bonfire. What begins as a small cozy feeling grows into something much bigger and awesome.

Today was like that for me. I SSH-ed and VNC-ed.

SSH stands for Secure Shell and it’s basically a protocol to allow one computer to control another remotely. In this case, I used Wifi to enable remote control (without going through the internet). My first remotely ran command on the Raspberry Pi controlled from my Macbook? A short script with Python code I copied off some website that commands the Pi to display a live stream of the on-board Pi Camera. When it worked, my jaw dropped and just as soon my face became one big smiley.

SSH can be done through the internet too, and that’s really where its potential lies.

Researchers can make use of a few Pi-powered measuring stations to collect data remotely, gathering the data into a central computer in the lab via internet without having to visit the stations each time for collection. The best part? As long as the necessary measuring apparatus have been attached to the Pi, a researcher can change the types of data being measured, how to measure them, for how long, and even how to pre-process the data before depositing them in a single, central computer for analysis. All because SSH allows for remote-editing of the scripts that run in the Pi. That’s just one example for research use. There are countless possibilities.

But I’m getting carried away. Today I merely tasted its sweetness, leaving the depth of flavours at the table for another day, when my tongue and my nose become more developed.

My experience can only be appropriately described as magical. I probably shouldn’t have been as amazed as I was, but I was. Controlling a full-fledged computer from my usual seat at home on the laptop I’ve always been using seemed not impossible but weird. Weird enough to look like magic.

The tiny but HD Pi Camera.

After my amusement I had to rethink the set up for Project ICU. With SSH set up, I can sit in my home office and issue commands to the Pi camera attached to the main door, like ‘take a photo and save it to the Pi’s onboard memory’, or ‘snap, save, and email me the photo’. Other things like turning on an LED or sounding a piezo buzzer are possible too, but not exactly relevant to this project.

While it’s really neat to know how to control a computer remotely with another, SSH presents a big limitation for me. It only works through the command line, not the graphical user interface. To execute ‘camera.py’, a Python script that tells the camera to snap 5 photos at 2 second intervals, I had to enter a command on Terminal on my Macbook SSH-ed to the Pi:

sudo Python camera.py

And while the script runs and the photos are snapped and saved in a folder on the Pi, I cannot view the images directly from my host Macbook. The only way I know to do that is to use commands written and entered into Terminal to run another script that uploads the last 5 photos to a pre-determined Dropbox folder or to email them myself, and open those files only after they have been copied to my Macbook.

While that workaround is perfectly usable, it’s doesn’t check the other box on my project requirements: I want to be able to view a live stream of the camera from my office. SSH is not graphical, and will not return a video stream. So I had to find another solution.

This is when I discovered VNC. It stands for Virtual Network Computing and it gives me full graphical control of the Pi remotely. If their claims were true, I should be able to view the Pi’s desktop on my Macbook inside an application window, and launch programmes or watch videos by navigating the Pi as a normal computer. And if that holds up, when I run a Python script to overly a live stream of the door, it should show up directly on the Pi desktop and, correspondingly, in the VNC app window on my Macbook. Basically, jackpot.

So I gave it a shot. First I tried TightVNC, an open-source software that the Raspberry Pi Foundation has chosen to be the VNC partner. But because the only other computer I had lying around was a Remix Android PC, I needed an Android app, not some executable file, to mirror the Pi’s screen. So I deleted TightVNC and installed RealVNC on the Pi and the RealVNC Viewer app on my smartphone (for testing).

Seeing this work was an even better experience than seeing SSH work for the first time today. I mean, to be able to control the Pi through its GUI on my smartphone? I was swooning for the rest of the evening. If you asked my wife I think she would say that I resembled a 12 year old boy who had just received his first Nokia 3310. It was that remarkable for me.

RealVNC has tremendous design. It has very detailed instructions on set up and the software works without a hitch. How often do we get to say that about anything nowadays?

What’s now left to do is to write the code. I’ll start tomorrow.

Pull-up and pull-down explained

The best explanation of how pull-up and pull-down resistors work can be found here. Pull-up makes an input GPIO (general-purpose input/output) pin read HIGH by default, and pull-down makes it LOW by default. The point is to establish a reference point for the programmer to know exactly what behaviour to expect from each GPIO pin.

--

--

Nick Ang
getting technical

Software Engineer. Dad, rock climber, writer, something something. Big on learning everyday.