# BME680 and RainbowHat

**URL:** <https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582>\
**Category:** Projects\
**Created:** [September 2, 2018, 12:56pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582 "2018-09-02T12:56:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [September 2, 2018, 12:56pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/1 "2018-09-02T12:56:16Z")

</div>

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)

 ![DSCF0308sm](https://us1.discourse-cdn.com/flex016/uploads/pimoroni/original/2X/0/0ce8eda014372eb559fc5af448cc7d046a2ab819.jpeg)

---

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [September 2, 2018, 1:10pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/2 "2018-09-02T13:10:07Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [September 2, 2018, 2:55pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/3 "2018-09-02T14:55:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [September 4, 2018, 3:19pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/4 "2018-09-04T15:19:52Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [September 5, 2018, 12:33pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/5 "2018-09-05T12:33:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [September 8, 2018, 10:05pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/6 "2018-09-08T22:05:13Z")

</div>

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

[![](https://us1.discourse-cdn.com/flex016/uploads/pimoroni/original/2X/b/bf81d1f1c3d2509fa397046ef7768c539fd390c8.jpeg "Rainbow Hat clock") ](https://www.youtube.com/watch?v=0qkER7dBjRI)

> 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?

---

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [September 8, 2018, 10:21pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/7 "2018-09-08T22:21:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [September 8, 2018, 10:40pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/8 "2018-09-08T22:40:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [September 9, 2018, 8:43am UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/9 "2018-09-09T08:43:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![The\_Handy\_Andy](https://avatars.discourse-cdn.com/v4/letter/t/b5ac83/32.png) [@The\_Handy\_Andy](https://forums.pimoroni.com/u/The_Handy_Andy)\
**Post date:** [September 9, 2018, 1:02pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/10 "2018-09-09T13:02:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [September 9, 2018, 2:25pm UTC](https://forums.pimoroni.com/t/bme680-and-rainbowhat/8582/11 "2018-09-09T14:25:33Z")

</div>

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.
