Introduction: RuuviTag and PiZero W and Blinkt! a Bluetooth Beacon Based Thermometer

Picture of RuuviTag and PiZero W and Blinkt!    a Bluetooth Beacon Based Thermometer

This instructable describes an approach to read temperature and humidity data from a RuuviTag using Bluetooth with a Raspberry Pi Zero W and to display the values in binary numbers on a Pimoroni blinkt! pHAT.

Or to put it short: how to build a state of the art and a bit nerdy thermometer.

The RuuviTag is an open source sensor bluetooth beacon that comes with a temperature/humidity/pressure and accelation sensors, but may also act as a standard Eddystone™ / iBeacon proximity beacon. It was a very successfully Kickstarter project and I got mine a few weeks ago. There is a Github with python software to read the RuuviTag using a raspberry, and I have used one of their examples, with some additions.

The Raspberry Pi Zero W is the latest member of the RPi family, basically a Pi Zero with Bluetooth and WLAN added.

The blinkt! pHAT from Pimoroni is basically a strip of eight RBG LEDs configured as a HAT for the Raspberry Pi. It is very easy to use and comes with a python library.

The idea was to read the data from the RuuviTag and display it using the blinkt! HAT. The values are displayed as binary numbers using 7 of the LEDs, while the eight one is used to indicate if humidity or temperature (+/-/0) values are displayed.

Step 1: Setting Up the System

Setting up the system is easy:

- Switch on the RuuviTag (RuuviTag temperature sensor version) .

- Set up your RPi Zero W, RPi3, or any other RPi with bluetooth capacity added, following the instructions on www.raspberrypi.org.

- Place the blinkt! HAT on the RPi (while off).

- Install the blinkt! and RuuviTag software, as indicated on the corresponding GitHub pages.

- You now have to identify the MAC address of your RuuviTag

- copy the attached Python program, open it with IDLE for Python 3

- change the MAC address of the RuuviTag to yours, then save and run the program.


- feel free to modify and optimize the program.
The program comes as it is, to be used on your own risk, no liabilities are taken for any damages.

Step 2: The Device and the Program

Picture of The Device and the Program

As mentioned above, the idea was to construct a simple and inexpensive system to read data from the beacon and display numerical values on the blinkt! HAT, or a similar LED strip.

The range of values for temperature to be measured with a RPi based system will in most cases be somewhere between - 50°C and +80°C, for humidity between 0 and 100%. So a display that can give values from -100 to +100 will be sufficient for most applications. Decimal numbers smaller as 128 can be displayed as binary numbers with 7 bits (or LEDs). So the program takes the temperature and humidity values from the RuuviTag as "float" numbers and transforms them into binary numbers, which then are displayed on the blinkt!.

As a first step, the number is rounded, analysed if positive, negative or zero, and then transformed into a positive number using "abs". Then the decimal number is converted into a 7-digit binary number, basically a string of 0s and 1s, which gets analysed and displayed on the last 7 pixels of the blinkt!.

For temperature values the first pixel indicates if the value is positive (red), zero (magenta) or negative (blue). Displaying humidity values it is set to green. To simplify the discrimination between temperature and humidity values the binary pixels are set white for temperature and yellow for humidity. To enhance legibility of the binary numbers, "0" pixel are not turned completely off, but instead are set much weaker than in the "1" state. As blinkt! pixels are veery bright, you can set the general brightness changing the parameter "bright"

The program displays the values and parts of the process also on screen. In addition you will find several muted (#) print instructions. I left them in, as you may find them helpful to understand the process if unmuted.

The values might also be stored in a log file.

Step 3: Program Code

The code was a bit debuged and optimized. You may now find version 3 (20_03_2017).

' This program is intended to read the temperature, humidity and pressure values form a RuuviTag '
' and to display the temperature and humidity values as binary numbers on a Pimorini blinkt! HAT. ' '' ' It is based on the print_to_screen.py example from the ruuvitag library at github. ' ' Requires a Pi Zero W, Pi 3 or any other RPi equiped with bluetooth and all neccessary libraries installed.'

import time import os from datetime import datetime

from ruuvitag_sensor.ruuvi import RuuviTagSensor

from blinkt import *

def temp_blinkt(bt): # this routine takes the temperature value and displays it as a binary number on blinkt!

clear ()

# color and intensity of "1" pixels : bright white r1 = 64 g1 = 64 b1 = 64

#color and intensity of "0" pixels : dim white r0 = 3 g0 = 3 b0 = 3

# Round and convert into integer r = round (bt)

# vz represents algebraic sign for indicator pixel if (r>0): vz = 1 # positive elif (r<0): vz= 2 # negative else: vz= 0 # zero # print (vz)

# Set indicator pixel if (vz==1): set_pixel (0, 64, 0, 0) # red for positive values elif (vz==2): set_pixel (0, 0, 0, 64) # blue for negative values else: set_pixel (0, 64, 0, 64) # purple if zero

# transform to absolute, 7-digit binary number i = abs(r) #print (i)

b7 = '{:07b}'.format(i) # transforms a decimal number into a binary number with at least 7 digits, # filled left with 0s

print (bt, " °C" ) # print on screen print ("temperature as binary number: ", b7) print()

# Set pixels on blinkt!

# set binary number for h in range (0,7): f = (h+1) if (b7[h] == "1"): set_pixel (f, r1, g1, b1) # print ("bit ", h, " is 1, pixel ", f) else: set_pixel (f, r0, g0, b0)

show() # write to blinkt!

# end of temp_blinkt()

def hum_blinkt(bh): # this takes the humidity value and displays it as a binary number on blinkt!

clear()

# Set indicator pixel set_pixel (0, 0, 64, 0) # green for humidity

#set color and intensity of "1" pixels: yellow r1 = 64 g1 = 64 b1 = 0

#set color and intensity of "0" pixels : dim yellow r0 = 3 g0 = 3 b0 = 0

# Round and transform into integer r = round (bh)

# transform to an absolute, 7-digit binary number i = abs(r) #print (i)

# transforms a decimal number into a binary number with at least 7 digits, # filled left with 0s b7 = '{:07b}'.format(i)

print (bh, " %") print ("humidity as binary number: ", b7) print() # Set pixels on blinkt!

# set binary number to pixels for h in range (0,7): f = (h+1) if (b7[h] == "1"): set_pixel (f, r1, g1, b1) else: set_pixel (f, r0, g0, b0)

show()

# end of hum_blinkt()

# changing parameter "bright" allows to define brightness of the pixels, max =1 bright = (0.3) set_brightness(bright)

set_clear_on_exit()

mac = 'EC:6D:59:6D:01:1C' # Change to the mac-address of your ruuvitag

# Reading data from the RuuviTag

print('Starting')

sensor = RuuviTagSensor(mac)

while True: data = sensor.update() bt = data['temperature'] # get temperature bh = data['humidity'] # get humidity bp = data['pressure'] # get pressure

line_sen = str.format('Sensor - {0}', mac) line_tem = str.format('Temperature: {0} C', bt) line_hum = str.format('Humidity: {0} %', bh) line_pre = str.format('Pressure: {0}', bp)

print() # Clear screen and print sensor data to screen os.system('clear')

print(str(datetime.now())) print(line_sen) print(line_tem) print(line_hum) print(line_pre) print('\n\r.......\n')

# display temperature on blinkt! temp_blinkt (bt) # display temperature value on blinkt! time.sleep (9) # display temperature for 9 seconds

# display humidity on blinkt! hum_blinkt (bh) # display humidity value on blinkt!

print ('Press Ctrl+C to quit.\n') # Wait for a few seconds and start over again try: time.sleep(5) except KeyboardInterrupt: # When Ctrl+C is pressed execution of the while loop is stopped print('Exit') clear() show () break

Comments

About This Instructable

1,798views

11favorites

License:

Bio: I have a background in chemistry, molecular biology and immunology and I am working in the field of in vitro diagnostics and life sciences. I ... More »
More by Dr H:A DIY Six-Color Transmitted-Light SpectrophotometerThe Perfect Shade: an Simple Self-regulatory Optoelectronic Circuit An Adafruit Si7021, Raspberry Pi and Pimoroni Display-o-Tron HAT  Humidity and Temperature Measurement Device
Add instructable to: