Maker.io main logo

LED Breath Stats Mask

2018-02-13 | By Adafruit Industries

License: See Original Project

Courtesy of Adafruit

Guide by Michael Sklar

Overview

mask%20that%20displays%20our%20breath%20attributes

Combining Adafruit’s CCS811 gas sensor with a Circuit Playground Express and two NeoPixel Sticks we can quickly put together a mask that displays our breath attributes. This setup will monitor temperature, carbon dioxide, and total volatile organic compounds. The sensor is easy to work with using its I2C interface and pre-calibrated ranges. A mask is an ideal wearable as it provides a place to house the electronics as well as an option for continuous monitoring as it is a hands-free device that could be adapted for exercise or sleep. The gas sensors TVOC monitoring can be used as an indicator of ketosis as it will detect acetone levels on the breath which is a by-product of producing ketones. CO2 levels can also be a helpful indicator of how much glucose is being burned versus fats.

Materials

Materials

We will be soldering the CCS811 gas sensor and NeoPixel RGBW Sticks to a quarter-sized perma protoboard and the Circuit Playground Express.

mask%20needs%20to%20have%20several%20small%20holes%20cut%20into%20it%20

The mask will need to have several small holes cut into it so we can run the wires for the Circuit Playground Express and NeoPixel Sticks. We will use ordinary nylon sewing string to adhere the components to the mask.

Circuit%20Playground%20Express%20on%20blank%20side%20of%20mask

I've placed the Circuit Playground Express on the blank side of the mask. The other side has a small plastic air filter so we will place a single NeoPixel Stick on that side.

Assembly

nibbling%20tool%20makes%20trimming%20down%20PCBs%20easy

This nickel-plated nibbling tool has been a staple in my lab for the last fifteen years. It makes easy work of trimming down PCBs and knocking off sharp corners. This quarter-sized perma-proto board can fit into the mask as is, but I split it in half to save space.

Nibble%2c%20nibble%2c%20nibble

Nibble, nibble, nibble.

Solder%202%26quot%3b%20leads%20to%20each%20of%20the%20NeoPixel%20stick

Solder 2" leads to each of the NeoPixel sticks. We only need to use the DIN, 5V, and GND.

start%20soldering%20wires%20to%20the%20perma-proto%20board

Once the electronics are attached to the outside of the mask via sewing through the mount holes and unused pins we can start soldering wires to the perma-proto board.

wiring%20diagram%20shows%20connections%20to%20put%20in%20place

This above wiring diagram shows which connections we need to put in place. Try and use 2" leads between components so it is to access the proto-board with a soldering iron.

Final%20hookup%20with%20all%20the%20components%20connected

Final hookup with all the components connected.

CircuitPython Code

CircuitPython%20Code

The Circuit Playground Express boards can run CircuitPython — a different approach to programming compared to Arduino sketches. In fact, CircuitPython comes factory pre-loaded on the Circuit Playground Express. If you’ve overwritten it with an Arduino sketch, or just want to learn the basics of setting up and using CircuitPython, this is explained in the Adafruit Circuit Playground Express Guide.

To use the code below, plug the Circuit Playground Express into USB…it should show up on your computer as a small flash drive…then edit the file “main.py” with your text editor of choice. Select and copy the code below and paste it into that file, entirely replacing its contents (don’t mix it in with lingering bits of old code). When you save the file, the code should start running almost immediately.

Copy Code
import time

import board
import busio
import adafruit_CCS811
import neopixel

# i2c interface for the gas sensor
i2c_bus = busio.I2C(board.SCL, board.SDA)
ccs = adafruit_CCS811.CCS811(i2c_bus)

# Three Different NeoPixel 8 LED Lengths for Output:
# 1 - Temperature - Circuit Playground Built-In LEDs
# 2 - Total Volatile Organic Compounds [strip]
# 3 - Co2 Output - NeoPixel [strip]
num_leds = 8
temperature_pix = neopixel.NeoPixel(board.NEOPIXEL, num_leds, brightness=.1)
tvoc_pix = neopixel.NeoPixel(board.A1, num_leds, bpp=4, brightness=.1)
co2_pix = neopixel.NeoPixel(board.A2, num_leds, bpp=4, brightness=.1)
led_draw = .05 # delay for LED pixel turn on/off

# wait for the sensor to be ready and calibrate the thermistor
while not ccs.data_ready:
pass
temp = ccs.temperature
ccs.temp_offset = temp - 25.0

# clear all LEDs for breathing effect
def clear_pix(delay):
for i in range(0, num_leds):
temperature_pix[i] = (0,0,0)
co2_pix[i] = (0,0,0,0)
tvoc_pix[i] = (0,0,0,0)
time.sleep(delay)

# Show Carbon Dioxide on a NeoPixel Strip
def co2_led_meter():
co2_floor = 400
co2_ceiling = 8192

# Map CO2 range to 8 LED NeoPixel Stick
co2_range = co2_ceiling - co2_floor
co2_led_steps = co2_range / num_leds
co2_leds = int( (ccs.eCO2 - co2_floor ) / co2_led_steps)

# Insert Colors
for i in range(0, (co2_leds - 1) ):
co2_pix[i] = (255,0,255,0)
time.sleep(led_draw)

# Show Total Volatile Organic Compounds on a NeoPixel Strip
def tvoc_led_meter():
tvoc_floor = 0
tvoc_ceiling = 1187

# Map CO2 range to 8 LED NeoPixel Stick
tvoc_range = tvoc_ceiling - tvoc_floor
tvoc_led_steps = tvoc_range / num_leds
tvoc_leds = int(ccs.TVOC / tvoc_led_steps)

# Insert Colors
for i in range(0, (tvoc_leds - 1) ):
tvoc_pix[i] = (0,0,255,0)
time.sleep(led_draw)

# Show Temperature on Circuit Playground built-in NeoPixels
def temp_led_meter():
temp_floor = 23
temp_ceiling = 36

# Map temperature range to 8 LEDs on Circuit Playground
temp_range = temp_ceiling - temp_floor
temp_led_steps = temp_range / num_leds
temp_leds = int( (ccs.temperature - temp_floor ) / temp_led_steps)

# Insert Colors
for i in range(0, (temp_leds - 1) ):
temperature_pix[i] = (255,255,0)
time.sleep(led_draw)

while True:
# print to console
# - co2
# - total voltatile organic compounds
# - temperature in celsius
print("CO2: ", ccs.eCO2, " TVOC:", ccs.TVOC, " temp:", ccs.temperature)

co2_led_meter()
tvoc_led_meter()
temp_led_meter()

time.sleep(.5)
clear_pix(led_draw)

Wear It

Wear%20it

The Circuit Playground Express will need to initially plugged in for 48 hours so that the CCS811 sensor can burn in. The spec sheet suggests an additional 20-minute warmup before each use.

connect%20Express%20micro%20USB%20to%20computer

If you wish to see the raw data, you can connect to the Circuit Playground Express micro USB connector to a computer and watch the console output. On Linux or OS/X the screen command the /dev/*modem* device is the easiest way.

Copy Code
$ ls /dev/tty.usbmodem*
/dev/tty.usbmodem1421
$ screen /dev/tty.usbmodem1421 115200

The above command will show the name of your Circuit Playground Express and connect you to the console on OS/X. You will probably need to adjust the usbmodem#### numbers to match your existing device.

制造商零件编号 3566
CCS811 AIR QUALITY SENSOR BREAKO
Adafruit Industries LLC
制造商零件编号 3333
CIRCUIT PLAYGROUND EXPRESS
Adafruit Industries LLC
制造商零件编号 2869
ADDRESS LED MODULE SERIAL RGBW
Adafruit Industries LLC
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum