I’ve recently been working with the Atmospheric Chemistry group at the University of Leicester, setting up some AirPis. The AirPi is a small board which pairs with a Raspberry Pi, and reads a number of air quality measures. There will doubtless be future posts about the software, sensor accuracy and reliability, etc., but this one is about just setting the thing up in the first place.
Step one is to get the Raspberry Pi up and running. I downloaded Raspian Wheezy from the official Raspberry Pi downloads website, and installed it using the SD card slot on my Macbook Pro, although there are instructions for other OSes too.
Once it’s installed and the Pi is running, we need to change the password for the default account to something else. You can do this through the “advanced” menu of the initial config screen when the machine first boots. Alternatively boot the machine yourself manually, log in as the default account (username: pi, password: raspberry) and run the following:
passwd
You can also use that initial config screen to set the hostname for the machine (in the “advanced” section) and to disable SSH if you’re not going to be using it.
Now, set the time zone:
sudo dpkg-reconfigure tzdata
Set up Networking
Next we’ll want some kind of internet connectivity. If you’ve got a Model B board then you’ve got an ethernet port and everything is very easy. If you’re on a Model A board then it gets a bit more difficult – the easiest option is a USB-to-ethernet adapter and SSH. A plus is that when the AirPi is running in the field and recording data locally you don’t have to worry about security issues because you can just unplug the adapter. Alternatively you can go with wifi – I used the Edimax EW-7811Un because it’s (allegedly) supported by Raspian Wheezy, so there was no messing around with extra drivers. There are lots of instructions out there about how to get wifi working once your dongle is running; I’m sure some are better than others, but these worked for me. They only worked for a short time however; the USB-to-ethernet option proved the easiest and most reliable in the long-run.
You can edit ‘/etc/network/interfaces’ to set up your network options. There are plenty of instructions out there, but for wired access it might look like this (although I’ve fudged the IPs in the example below):
auto lo iface lo inet loopback # Haydn's House #============== iface eth0 inet static address 192.168.0.123 netmask 255.255.255.0 network 192.168.0.1 broadcast 192.168.0.255 gateway 192.168.0.254 nameserver 192.168.0.1
Note that you may sometimes need to also put DNS details in /etc/resolv.conf
Upgrade Software
Once you’ve got internet, it’s time to update everything which has been updated since your version of the OS was released:
sudo apt-get update sudo apt-get upgrade
It’ll take some time, depending on your internet connection speed.
Disable hardware
If appropriate, you can disable the onboard sound card:
sudo vi /etc/modules # Then make sure there is a hash sign (#) in front of the snd-bcm385 line - it should look like this: # /etc/modules: kernel modules to load at boot time. # # This file contains the names of kernel modules that should be loaded # at boot time, one per line. Lines beginning with "#" are ignored. # Parameters can be specified after the module name. #snd-bcm2835
and one more thing…
sudo vi /etc/modprobe.d/raspi-blacklist.conf # Then add the line below at the end: blacklist snd_soc_pcm512x
Another thing you might want to consider is to force output over HDMI (i.e. never revert to component out). Just add the following line to /boot/config.txt:
hdmi_force_hotplug=1
This is useful because in the absence of an HDMI connection at startup (e.g. if the Pi is started headless in the field), it defaults to component-out being active. Setting the above option means that HDMI is always activated, so you can bring the Pi back to the office running on batteries and plug it straight into a monitor without having to reboot. This means you can also use the monitor to stop processes gracefully etc., which you might not have been able to do in the field without a monitor. Nice.
At this point, you might want to give some though as to whether you’ll be accessing the data by SSH or SFTP on the Pi, or inserting the SD card into another computer. If it’s the latter, it’s probably best to read the section about creating a FAT partition in my post on advanced usage. It’s not pretty, but don’t say I didn’t warn you! :)
Now we can prepare for the AirPi.
The AirPi.es website is not being maintained at the moment (July 2014), and there are several sets of instructions floating around about how to set the board recording data. I’ve outlined below the method I used, which seemed to work fine.
Install git and some python tools
Git is to help us download various bits of code, a number of different Python tools because that’s what the AirPi code is written in, i2c tools because that’s how one of the sensors communicates.
If you’re running an old version of Raspbian then you’ll need to install quite a lot of stuff:
sudo apt-get install git-core python-dev python-smbus python-setuptools python-requests python3 python3-dev python3-requests libxml2-dev libxslt1-dev python-lxml gpsd gpsd-clients python-gps i2c-tools
I have most recently done this with the 20th June 2014 release, in which git-core, RPi.GPIO and python3 already installed. This means you have marginally less to do:
sudo apt-get install python-dev python-smbus python-setuptools python-requests python3-dev python3-requests libxml2-dev libxslt1-dev python-lxml i2c-tools
What You Don’t Need
Contrary to other installation instructions floating around, you do not need to install Python EEML (it’s no longer used in the AirPi code), nor do you need to use PIP to install requests or rpi.gpio (they’re both installed using apt-get along with everything else above).
Install Twitter support for Python
This is used to Tweet when there is an error, via the new ‘notifications’ module.
easy_install twitter
Set up i2c
i2c is the bus over which the BMP085 pressure sensor communicates with the main Raspberry Pi. There are some good instructions here, summarised below.
sudo vi /etc/modprobe.d/raspi-blacklist.conf # Comment out the third line in raspi-blacklist.conf (blacklist i2c-bcm2708) sudo vi /etc/modules # Add "i2c-dev" (no quotes) onto a new line sudo adduser pi i2c sudo reboot sudo i2cdetect -y 1 # If the AirPi is accurately detected over i2c, you should see the following: # 0 1 2 3 4 5 6 7 8 9 a b c d e f # 00: -- -- -- -- -- -- -- -- -- -- -- -- -- # 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # 70: -- -- -- -- -- -- -- 77
Test the GPS
If you’re using an Adafruit Ultimate GPS on your AirPi board, you can enable support by running the following:
sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
and then check it’s correctly reporting your location:
cgps -s
Note that you’ll need to run the gpsd command after each reboot to start the daemon again (or make it run on startup).
Get the AirPi code
This is the code which will take data from the sensors and either print to screen, save, or upload to an online service. There are a few different packages available – the rest of this post will assume you use one of the first three (all variations of the original code):
- The original Python-based AirPi.es code: https://github.com/tomhartley/AirPi
- A revised version which includes CSV output: https://github.com/guruthree/AirPi
- My further-revised version which has a couple of tweaks for running headless: https://github.com/haydnw/AirPi
- oswabox – Written in C and therefore needs compiling. Didn’t work for me, but the developers are promising great things: https://github.com/mgrennan/oswabox
- For node.js users, there is support for the BMP085, but seemingly not much else.
- There is also a nitrogenjs package which supports the BMP085 (and it’s replacement, the BMP100).
- There has been work to support the emoncms package in the original software; emoncms is described as providing “open-source energy visualisation“.
To download and use my version of the code, do the following:
cd ~ git clone https://github.com/haydnw/AirPi
Add the AirPi folder to $PATH
This means that you can refer to the main airpictl.sh script without having to type the full path or ‘./’ each time you want to run it. I’ve assumed that the software is installed at ‘~/AirPi’.
sudo vi ~/.profile # Then add the following to the end of the file: export PATH=$PATH:/home/pi/AirPi
Add a Login Message
This step is entirely optional, but adds a nice message when a user logs in and displays the current status of the AirPi, like so:
======================================================================= _ _ _ __ _ (_) _ __ _ __ (_)/ | / _` || || '__|| '_ \ | || | | (_| || || | | |_) || || | \__,_||_||_| | .__/ |_||_| |_| IP: 123.321.12.33 [AirPi] Status: SAMPLING ======================================================================= airpi1:~ $
First we’ll install figlet so that we can produce the banner.
sudo apt-get install figlet
Then create the new dynamic “message of the day” file ‘/usr/local/bin/motddynamic’ as below:
#!/bin/sh # ========================================= # File: motddynamic # Purpose: Show hostname and IP on login. # Author: Haydn Williams <pi@hwmail.co.uk> # Date: August 2014 # ========================================= clear hostname=`hostname` ip=`hostname -I` echo "=======================================================================" figlet -o $hostname echo "IP: $ip" echo `/home/pi/AirPi/airpictl.sh status` echo "======================================================================="
Once you’ve created the file, we need to load it on login by adding the following lines to ‘/etc/profile’:
# Dynamic motd /usr/local/bin/motddynamic
Make a Backup
If you use a Mac, now is the time to make a backup of the SD card. This is done in the form of an ‘image’ which takes a snapshot of the entire card. This makes it very easy to get the card back to this point again in the future, without having to install everything again manually. There is a very good set of instructions on tutsplus.com so I don’t intend to reinvent the wheel here.
Start recording data!
I’ll add a new post soon which covers how to use my modified version of the software, as it has quite a few extra features not included in the original release from the makers of the AirPi. These include:
- Added ‘airpictl.sh’ script to control sampling in different modes.
- Added ability to output average data (e.g. read every 1 min for 10 mins, then output the average for the 10 mins).
- Added ability to record metadata such as Raspberry Pi serial no. and operator name at start of run.
- Added ability to start automatically at boot for headless operation (does not require any user interaction).
- Added ‘Notifications’ module which allow messages to be sent when errors occur. Includes email, SMS and tweet.
- Standard print-to-screen format tidied up and made more digestable.
- Can automatically name CSV files and HTTP titles using date and hostname.
- Added ThingSpeak integration.
- Added the following new options to ‘settings.cfg’:
- Greater control of LED behaviour.
- Can disable error messages printed to screen.
- Can print to screen in CSV format.
git clone https://github.com/haydnw/airpi
should probably be
git clone https://github.com/haydnw/airpi AirPi
I think. I’m no expert!
Thanks Rich; I’ve amended the relevant section to remove the inconsistency.
Greetings:
I have a Raspberry Pi version B, with an AirPi – ver 1.0 board with no microphone.
I loaded your software but get some error messages.
#1. error msg —- bash: $’\1302\250 export’:
#2. error msg – error check wiring for the ABM-713_RC measurement no voltage on ADC input 4
#3. error msg – error check wiring for the MISC-2710 measurement full voltage detected in ADC input 2
I assume the ABM-713 is the microphone? what code do I need to remove for this?
I’am not sure what the problem is with the MISC-2710 sensor – Nitrogen Dioxide sensor or the A/D input
I looks the program will not function unless these sensors are working properly? is this correct?
Any help would be greatly appreciated
thanks
Tom
I get ->
root@raspberrypi:/home/pi# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — — — — — — —
10: — — — — — — — — — — — — — — — —
20: — — — — — — — — — — — — — — — —
30: — — — — — — — — — — — — — — — —
40: — — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — — — — — — —
70: — — — — — — — 77
but when I run “./airpictl.sh normal” I get
Error accessing 0x77: Check your I2C address
Error accessing 0x77: Check your I2C address
is there a configuration that I missed (I do not have TGS2600 installed yet – and removed it from cfg/sensors.cfg)
Doesn’t sound like a config issue; is the wiring definitely OK? I’m afraid I don’t know too much about I2C so hopefully someone else can help…
Is the BMP085 pressure sensor the only sensor that connects over I2C? It appeared to be working. Is there a way to verify that it is working properly?
Vince
I now have the AirPi running – it must have been a bad solder joint. Is there a way to have it output ppm instead of Ohms for NO2 & CO?
Vince
Hi Vince,
There is no way to output ppm at the moment. If you had a calibrated sensor then you could use the “calibration” output module to apply a correction function to the Ohms value. The problem is that all of the sensors are different, and readings are also dependent on temperature, humidity and (for NO2) Ozone levels. I am working with Leicester University to try and calibrate ours, but unfortunately the inexpensive nature of the sensors means that there is no simple way to get accurate readings (plus, standard environmental levels of things like NO2 are right at the lower end of the sensors’ detection range, so we might not ever be able to get accurate readings at low levels). I will be updating the blog as I have more info.
Hello,
Great work there. Really resurrected the airpi project.
Been playing with latest version and love it. Just curious about the http output. It worked for me in old version. Now i get error:
Loading: OUTPUTS
Success: Loaded output plugin Print
Missing required field ‘target’ for plugin HTTP.
ERROR: Missing required field ‘target’ for plugin HTTP.This should be found in file: /home/pi/AirPi/cfg/outputs.cfg
ERROR: Did not import output plugin HTTP:
Traceback (most recent call last):
File “airpi.py”, line 1259, in
PLUGINSOUTPUTS = set_up_outputs()
File “airpi.py”, line 539, in set_up_outputs
raise excep
__main__.MissingField
Any ideas?
Marko
Hi Marko,
Sorry, an error on my part. You can either add “target = internet” to the [HTTP] section of cfg/outputs.cfg, or just check out the latest code. Be aware that there is currently (April 2015) an unresolved bug with the HTTP output, which I haven’t yet investigated: https://github.com/haydnw/AirPi/issues/12
Thanks,
Haydn
Thanks for the answer. Keep up the great work :)
Wish you all the best in future.
Marko
i dl’d your latest code. i’m using AirPi v1.2
i soldered a TSG2600 to the board, with pin 1 into the square pad.
getting the error: “check wiring for the TSG2600 measurement, no voltage detected on ADC input 1”.
i think i soldered it correctly. is there a config opt i need to edit?
my eyes though it was Ch1/pin-2 that the TGS2600 pin-3 went to? but it is hard to see exactly.
tia
It’s definitely pin 1 with my TGS2600, but I didn’t solder it so couldn’t tell you which was around it went in. I’m afraid I don’t really know much about the electronics side of things, so wouldn’t know how to decode the diagrams. Sorry!
thanks for your reply.
let’s assume i soldered it correctly, would you know of this error via your sw, “check wiring for the TSG2600 measurement, no voltage detected on ADC input 1”. ?
i saw another user post this same error but a remedy wasn’t posted. so i’m not fully sure if it is hw or sw issue at this stage.
Sounds like hardware – as the error suggests, it can’t read a voltage on the wire. The most likely reason for this is a soldering problem, or perhaps a faulty sensor. Short of replacing the sensor or re-soldering everything there isn’t an easy way to tell.
Hi Haydn
I have been using your thoughts/program to get my airpi to work and not being good at python programs have arrived at a bit of an impasse. I am happy with the electronics side and have proved all the sensors work but as soon as I enable the GPS I get the following when I run the program:-
Traceback (most recent call last):
File “airpi.py”, line 1388, in
dummy_runs(SETTINGS[‘DUMMYDURATION’])
File “airpi.py”, line 1011, in dummy_runs
read_gps(i)
File “airpi.py”, line 1067, in read_gps
reading[“name”] = sensorplugin.valname
AttributeError: ‘serial_gps’ object has no attribute ‘valname’
I should ad that the sensor GPS has loaded correctly but as my programming skills are lacking I am unsure which way to go. Thanks for all the information contained in the blog as I would still be struggling with the various bits.
Regards Dave
Hi Dave. This was an error in the software and is fixed in commit 608f585 on GitHub. Good luck with your project! Haydn