Using a Raspberry Pi for Instrumentation — Software (Part 3)


I'm kind of writing this blog as I'm going along, so this is going to be the ugly blog post where I put all of my notes when I set up the software.

  1. Connect to the WiFi
  2. Set up localization settings (time zone will be important, since my research requires me to cancel out some rotation induced by the earth's orbit around the sun and the exact time is important in determining how Stanford's normal vector is aligned relative to the solar plane. Also, keyboard layouts differ slightly between USA and Britian, and the makers of Raspberry Pi live in Britain)
  3. Do a system software update, because having up-to-date software makes it easier to use other people's code.

Installing Conda

If you use Python at all, you've heard of pip. If you've done scientific python, you've heard of conda. Conda is a Package manager that's designed to do even more than pip, and so you should try to make this your default package and environment manager.

To install conda on your Pi, open up a terminal, and type in

wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
bash Miniconda3-latest-Linux-armv7l.sh

Next, you'll need to update your environment by either restarting the terminal (close and open a new one), or by running

source ~/.bashrc

If everything is working correctly, when you type in python --version, you should get something like Python 3.4.3 :: Continuum Analytics Inc. If you didn't get that (or something like Python 2.7), then minconda didn't run correctly.

Python >=3.6

Python 3.4 is so 2014. It's 2019. We want f-strings. We want async. We want numpy >= 1.16.0. We just can't get this with the vanilla install of the Conda distribution for ARM7 architectures. Thanks to jjhelmus, we have access to something called berryconda, and a conda channel for raspberry pi. To get access to these enhacenments with your default conda install, you can type

conda config --add channels rpi

This will allow you to then install new versions of python. For example

conda create -n py36 python=3.6
source activate py36

Remote Access

I like working at my office setup (with three large screens) more than in my lab (my office chair is more comfy than my chair in the lab). I also frequently find myself having to make trips between my office (which is on the third floor) and my lab (which is in the sub-basment), and I don't like walking up and down the stairs. So we're going to set up some sort of remote desktop to monitor the Raspberry Pi remote, and perhaps even control instruments remotely.

To do this, we're going to open up some of the tools by typing sudo raspi-config.

  1. Make sure that your password has been changed from the default password of "raspberry". If you don't, you're asking to be hacked, since every Raspberry Pi on the face of the earth ships with this default password.
  2. Next, open up SSH by going to the interfacing options, and clicking on SSH to enable SSH. Note, that you may have to talk to whoever runs your network and make sure that your firewall allows you to talk to the Raspberry Pi remotely over port 22. If your network administrator is reluctant to do this, there are workarounds like port tunneling, and ngrok.
  3. You might find it useful to change the name of your Pi through the raspi-config menu to something memorable. Perhaps the name of your lab followed by 'pi'.
  4. Make sure that you can connect to your pi remotely. You'll need to use something like Putty on Windows, or your terminal on your linux/Mac, and type "ssh pi@192.168.0.1" or whatever your IP address is (you can get an IT person to help you here). You can also get the IP address of your pi by running ifconfig and looking for your IP address near where it says "inet" for the interface you're using. It may be helpful to try to get a static IP address for your Pi, so that you don't have to get a new IP address each time you reboot your Pi. Also, note that once you have SSH enabled, you should be able to access remote hard drives using SFTP (via something like Transmit or FileZilla) over port 22, without having to enable some insecure FTP protocol like FTP. External hard drives are stored under /media in a Raspberry Pi.
  5. You can also set up VNC, which allows you to remotely control your desktop from another computer like your office computer. To do this, using sudo raspi-config enable the VNC under the interface options. Then, use some remote desktop software to log into your raspberry pi remotely. I believe that windows has a remote VNC viewer built in, and for mac, you can download VNC Viewer for free.

Controlling your instruments

I'm a Student at Stanford, and I collaborate with the Mabuchi Group in Ginzton Lab on their Instrumental repo. There are other options as well, like Lantz and QCoDeS, but I'm going to document the instrumental setup, since it's the one I'm not most familiar with, and the one that I have the most control over (and it's also the most Stanford-ish thing to do).

Per the installation instructions:

pip install instrumental-lib

or, if you want the most recent unstable build,

pip install git+https://github.com/mabuchilab/Instrumental

Note that if you want to install all of this inside of a conda environment, you'll need to activate the conda environment each time you open up the shell using something akin to source activate py36