The software for this project is written in CircuitPython so it's easy to run and modify, just write the code straight to the board's USB drive!  If you're new to CircuitPython and Gemma M0 first check out the Gemma M0 CircuitPython guide pages.  These will explain what CircuitPython is and how to load it onto your Gemma M0 board.

Before you continue make sure your Gemma M0 is running the latest version of CircuitPython by updating its UF2 firmware.  Also be sure you can see the board's CIRCUITPY drive when you connect it to your computer with a USB cable.  Once you see the CIRCUITPY drive you're all set and ready to load the project code.

Now you need to install two dependencies from the CircuitPython bundle.  Like the bundle install page mentions for non-express boards like Gemma M0 this means you have to download the bundle zip file, open it on your computer, and copy the following files and folders to your board's CIRCUITPY drive:

  • adafruit_dotstar.mpy
  • adafruit_fancyled

Be sure you've copied both these files and folders (and all the files inside the folders) to your CIRCUITPY drive before continuing!

Next download the file with the code for the cyber flower project by clicking the button below or going to its home on GitHub:

Copy this to your Gemma M0's CIRCUITPY drive.  Make sure to overwrite any that's already on the board!

At this point be sure your CIRCUITPY drive has the cyber flower, adafruit_dotstar.mpy, and adafruit_fancyled files and folder on it.  You can delete any other files and folders on the drive (boot_out.txt is created by the board with debug data, you can ignore it):

The flower code might start running as soon as you copy the file to your board.  However just to be sure you can eject the CIRCUITPY drive from your computer, then press the board's reset button and the flower code should start running.

When the flower code first starts it will wait 5 seconds and flash the Gemma M0's tiny red LED on and off.  This is a short delay that gives you time to stop touching the board and the D0 and ground wires.  For the capacitive touch sensing to work you want the board to be 'calibrated' with nothing touching it, so during the initial startup delay put the flower down so nothing is touching it.  Then after 5 seconds the red LED will stop flashing and the DotStar LED will turn on to animate different colors.  At this point the flower code is running--try picking up the flower or touching the D0 wire to see the heart beat animation!

Note that if the flower is only powered by a battery (i.e. not connected to your computer) you might need to touch both the ground wire and D0 wire to trigger the heart beat animation.  This is why assembling the flower with a bare / uninsulated wire connected to ground is best, it allows someone to touch the flower and simultaneously ground themselves and trigger the capacitive sensing.

Also be aware if you have trouble getting all the dependencies copied to your board and working, there's a variant that does not have any dependencies called  You can download and rename it to, then copy to your Gemma M0's CIRCUITPY drive.  There are no other dependencies needed to use this version of the code (but it's a little harder to read and follow compared to the main code above).

Modify The Flower Code

Out of the box the flower code should work great without any modifications.  However since it's all simple Python code you can easily change it with any text editor.  The code is written with a few variables at the top that you can change to modify how the flower works.  First make sure you're familiar with editing and running code on a CircuitPython board.

If you open the flower on the CIRCUITPY drive, notice these values at the top:

# Variables that control the code.  Try changing these to modify speed, color,
# etc.
START_DELAY = 5.0       # How many seconds to wait after power up before
                        # jumping into the animation and initializing the
                        # touch input.  This gives you time to take move your
                        # fingers off the flower so the capacitive touch
                        # sensing is better calibrated.  During the delay
                        # the small red LED on the board will flash.

TOUCH_PIN = board.D0    # The board pin to listen for touches and trigger the
                        # heart beat animation.  You can change this to any
                        # other pin like board.D2 or board.D1.  Make sure not
                        # to touch this pin as the board powers on or the
                        # capacitive sensing will get confused (just reset
                        # the board and try again).

BRIGHTNESS = 1.0        # The brightness of the colors.  Set this to a value
                        # anywhere within 0 and 1.0, where 1.0 is full bright.
                        # For example 0.5 would be half brightness.

RAINBOW_PERIOD_S = 18.0 # How many seconds it takes for the default rainbow
                        # cycle animation to perform a full cycle.  Increase
                        # this to slow down the animation or decrease to speed
                        # it up.

HEARTBEAT_BPM = 60.0    # Heartbeat animation beats per minute.  Increase to
                        # speed up the heartbeat, and decrease to slow down.

HEARTBEAT_HUE = 300.0   # The color hue to use when animating the heartbeat
                        # animation.  Pick a value in the range of 0 to 359
                        # degrees, see the hue spectrum here:

On the right you can see comments (text after a # character) which describe the values.  Try changing one of these, like the HEARTBEAT_HUE value at the bottom.  If you change HEARTBEAT_HUE from 300.0 to 180.0 it will change the color of the heart beat animation to a cyan/blue color.  Modify the value and save the file on your CIRCUITPY drive.  The board should see the changed code and start running it again (remember it has a 5 second startup delay where it blinks the red LED).  If you touch the D0 pad now the heart beat should be cyan/blue--cool!

Experiment with changing other values like HEARTBEAT_BPM to change how fast the heart beat animation runs, or RAINBOW_PERIOD_S to change how long it takes for the DotStar to cycle through a rainbow of colors.  Each time you change a value just save the on the board again and it should start running with the new code!

That's all there is to the cyber flower digital valentine project!

This guide was first published on Feb 05, 2018. It was last updated on Feb 05, 2018.

This page (Software) was last updated on May 12, 2021.

Text editor powered by tinymce.