0

Biohack: Circadian Pi Desk Light #CircuitPython #RPI #NeoPixels

Blue light in the morning and red light in the evening can help us adopt a more natural circadian rhythm. Blue light is stimulating and ideal to be exposed to early in the day while the removal of blue light allows melatonin production to ramp up so red light in the evening can help get us ready for bed. The Raspberry Pi is the perfect device to help with the timing and driving of long NeoPixel strips. In this post we will show how just a few wires, some code and a tiny bit of hardware we can have a light with some circadian awareness.

Parts


Wiring


We are limited to just a few pins on the Raspberry Pi to drive NeoPixel strips (D10, D12, D18 and D21). You can see the white wire is our control line (D18) and the black is our shared ground. The other red/black wire of the NeoPixel strips can go right into the marked +/- barrel jack terminal block. That is it. We are wired up.

Pi Setup


Make sure your Pi is running the latest version of Raspbian and has the following Adafruit blinka and neopixel libraries installed.

  1. Prerequisite Pi Setup
  2. Updates for an existing Pi
    1. sudo apt-get update
    2. sudo apt-get upgrade
  3. Library installation
    1. sudo pip3 install adafruit blinka
    2. sudo pip3 install adafruit-circuitpython-neopixel

Code


Go ahead and cut and paste this into your Raspberry Pi. Name the file Circadian_Pi.py. You can test and see if your hardware is working using these commands:

  • sudo python3 ./Circadian_Pi.py morning
  • sudo python3 ./Circadian_Pi.py night
  • sudo python3 ./Circadian_Pi.py off
import board
import neopixel
import sys

pi_pin = board.D18
numpix = 144
brightness = 1.0
pixels = neopixel.NeoPixel(pi_pin, numpix, brightness=brightness) # Raspberry Pi wiring!

# valid argument check and color assignment
# morning == blue
# night == red
# off == all LEDs off
if len(sys.argv) == 2:
    if sys.argv[1] == "morning" :
        color = (0, 0, 255)
    elif sys.argv[1] == "night" :
        color = (255, 0, 0)
    elif sys.argv[1] == "off" :
        color = (0, 0, 0)

    pixels.fill(color)

else:
    print("valid arguments are morning, night or off")

CRON


We can schedule our light to turn on the in the morning hours, off during most of the day and on again in the evening hours using the CRON system. This is one of the ways where using a Raspberry Pi is really powerful since it knows the correct time and can schedule jobs for us. The cron system has five fields of which we are just going to use the first two (minute and hours) which we want to the light to be turned on.

Use the following command and paste in this example crontab syntax.

  • sudo crontab -e

# 5am - 8am blue light mode [stimulate]

0 5 * * * python3 /home/pi/Circadian_Pi.py morning 

0 8 * * * python3 /home/pi/Circadian_Pi.py off 

# 6pm - 10pm red light mode [melatonin]

0 18 * * * python3 /home/pi/Circadian_Pi.py night 

0 22 * * * python3 /home/pi/Circadian_Pi.py off 

 


Please vote for Limor Fried (Ladyada) for Red Hat’s Women in Open Source Award
Our Ladyada (Limor Fried) was nominated for Red Hat’s Women in Open Source Award! Please vote for her! Visit: https://www.redhat.com/en/about/women-in-open-source

Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, or even use Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for MakeCode, CircuitPython, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.

Join 10,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython 2019!

Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more https://www.instagram.com/adafruit/


Maker Business — The strange world of low-margin online returns

Wearables — Liquid magic

Electronics — Diamonds may be forever… but components? Not so much.

Biohacking — Raspberry Pi Health Dashboard

Python for Microcontrollers — Python on hardware, a portal to a world of fun! #Python #Adafruit #CircuitPython @circuitpython @micropython @ThePSF @Adafruit

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



2 Comments

  1. I can see using the Pi Cobbler for complex circuits, and even simple ones if you design a lot of Pi connected circuits and/or simply have it lying around. But why would anyone want to spend seven or eight dollars for a something that’s already tested and running, and requires only two wires?

  2. Chris – You are correct that the cobbler is overkill for this circuit. However, it makes the pin locations easy to convey and allows for easy expandability. If you wanted to add a trimpot to control brightness and some buttons to switch into different modes it would be convenient to hook them up. Those who know they don’t need a cobbler can skip that component.


Leave a comment

Adafruit has a "be excellent to each other" comment policy. Help us keep the community here positive and helpful. Stick to the topic, be respectful of makers of all ages and skill levels. Be kind, and don't spam - Thank you!

Prove you are human by reading this resistor:

0Ω+/- 5%

0
0
1
2
3
4
5
6
7
8
9

0
0
1
2
3
4
5
6
7
8
9

0
0
1
2
3
4
5
6
7
8
9

5
5
10

Prove you are human by reading this resistor:


Match the sliders on the left to each color band on the resistor.

Click Here for a new resistor image.

New to electronics? Click here to learn how to read resistor values.

Or learn to read resistors by playing Mho's Resistance!