Raspberry Pi Data Logging Sensors

Having pursued a career in data and analytics, I’ve been thinking recently that it would be fun to take on some kind of data logging project at home. In light of that, I’ve been looking at a few sensors available for the Raspberry Pi that I could use.


Probably one of the most straight forward measurements would be temperature. With just a temperature sensor and the right resistor, the Pi can measure temperature and capture it through the terminal window. With that possibility, it is then very straight forward to log it in an ASCII file, or even drop it into a SQL database. Using a python module such as matplotlib the system could create a constantly updating graph that could be shared to a web server, having a very straight forward sensor, the results accessible via a browser.

The Sense Hat

A more refined piece of hardware already exists, and this is the Sense HAT. If I understand this rightly, the sense hat sits on the Raspberry Pi board directly over the GPIO pins. As well as a temperature sensor, it also senses air pressure and humidity, and it even has a built-in accelerometer. It looks like a very capable board for a fantastic price. It was also used recently for the Astro Pi project by astronaut Tim Peake. It looks like a very straight forward, easy to set up means for learning data logging.

Weather and Air Quality

I also learned that weather is an interesting option for Raspberry Pi data logging. Recently, a set of schools were distributed with Pi based weather monitoring kits. Unfortunately these never made general production, however there are several guides available for sourcing your own components and making your own.

Looking at the weather stations got me looking at something I’m more interested in: air quality. In recent years I have thought more and more about air quality. In 2013 I spent Christmas in Salt Lake City, Utah. While I was there, I saw something I’d never seen before: visible smog. I would say Utah is no more or less car loving than the rest of the USA, but a few geographical features of the landscape make it prone to this inversion. The area around SLC is in the Salt Lake basin. It is surrounded by mountains and little or no weather, so the pollution just gathers in the bottom of the valley until a weather front blows it away. Anyway, I digress. I never realised how real it could be.

Now, I live in Leeds which very seldom has smog, if ever. Even so, British cities have been criticized for their poor air quality recently, so it would be interesting to measure air quality around here and get some of my own statistics on what’s going on.

rsz_sensly_hatThere looks to be a few sensors available. Most interestingly is the Sensly HAT, which senses particulate matter, carbon monoxide, nitrogen oxides and the other poisonous gasses in the air. It’s still in development with a hopeful release date of September 2016 and is being developed by Altitude Technology with the support of a number of organisations. I like the look of this product; it carries the backing of the University of the West of England so it should be well refined and produce some good data. I’ll be interested to keep and eye on its development.

There’s a few more obscure sensors already available for the different measures, such as the SEEED STUDIO 101020078 Grove Air Quality sensor. These look a little trickier to work with, and although I gather they could work, an electronics novice like me might struggle.

So there we have it, a set of Raspberry Pi sensors measuring a variety of interesting constructs. I particularly like the Sensly HAT and I hope it gets into production soon. It would be most excellent to have a crowd sourced air quality measuring scheme to support air quality research. It would also be an awesome DIY data logging/analytics project too.

Raspberry Pi meets Cognitive Neuroscience

Can the Raspberri Pi be used to process 4d neuroimaging data?

Can the Raspberri Pi be used to process 4d neuroimaging data?

When I started my masters degree, I didn’t entirely know what I was taking on. I chose to study cognitive neuroscience because I knew this was an area which presently receives a lot of funding for PhD research, and also because it seemed like a robust, scientific approach to psychology. After a few short months I have come to discover that research in this area is something that I really enjoy, and that is largely down to the opportunities to program and develop computerized research tools.

At the same time, the Raspberry Pi Foundation have announced and launched the new Raspberry Pi 2: a credit card sized motherboard which can be run as a standalone personal computer. I’m not going to go in to all the ins and outs of the Raspberry Pi (or Pi, for short), you can find more about it by visiting their website at www.raspberrypi.org. Instead, I want to talk about what it brings to the study of psychology.

Anybody who has studied psychology as a science will know that a lot of research is made up from undergraduate students sitting in dark rooms performing mundane tasks while their reaction times were being measured. This has been terrific for the creators of Matlab, whose IDE has facilitated many a psychology-button-pressing extravaganza. Even so, there is a new kid on the block who is gradually gathering momentum, and that is python.

One of the modules we undertook this spring semester was programming in python, something I hadn’t done before. I was keen to do at least some of this on the Pi, so as to justify my impulsive buying of it. My lecturer found kind of cute (that would be “cute”, except that he didn’t say it aloud). I persisted non the less, until I found that at least for graphics the Pi weren’t altogether compatible with the PsychoPy module we were using. Unfortunately it does not support Open GL graphics, so it actually struggles with button pressing experiments. But it was a start, it wet my appetite, and it was fun.

The real fun has commenced as I’ve begun my dissertation project. We’re doing some work on spatial cognition (how space is represented in the brain) using functional magnetic resonance imaging (fMRI), and part of this involves calculating different test statistics on 3d data on a voxel by voxel basis (voxel = volumetric pixel). There is lots of python modules optimized for flattening, analyzing and reassembling these datasets and we’re using them to build novel analyses which haven’t been done before. On this frontier of neuroimaging research, the raspberry pi stands gallant as my building platform and testing station to produce these scripts.

I’ve been using the module ‘minepy‘ to calculate the Maximal Information Coefficient (MIC) for each voxel in a set of datasets. The modules install seamlessly on the pi from the different repositories, and scripts can be written elegantly through the ‘spyder‘ IDE. I’m most excited most of all about the sheer size of the data we are working with. Each dataset is 64x64x26 voxels, which means 106496 calculations. On the Pi, each one takes about a second, and (when I close the GUI) all in all it takes about 2 hours. For me to run this on all 48 of our scans, that would take about 4 days. For processing the whole lot, fortunately we can pass our script to the cluster computer at York, which (assuming it is coded correctly) should polish it all up in around 16 hours.

It looks like something out of a movie, but its real!

It looks like something out of a movie, but its real!

What I really like about this is how real it all is. I’ve taken on many little projects here and there over my years, but none of them have ever really meant anything. Sure, I learned a lot, but I wanted to put it into action. Here, when those lines of text fly up my screen for 2 hours, I look forward to the output for reasons more than just knowing it worked. It also gives me the opportunity to work on my projects at home using a linux software environment, which great since Python runs natively in Linux.

This also ticks another box for the raspberry pi foundation. Universities and hospitals around the world have powerful workstations and supercomputers which they use to process neuroimaging data. That is very sensible, considering the sheer volumes they work with. But can it also be done on a £25 printed circuit board in Billy-whizz’s basement? Yes… It can!