BME680 and RainbowHat

My latest thing:
A Pi0W (with a right-angle female header)
BME680 Breakout
On/Off shim soldered in (talk about a pain to solder … had to use a file to remove excess solder before I could mount the Pi) with pins for an external button
The original BlackHat Hack3r


  1. Use the Rainbow Hat to display data from the BME680 (maybe just air quality).
  2. Use the 7 APA102 s to countdown the burn-in time for the BME680.
  3. Use the capacitive buttons in some sort of double press way (i.e if segment display shows temp then press a button once to show x, press again to go back to temp)

1 Like

This is my method of correcting the pressure measurement on the BME680. I checked the air pressure for my closest weather station and added the difference to I tried to do something similar with the sense hat but couldn’t get it to work.

while True:
if sensor.get_sensor_data():

        output = "{0:.2f} C,{1:.2f} hPa,{2:.3f} %RH".format(,,


Local pressure (from the web) is likely corrected for mean sea level pressure. That will cause a discrepancy in what you get depending on your altitude above sea level. I live along the cost and my house is about 100 feet above sea level. I don’t bother correcting, it’s close enough for what I use my weather clock for. Plus one of mine is portable so it’s altitude varies depending on where I take it.

I’ve just modified the 4letterPhat clock script fof use with the rainbowhat

import time

import rainbowhat

This example will display a simple HH/MM clock,
with a blinking decimal point to indicate seconds.
Press Ctrl+C to exit.

while True:

str_time = time.strftime("%H%M")

# Display the time

# Blink the middle decimal point
# int(time.time() % 2) will alternate 1 0 1 0
# which we can use to directly set the point
rainbowhat.display.set_decimal(1, int(time.time() % 2))


I’ve now combined my script with the rainbowhat script.

import time

import signal

import rainbowhat

def display_message(message):
def touch_a(channel):
def touch_b(channel):
def touch_c(channel):

def release(channel):

while True:
str_time = time.strftime(“%H%M”)
rainbowhat.display.set_decimal(1, int(time.time() % 2))


Unfortunately when I touch the pads the message just flashes for an instant before going back to the clock. The rainbow.lights.rgb work fine, staying lit for the required 5 seconds.

Any ideas?

I’ve also added (and altered) the Blinkt to my script so I can use the APA102s as a vitual pendulum (which is why I have #'d the flashing decimal point).

import math
import time
import rainbowhat


reds = [0, 0, 0, 0, 0, 3, 1, 10, 1, 3, 0, 0, 0, 0, 0]

start_time = time.time()

while True:
delta = (time.time() - start_time) * 8

# Sine wave, spends a little longer at min/max
# offset = int(round(((math.sin(delta) + 1) / 2) * 7))

# Triangle wave, a snappy ping-pong effect
offset = int(abs((delta % 16) - 8))

for i in range(rainbowhat.rainbow.NUM_PIXELS):
    rainbowhat.rainbow.set_pixel(i , reds[offset + i], 1, 1)

str_time = time.strftime("%H%M")

# Display the time

# Blink the middle decimal point
# int(time.time() % 2) will alternate 1 0 1 0
# which we can use to directly set the point
#rainbowhat.display.set_decimal(1, int(time.time() % 2))


Now for the observant of you if you look at my code and at the video you will notice that the brightest ‘red’ stops at LED number 7 (far right) but doesn’t stop at LED number 1 (far left). It does the same if I change two lines of code to this.

reds = [0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0]

    rainbowhat.rainbow.set_pixel(i , reds[offset + i], 0, 0)

Any ideas on how to stop the pendulum at LED 1?

I also tried to add a tick to the clock and this is the best I could come up with.

rainbowhat.buzzer.midi_note(2, 0.1)
rainbowhat.buzzer.note(1, 0.9)

It sort of works, but I still get a tone between ticks and sometimes I get a double tick. Maybe its a step too far.

I’ve just changed the ‘reds’ line to this:

reds = [0, 0, 0, 0, 0, 0, 10, 10, 0, 0, 0, 0, 0, 0, 0]

and it cures the LED 1 mystery (and it looks better).

Isn’t it a “1” time burn in for the BME680 Air Sense? Or does it do it every time you fire it up? The Air quality sensor is the only part of mine I’m not using. I have it disabled in my code.

For the gas sensor I think you have to ‘warm it up’ every time you use it.

This is a quote from the Adafruit site about their BME680 board:

We recommend that you run this sensor for 48 hours when you first receive it to “burn it in”, and then 30 minutes in the desired mode every time the sensor is in use. This is because the sensitivity levels of the sensor will change during early use, and the resistance will slowly rise over time as the MOX warms up to its baseline reading.

Ok, thats not going to work for me, think I’ll just leave it disabled. I would think thats going to cause my temp reading to read high while the heater is on? My portable weather clock is on and off several times a day, and switches form being run on battery to just on power supply.