Wearable Tech

Enter Your Electronics & Design Project for a chance to win a $100 Shopping Cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

Intro

I've recently read the book Why We Sleep by Matthew Walker. It covers many aspects of why sleep is very important for our health and factors related to its quality. Reduced amount of sleep can significantly degrade health, memory, productivity, athletic performance and quality of life. Exposure to light and specifically to blue spectrum of the light before the sleep is reducing amount of sleep hormone (melatonin) and making harder to fell asleep and as result can reduce time we have for sleep.

 

I wanted to start measuring my exposure to blue light over the day. Over holiday season I had some extra time, so I decided to build a wearable device that can log sensor data, monitor blue light exposure and alert me if its level too high and potentially can prevent normal sleep, especially at time close to sleep.

 

I'd like to share my journey in this blog post. I hope you find this helpful.

 

PocketBeagle

I've published my idea at element14 Wearable Tech contest page. Shortly I've received a nice holiday card from element14 team, PocketBeagle, element14 t-shirt and other goodies.

PocketBeagle and other goodies from element14

I've done a mobile robot project in the past on BeagleBone Black (BBB) as part of Control of Mobile Robots course by Georgia Tech and Coursera. It was quite a challenging, but at the same time rewarding experience So I was hopping to leverage some Python and BeagleBone skills I've developed at that time.

 

BBB vs. PocketBeagle

Here are some key differences between BBB and PocketBeagle in context of my project:

  • PocketBeagle is much smaller (35mm x 56mm x 5mm) then BBB (55mm x 86mm) so it is more portable and wearable.
  • PocketBeagle doesn't have eMMC so it needs a microSD card to support OS. The recommended OS is Debian and its latest release image can fit on 4GB card.
  • PocketBeagle comes with USB mini port, but it doesn't have expansion headers, and DC plug. I realized that it requires some soldering to connect sensor and battery.
  • There are a lot of projects and code samples available for BBB. Most of them can be used with PocketBeagle. But PocketBeagle has a bit different pin-out compare to BBB. So some adjustments of code and connectivity is required.

PocketBeagle Setup

The PocketBeagle  documentation is quite good and easy to follow. So I was able to setup SD card and start using provided web examples quite fast.

As I decided to use Python as my development language I needed to ssh to the device. PocketBeagle IP address for on Windows is 192.168.7.2. The user id: debian and password: temppwd . I've required a root access to add a user to run my code. I've run

sudo su

to get root authorities. The root user has the same default password - temppwd .

 

 

Sleep Research

 

If you are interested in the modern sleep research I'll highly recommend to read Matthew Walker.book. You can as well start by watchin his talk at Google https://www.youtube.com/watch?v=aXflBZXAucQ

One of his points is the effect of the blue light on sleep. Melatonin helps trigger sleep in humans..Blue light has a very strong on melatonin inhibition.

Blue light effect on melatonin

 

 

Design

I was looking for something to embed light sensor, so it can be wearable, but not too big and not look super nerdy like Google Glass. Pen seems to be a good option.It can host a photoresistor and a LED indicator.USB battery is quite big compare to everything else. So it is a good candidate to be replaced with something smaller.

 

PocketBeagle with light sensor design

assembled light sensor and LED

Assembled sensor with LED inside a pen.

PocketBeagle with blue light sensor in my pocket

Assembled sensor,  PocketBeagle and battery in my from pocket

Assembled sensor - view from top with blue light filter.

Assembled components.

Assembled PocketBeagle Board view from the top.

Assembled PocketBeagle Board view from the bottom.

There is less light in horizontal position of the sensor. As result LED is off. When I turn it into vertical position, there is more light (including blue light) and LED gets switched on.

Fritzing PocketBone schema

Fritzing PocketBeagle schema

 

Components

Electronic Components

PocketBeagle Board

LED

Photoresistor

Resistors - 1K, 10K

USB battery

USB cable

Wires

Connector

Header extensions

 

Other materials

 

Scotch tape

Electric tape

Pen

Heat Shrink

Silicone earbuds tip

 

Sensor Calibration

I've a NXP Rapid IoT node. It has several sensors including light sensor, During the test I've set both devices next to a light source (Varilux Comfort Lens VT15 - CFML36VLX - 2500 lumen) using my soldering station and applied the same blue filter for both of them. I've oriented NXP device to represent a head and my wearable sensor simulated position in the front pocket.

CFML36VLX lamp light is evenly distributed according to its manufacturer. So blue light is taking ~1/3 of visible light spectrum.

calibration of light sensor.

My NXP device measured 354 lx At the same time I've got the following GPIO readings from PocketBeagle:

0.0678876712918
0.0686202719808
0.0688644722104
0.0693528726697
0.0691086724401

 

Code

import Adafruit_BBIO.ADC as ADC
import Adafruit_BBIO.GPIO as GPIO

import time
import logging

logging.basicConfig(format='%(asctime)s %(message)s', filename='blue-light.log', level=logging.DEBUG)

ADC.setup()
GPIO.setup("P2_22", GPIO.OUT) #Red LED

#loop forever
while True:

    value = ADC.read("P9_39")
    logging.info(value)

    if value>0.06:
        GPIO.output("P2_22", GPIO.HIGH) #Red LED
        time.sleep(5.0) #LED on for 5 seconds
        GPIO.output("P2_22", GPIO.LOW) #Red LED
    else:
        time.sleep(5.0) #loop every 5 seconds

Please note, that you need to have an elevated permissions on PocketBeagle to run this code thanks to GPIO setup call..

 

Output is saved in a log file:

2019-01-14 00:09:24,274 0.0388278402388
2019-01-14 00:09:29,281 0.0481074489653
2019-01-14 00:09:34,292 0.0148962149397
2019-01-14 00:09:39,302 0.279120892286
2019-01-14 00:09:44,313 0.243956044316
2019-01-14 00:09:49,322 0.0451770462096
2019-01-14 00:09:54,330 0.246398046613
2019-01-14 00:09:59,339 0.0158730167896
2019-01-14 00:10:04,348 0.24859584868
2019-01-14 00:10:09,358 0.095970697701
2019-01-14 00:10:14,367 0.0307692307979
2019-01-14 00:10:19,376 0.030036630109
2019-01-14 00:10:24,384 0.0280830282718

Summary

It is a small fun project to have a better sleep. There is a lot of room for improvements - make it smaller, replace static with dynamic alerts depending on how much time left before sleep, more precise calibration of sensor, automated data upload when network connection is available.

PocketBeagle is a very tiny, but impressive Linux board.I still like to explore a lot of its capabilities, like PRU, power management.

I wish PocketBeagle came with soldered extension headers and a battery.

I hope PocketBeagle in the future will have some king of wireless network connectivity like BLE.

 

References

Why We Sleep by Matthew Walker.

Getting Started – USB Network Adapter on the Beaglebone

Automatically Setting the Beaglebone Black Time Using NTP

https://beagleboard.org/pocket