Developing a data-logging sensor system using Raspberry Pi

Assembled Sensor System

One objective of the BLUEsat High-Altitude Ballooning Mission is to acquire data about flight dynamics and atmospheric characteristics. The payload includes an assortment of sensors connected to a Raspberry Pi, which logs the sensor outputs to an SD card to collect the required data during flight.

Assembled High Altitude Balloon Sensor System
Assembled Sensor System

The code was written in Python and the necessary modules had to be installed to interface the code with the sensors, which will be covered here for each sensor. Please refer to our GitHub repository for all our code related to this project.

Getting Started

First, purchase a good-quality SD card from a reputable seller. I prefer to use a 32GB card so there is extra room for future uses, but if you are using it to record your flight with a Pi Camera, then I would recommend a 64GB card due to the storage requirements of the HD video and images.

This tutorial assumes you are going to be using the Raspbian Stretch OS on your SD card. Download the latest version from the Raspberry Pi website here, and extract the image file from within.

Download Etcher from here. Connect your SD card to your computer, select the image file that you extracted above and select the drive as your SD card. Hit “Flash!” and allow it to complete the flashing and validating process. Alternatively, you can use Win32 Disk Imager.

Now insert your SD card into your Pi and power it up.

Before starting work with your Pi, make sure your software is up to date. First connect your Pi to the internet (if your model doesn’t have WIFI, you can use a USB WIFI dongle or ethernet).

Open a terminal window and enter:
sudo get-apt update

sudo get-apt upgrade

Both of these commands may take a while since they download/install files (make sure your internet stays connected).

Next we will install a python module to communicate over I2C.

sudo pip install smbus2

The next command will install I2C tools.

sudo apt-get install i2c-tools

Next enable I2C on the Pi:

sudo raspi-config

Look for I2C under Interfaces, enable and reboot when prompted.

The following command will show you the hexadecimal addresses of all connected I2C devices. This will be useful in later stages after wiring up I2C sensors.

sudo i2cdetect -y 1


I will now detail the setup process for each sensor.


The DHT22 is a combined temperature and humidity sensor. This module by DFRobot has all required resistors already attached and a removable plug for easy connection, and will be mounted externally on our payload.

DHT22 Humidity & Temperature Sensor module from DFRobot
DHT22 module from DFRobot

You will need to download the following python class to interface with the sensor, available here. It is also included in our code repository named “” under the DHT22 directory.

The PIGPIO daemon must be running for your scripts to work. Start it by typing the following into a terminal:

sudo pigpiod


The BMP280 is a precision barometric pressure sensor with ±1 hPa absolute accuracy. The breakout board offers both I2C and SPI digital communication interfaces.

BMP280 Temprature Sensor Breakout Board
BMP280 breakout board

First install a python library to use the sensor. Download/copy this file to your Pi, available here.

Then open a terminal and navigate to the folder in which the file is saved. Run the following command and wait until install completes:

sudo pip install RPi.bme280-0.1.3.tar.gz


The MPU9250 is a 9-axis motion tracker: Gyroscope + Accelorometer + Compass. We used a GY-91 module, which combines the BMP280 and MPU9250 sensors into a single board.

GY-91 breakout board containing both BMP280 and MPU9250 sensors
GY-91 breakout board containing both BMP280 and MPU9250 sensors

First install the MPU9250 python library. If connected to the internet, run this command:

sudo pip install FaBo9Axis_MPU9250

If the Pi has no internet, download this repository as a ZIP file and copy over to the Pi. Then navigate to the folder it is saved in within a terminal and run:

sudo pip install

You can check which python modules are installed by running:
pip list

PT100 RTD Temperature Sensor with MAX31865 Amplifier Board

The PT100 sensor is a platinum “resistance temperature detector” (RTD). A piece of platinum in the probe changes resistance according to the temperature, and has a resistance of 100 ohms at 0 degrees Celsius (hence the name ‘PT100’). This resistance is amplified and converted to a digital signal by the MAX31865 board, which allows SPI connection with the Pi. The probe was mounted outside our enclosure to measure external temperature.

A PT100 connected to a MAX31865 on a bread board
PT100 connected to the MAX31865 board

Refer to the following document for wiring instructions, available here. Make sure you carefully cut the appropriate trace on your board, using a blade or box cutter of some kind, and short the respective pads as instructed by the guide.

Wiring diagram of the MAX31865 connecting to the raspberry pi. Left is MAX31865 right is Raspberry Pi. Wires are: VIN to 5V, GND to GND, CLK to SCLK, SDO to MISO, SDI to MOSI, CS to CEO.
Wiring the MAX31865 to the Raspberry Pi

The original python module to interface with the sensor can be found here, but it won’t work since some code needs to be added/changed. A working version can be found in our repository linked at the start, named “” within the MAX31865 directory.

Ensure that your logging script will be in the same folder as this python module to read the digital output of the MAX31865.

Putting it all together

The in-flight power source for our Pi is a 5000mAh USB power bank, and the various boards were arranged onto a Perma-Proto HAT for a neat final assembly.

Sensor boards mounted on the Perma-Proto HAT
Sensor boards mounted on the Perma-Proto HAT

You will also see some bash scripts in our code repository which automate various processes, such as starting all logging scripts together, removing existing CSV files or killing all script processes. You can experiment by creating your own bash scripts that do cool things. You need to give these files permission to execute by using the following command from the command line:

chmod +x

Then run it using this:


Also, it is simple to join multiple CSV files using this command (order of filenames is important as they will be joined in that order):

cat file1.csv file2.csv > combined.csv

Or you can combine all CSV files in the folder using:

cat *.csv > combined.csv

Concluding Remarks

I hope this tutorial has been useful for you. Whilst you may use our code, you are encouraged to develop your own scripts to improve your learning experience. If you intend to perform multiple functions using your on-board computer (e.g. sensor logging, photography/recording), then I recommend using separate hardware to implement these functions for greater reliability in the event of system failure during flight. Furthermore, you may wish to add a DS18B20 digital temperature sensor to measure internal temperature, which was not covered in this tutorial. You may also want to script automated logging upon startup of the pi, but further functionality will be left to the imagination and experimentation of the reader.

For any technical inquiries, you can contact us at:

Leave a Reply