Skip to content

Take readings from a BME680 sensor or Sense-HAT on a Pi or Pi Zero, store with InfluxDB and view with Grafana

License

Notifications You must be signed in to change notification settings

vschinazi/balena-sense

 
 

Repository files navigation

balena-sense

A Raspberry Pi balenaCloud starter project taking readings from a either a Bosch BME680 sensor, a Sense-HAT, or a 1-wire temperature sensor (such as a Dallas DS18B20), storing using InfluxDB and reporting using Grafana.

The Bosch BME680 is recommended as it includes sensors for temperature, humidity, pressure and gas content and is available on a breakout board from a few different places for around $10-$20.

As an alternative, if you have one already, you can use the Raspberry Pi Sense-HAT. This however does not include a sensor for gas content and so if you use this the air quality readout is derived from humidity and temperature target values.

If you have neither a BME680 nor a Sense-HAT, or if you only need temperature readings, you can use a so-called 1-wire sensor, such as the DS18B20. Air quality metrics are not available with these sensors.

The sensor provides a reading for Indoor Air Quality (IAQ) which is a range from 0 to 500 where lower is better, and displays it with a web interface provided by Grafana.

Hardware required

Here’s the shopping list for this project. Depending if you’d like to crack out the soldering iron or not will dictate what sensor board you can use; some are plug and play, some require a little soldering.

  • Raspberry Pi 2Bv1.2/3B/3B+/3A+/Zero
  • 8GB (or larger) Micro-SD Card (we recommend Sandisk Extreme Pro SD cards)
  • Power supply & micro-USB cable
  • Bosch BME680 sensor with breakout board (see below for places to find one) or...
  • Optional: Sense HAT (optional replacement for the BME680, but does not include an air quality sensor)
  • Optional: 1-wire temperature sensor (temperature only)
  • Optional: Male-to-female Dupont cables (optional)

You can get hold of the Bosch BME680 sensor on a breakout board from a variety of vendors too, all at varying costs. If you’d like to do everything without a soldering iron, take a look at Pimoroni, who offer a BME680 breakout board compatible with their breakout garden HAT so that everything plugs together with no soldering required. If you don't want to do any soldering and are happy to sacrifice the air quality reading, you can also use the Sense HAT, with the added bonus that you'll get a smiley face showing on the LED matrix! However, if you're buying hardware specifically for this project, get one of the BME680 options below, don't buy a Sense-HAT just for this! If you only need temperature readings, you can find DS18B20 1-wire sensors readily available on eBay (and much cheaper than the BME680 or Sense-HAT), with minimal soldering required.

If you’re happy to do a little soldering, that opens up a few more options:

Software required

We’ve set up this project which contains all of the software, configuration and code you’ll need to start taking readings straight away. We’re going to deploy this project on balenaCloud using a free account to push the project and all the software to your Raspberry Pi as well as to provide remote access. Therefore, you’ll need:

Configuration

Sensor offsets

If required, this project supports offsetting of the measured values before they are recorded in the database.

To offset temperature, add a balenaCloud environment variable called BALENASENSE_TEMP_OFFSET, and add an offset in degrees C.

To offset humidity, add a balenaCloud environment variable called BALENASENSE_HUM_OFFSET and add a value in % RH.

To adjust the pressure sensor and compensate for altitude, add a balenaCloud environment variable called BALENASENSE_ALTITUDE and set it to your altitude above sea level in meters.

Using 1-wire sensors

To use 1-wire sensors such as the DS18B20 on the Raspberry Pi, you'll need to enable the 1-wire GPIO interface by adding the w1-gpio device tree overlay. Information on the 1-wire interface is available at pinout.xyz, but in the case of BalenaOS, you can do this easily in the Device Configuration section of the BalenaCloud dashboard by adding a custom configuration variable called RESIN_HOST_CONFIG_dtoverlay, with value w1-gpio.

More information about device tree overlays and other advanced boot settings for the Raspberry Pi is available in the BalenaOS docs and BalenaCloud management reference section.

Hardware setup

The Pi Hut guide to using a DS18B20 sensor with a Raspberry Pi shows how to wire these sensors up. Don't forget you'll need a pullup resistor between the Vin and data lines.

Multiple 1-wire sensors on one device

1-wire devices each have a unique ID; if you have more than one sensor attached to your Raspberry Pi, it is possible to select which one to use by setting the BALENASENSE_1WIRE_SENSOR_ID device variable in BalenaCloud. If no ID is given, the first sensor found will be used.

For more information about how to find the ID for 1-wire devices, the Pi Hut guide referenced above, or this Raspberry Pi tutorial are useful.

Data outputs

Versions of balenaSense after v1.5 introduce Telegraf to capture the data from the sensor which permits the feed of data to other sources in addition to the internal InfluxDB instance.

Feeding to InfluxDB cloud 2.0

Configure the following environment variables within the balenaCloud dashboard to enable the feed to the InfluxDB Cloud 2.0 service:

  • INFLUX_BUCKET - the name of the bucket you created
  • INFLUX_ORG - your login email address used for InfluxDB cloud
  • INFLUX_TOKEN - the read/write token for your bucket
Feeding to an external InfluxDB instance

Configure the following environment variables within the balenaCloud dashboard to enable a feed to an external InfluxDB instance:

  • INFLUXDB_EXTERNAL_URL - the HTTP URL to your InfluxDB instance
  • INFLUXDB_EXTERNAL_USERNAME - the username for authentication to your InfluxDB instance
  • INFLUXDB_EXTERNAL_PASSWORD - the password for authentication to your InfluxDB instance
Multiple sensors

If you're feeding to one of the above services and have multiple sensors, you can add the BALENASENSE_ID variable to each of your devices. This will then be passed to the output database along with the measurements, allowing you to filter and plot metrics from each device individually.

Setup guides

A full guide covering the initial setup of this project is available on our blog.

We published an additional blog covering the setup of a fleet of balenaSense devices to feed to a central database on our blog here.

About

Take readings from a BME680 sensor or Sense-HAT on a Pi or Pi Zero, store with InfluxDB and view with Grafana

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 82.9%
  • Shell 17.1%