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 

 


Adafruit publishes a wide range of writing and video content, including interviews and reporting on the maker market and the wider technology world. Our standards page is intended as a guide to best practices that Adafruit uses, as well as an outline of the ethical standards Adafruit aspires to. While Adafruit is not an independent journalistic institution, Adafruit strives to be a fair, informative, and positive voice within the community – check it out here: adafruit.com/editorialstandards

Join Adafruit on Mastodon

Adafruit is on Mastodon, join in! adafruit.com/mastodon

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, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, 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.

Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.

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

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

CircuitPython – The easiest way to program microcontrollers – CircuitPython.org


Maker Business — “Packaging” chips in the US

Wearables — Enclosures help fight body humidity in costumes

Electronics — Transformers: More than meets the eye!

Python for Microcontrollers — Python on Microcontrollers Newsletter: Silicon Labs introduces CircuitPython support, and more! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi

Adafruit IoT Monthly — Guardian Robot, Weather-wise Umbrella Stand, and more!

Microsoft MakeCode — MakeCode Thank You!

EYE on NPI — Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey

New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — #NewProds 7/19/23 Feat. Adafruit Matrix Portal S3 CircuitPython Powered Internet Display!

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.

Sorry, the comment form is closed at this time.