BME680 and RainbowHat


#1

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
RainbowHat
The original BlackHat Hack3r

Ideas:

  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)


#2

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 sensor.data.pressure. I tried to do something similar with the sense hat but couldn’t get it to work.

Blockquote
print(“Polling:”)
try:
while True:
if sensor.get_sensor_data():

        output = "{0:.2f} C,{1:.2f} hPa,{2:.3f} %RH".format(sensor.data.temperature, sensor.data.pressure+16, sensor.data.humidity)

        print(output)

#3

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.


#4

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

import time

import rainbowhat

print("""
rainbowhat: clock.py
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
rainbowhat.display.print_number_str(str_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))

rainbowhat.display.show()

time.sleep(0.1)


#5

I’ve now combined my clock.py script with the rainbowhat touch.py script.

import time

import signal

import rainbowhat

def display_message(message):
rainbowhat.display.print_str(message)
rainbowhat.display.show()

@rainbowhat.touch.A.press()
def touch_a(channel):
display_message(“AHOY”)
rainbowhat.lights.rgb(1,0,0)

@rainbowhat.touch.B.press()
def touch_b(channel):
display_message(“YARR”)
rainbowhat.lights.rgb(0,1,0)

@rainbowhat.touch.C.press()
def touch_c(channel):
display_message(“GROG”)
rainbowhat.lights.rgb(0,0,1)

@rainbowhat.touch.release()
def release(channel):
time.sleep(5)
rainbowhat.lights.rgb(0,0,0)

while True:
str_time = time.strftime("%H%M")
rainbowhat.display.print_number_str(str_time)
rainbowhat.display.set_decimal(1, int(time.time() % 2))
rainbowhat.display.show()
time.sleep(0.1)

signal.pause()

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?


#6

I’ve also added (and altered) the Blinkt larson.py to my clock.py 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

rainbowhat.rainbow.set_clear_on_exit()

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)
rainbowhat.rainbow.show()

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

# Display the time
rainbowhat.display.print_number_str(str_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))

rainbowhat.display.show()

time.sleep(0.1)

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?


#7

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.


#8

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).


#9

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.


#10

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.


#11

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.