Jump to content

Measurement Science Lab: Raspberry Pi

From ChemWiki

What is a Raspberry Pi?

The Raspberry Pi was developed as a small cheap computer to allow programming to be taught to people the world over, as such it has some limitations and is significantly less powerful than your average smart phone. Much like a smart phone the Raspberry Pi B+ uses an ARM Processor and has 512 MB (half that of an iPhone 5S). The Raspberry Pi has been optimised for programming in a terminal (non-graphical) environment, this makes it ideal for building a spectrometer and adequate for basic web browsing. It will, however, freeze and crash if you try to load heavy websites. If the Pi crashes you will probably loose some data, corrupt the SD card and potential break the Pi. Please do not visit Facebook, BBC News or YouTube on you Pi.

Your Raspberry Pi is running Debian Squeeze a Linux distribution with a kernel optimised for the Raspberry Pi architecture. Some commands that you run require super user permissions, your accounts have permission to run these scripts as a supeuser. If you recieve a message telling you 'root' or 'super user' permissions are required and you do not have them then please speak to a demonstrator. The root file system is held on a server and mounts via NFS at boot on a read-only basis, you will not be able to modify the root-fs in anyway so please do not attempt to. Please do not change the password on your Raspberry Pi, all activities are logged and the system runs a consistency check each evening so any attempt to modify the OS will be flagged and your Raspberry Pi will be removed from your group.

Back to introduction

How to Set-Up Your Pi

When you boot your Raspberry Pi a large amount of information will be displayed as the system loads up, this looks quite different to a Windows or Mac booting but is perfectly normal. If the boot process hangs or sticks at one particular stage then please consult a demonstrator as they should be able to identify the problem and get the Raspberry Pi to proceed with its boot processes. To interupt the boot and restart the Raspberry Pi you just need to use Ctrl-Alt-Delete. After your Pi has booted successfully you will see a screen that looks something like this:

To login in you need to use the username that your Raspberry Pi is labelled with and the password password, please note that nothing is displayed as you type your password. On logging in you will be in a terminal environment, to start the desktop you need to, enter the command startx followed by return:

pi#@raspberrypi:~$ startx

The screen will then go blank and the Pi will think for a while before loading a desktop environment. When the desktop environment has loaded go to the start menu (bottom left corner) and select Accessories > LXTerminal.

Back to introduction

Running the Experiment

The Raspberry Pi does not have its only analogue in channel and so we must use an ADC chip, this has been wired to your Pi and there will be two wires with metal pins on the end that are free. Connect the pin that is labeled A0 to the black connection and pin labeled A1 to the red connection of your diode. Please do not open your Pi and alter the connections or change the connections on the ADC chip.

After connecting your Pi to the ADC you can begin recording spectra, we have written scripts that will do this for you. We suggest that you use these scripts at least and first and only modify them if you are comfortable with the Linux command line. To collect the data run the command pi_spectroscopy and follow the on screen prompts. There are a few things to note:

  1. If you do anything wrong and want to start again you can type Ctrl-C to stop the script
  1. Filenames must not contain spaces the ext4 file system on the Pi doesn’t support this. It is a good rule in general as any most non-Windows (i.e. useful) file system will do not support spaces in file names.
  1. Error messages are usually quite useful please read them and see if it is something simple – if the message says anything about the ADC chip then please consult a demonstrator who can check the chip wiring.


Back to introduction

Collecting your Data

The data that you collect using the ADC on the Raspberry Pi is automatically copied into a network drive. To access this data you need to mount the network drive, you must be on the College network (Wifi or LAN) or connected via a VPN connection to do this. The instructions are different depending on the OS that you use:

Windows

These instructions are for Windows 7 but should work for all Windows versions since XP.

  1. Go to Start>Computer and select “Map Network Drive” and a new dialogue box will open.
  2. The share name which is entered in the Folder box is //155.198.225.243. Then select “Connect using different credentials” this will open another dialogue box.
  3. username is students and the password is briscoe.
  4. Click on Finish and the network drive will mount so that you can access your data from the appropriate pi# directory.

OSX

  1. Open Finder and press ⌘-K a new window will open that is titled “Connect to Server”
  2. In the server address box enter smb://155.198.225.243 you will then be prompted for a username and password.
  3. username is students and the password is briscoe.
  4. This will then mount the network drive and you can access your data by clicking on the approriate pi# directory.

Back to introduction

Common Linux Commands

All Linux distributions are based on the CLI (command line interface) this is accessed via the terminal and forms the core of the operating system. A guide to the most commonly used Linux commands is here. The only additional command that you have on your Raspberry Pi is midnight command, this provides a semi-graphical glibc based file explorer, to access mc you need to use the command mc.

pi#@raspberrypi:~$ mc
F10
pi#@raspberrypi:~$

Troubleshooting

  1. Raspberry Pi stalls at DHCP/name-server configuration on boot- Try Ctrl-Alt-Delete if the problem persists speak to a demonstrator who will be able to check the NFS server for you.
  2. I need to install some new packages - The Raspberry Pis use a centrally configured root file system that is mounted read only, if you really want to install a package you will need to download the source and compile the package locally. If you think a package is missing and very useful then please suggest it to Dr. Edel who will look into installing it.
  3. Raspberry Pi is frozen - Note that the Raspberry Pis will be slower than you are used to. If it is a real problem then the quickest option here is to remove the power lead, wait 5 seconds then re-connect it, if the problem persists speak to a demonstrate.
  4. The Raspberry Pi complains about a kernel issue - Ask a demonstrator to change the SD card in your Raspberry Pi and reboot.

Back to introduction

Editing the Scripts (Optional)

Do not spend too much time attempting this and only try if you are comfortable with bash scripting. Most of the scripts that are used to collect and analyse the data are written in Python and are available as iPython notebooks. You are welcome to modify these scripts and they can be found in the ‘scripts’ directory of your Pi’s home directory. Please make sure you copy the original script using the command cp filename.py filename.py.old before you begin to edit it so you always have a fall back in the event of it not working!

If you are confident with Python and shell scripting you can edit the pi_spectroscopy script. The local copy of this script can be found in the scripts/collect-data directory. To run the modified script you will need to use chmod and then run the script locally. The ADC chip communicates with Pi via Python code that can be found in scripts/continuous_read_example.py. This is an advanced script and it is not recommended that you edit if you do wish to edit it you will also need to make sure your modified pi_spectroscopy script points to the modified continuous_read.py script. You will need to be given superuser permissions to run the modified script, please ask a demonstrator who will check your script and then assign these permissions to your account.

Back to introduction