Introduction: HackerBox 0091: Fibonacci
Welcome to HackerBox 0091. Explore the beautiful mathematics of Fibonacci numbers, spirals, and sunflowers. Configure the Seeed Studio XIAO RP2040 microcontroller module for use with CircuitPython. Experiment with CircuitPython programming to implement NeoPixel animations and touch pad controls on the Raspberry Pi RP2040 microcontroller. Assemble the RGB LED Fibonacci Spiral Kit using 64 through-hole NeoPixel RGB LEDs. Practice a step-wise approach to PCB assembly using through-hole soldering. Consider modification of an animated LED module into a wearable badge. Assemble the Cyber Voice Recorder kit from Cyber City Circuits. Get inspired to (re)watch Darren Aronofsky's 1998 film Pi.
HackerBox is the original monthly subscription box for electronics, computer technology, and hacker culture. Each HackerBox is a discovery box, which means all members await and enjoy a new surprise each month. Tech, toys, knowledge, and fun. It's like having a hacker convention, your birthday, and the first day of school - every month - right in your mailbox.
There is a wealth of information for current and prospective members in the HackerBoxes FAQ. Almost all of the non-technical support emails that we receive are already answered there, so we'd really appreciate it if you can take a few minutes to read the FAQ.
Supplies
This Instructable contains information for getting started with HackerBox 0091. The full box contents are listed on the product page for HackerBox 0091 where the box is also available for purchase while supplies last. If you would like to automatically receive a HackerBox like this right in your mailbox each month, you can subscribe at HackerBoxes.com and join the party. Subscribers save at least $15 every month and get each new HackerBox shipped immediately off of the production line.
A soldering iron, solder, and basic assembly tools are generally needed to work on the monthly HackerBox. A computer for running software tools is also required. Have a look at the HackerBox Workshops for tools and supplies along with a wide array of introductory activities and experiments.
The most import thing you will need is a sense of adventure, hacker spirit, patience, and curiosity. Building and experimenting with electronics, while very rewarding, can be tricky, challenging, and even frustrating at times. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from this hobby. Take each step slowly, mind the details, and don't be afraid to ask for help.
WEAR SAFETY GLASSES WHEN SOLDERING, WHEN TRIMMING WIRE LEADS, OR WHEN CUTTING, DRILLING, ETC.
Step 1: Leonardo Fibonacci
Fibonacci aka Leonardo Bonacci was an Italian mathematician from the Republic of Pisa. He is considered to be one of the most talented mathematicians of the Middle Ages.
The Fibonacci Sequence of numbers is defined such that each number is the sum of the two preceding numbers. The sequence starts from 0 and 1 (or sometimes 1 and 1), thus the initial values in the sequence are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144...
From these code examples, it is easy to see why computer science students often encounter the Fibonacci Sequence in a programming course while studying the concept of recursion.
The Fibonacci spiral is an approximation of the golden spiral created by drawing circular arcs connecting the opposite corners of squares in the Fibonacci tiling. It starts with a rectangle partitioned into 2 squares. In each step, a square the length of the rectangle's longest side is added to the rectangle. The ratio between consecutive Fibonacci numbers approaches the golden ratio as the Fibonacci numbers approach infinity. Accordingly, the Fibonacci spiral grows increasingly similar to the golden spiral as more squares are added.
Biological manifestations of the Fibonacci Sequence appear in the branching in trees, phyllotaxy (the arrangement of leaves on a plant stem), the fruitlets of a pineapple, the flowering of artichoke, an uncurling fern, the petals of field daisies, and so forth. Kepler, of planetary mechanics fame, used the Fibonacci sequence to explain the pentagonal form of many flowers that relate to the golden ratio.
Parastichy is the spiral pattern of certain plant parts, such as areoles on cacti stems, florets in sunflower heads, and scales in pine cones. Parastichies are often expressed as fractions involving Fibonacci numbers, such as in this sunflower example from the National Museum of Mathematics.
Step 2: If We're Built From Spirals
... while living in a giant spiral, then everything we put our hands to is infused with the spiral."
Scientific American video: The Mind-Blowing Mathematics of Sunflowers
Numberphile video: Sunflowers and Fibonacci
Polyphonic video: The Fibonacci Sequence in Tool's Lateralus
Video: How Composers use Fibonacci Numbers and the Golden Ratio
Gödel, Escher, Bach: Book, MIT lecture videos
"It's fair to say I'm stepping out on a limb, but I am on the edge and that's where it happens." - Pi
Step 3: Seeed Studio XIAO RP2040
Perform the initial power up and programming tests in this step before soldering or otherwise connecting to the XIAO RP2040 Module.
The Seeed Studio XIAO RP2040 microcontroller module is compatible with the Raspberry Pi Pico ecosystem as they share the same RP2040 chip. It supports multiple languages including MicroPython, CircuitPython, C, and Arduino Wiring. It is a great tool for getting started with microcontroller hardware hacking.
Hello World
Power up the XIAO RP2040 by connecting it to your computer using a USB-C cable.
The tiny RGB LEDs (next to USB connector) will cycle and the NeoPixel (between the two buttons) will light up red, green, and then blue.
NeoPixels
Check out the Adafruit NeoPixel Überguide. Among many other DIY electronic goodies, Adafruit has a lot of great NeoPixel products.
CircuitPython
Download the latest stable release of the CircuitPython UF2 from this page.
There are installation instructions linked from there, but this is the crux:
- Hold the BOOT (B) button while plugging the XIAO into your computer
- A drive named "RP1-RP2" will appear on the computer
- Paste or drag the .uf2 file onto the RP1-RP2 drive
- Verify that the name of the drive changes to "CIRCUITPY"
- That drive should have a code.py file (or grab this one)
- The comments in code.py explain that two libraries are required
- They can be found here (be sure to match the version number)
- Put those two libraries into the folder CIRCUITPY/lib
- The NeoPixel should now blink RED
- Open code.py in an editor (consider installing Mu)
- Change pixels.fill((255, 0, 0)) to pixels.fill((0, 0, 255))
- Now the NeoPixel should be blinking BLUE
Step 4: RGB LED Fibonacci Spiral Kit
Sunflowers, Daisies, and More
Parts of certain flowers grow as a mesh of spirals that occur in Fibonacci numbers and take on the shape of Fermat spirals. In 1979, the Vogel model was proposed to locate nodes on the spirals by the polar coordinates:
- r = c * sqrt(n)
- θ = n * 137.508°
where n is the index number of the node, θ is the angle, r is the radius from the origin, and c is a constant scaling factor. The golden angle is given by 137.508° as approximated by ratios of Fibonacci numbers.
Design of the Fibonacci Spiral PCB
Locations for the 64 LEDs of the Fibonacci Spiral PCB are computed using the polar relationships above for n = 0...63. The values were computed in a spreadsheet. Prior to importing the coordinates to KiCad, the polar (r,θ) coordinates were translated to rectangular (x,y) coordinates, they were translated off of the origin to the center of the PCB layout, and they were scaled out just enough to keep the first two 5mm LEDs from overlapping. A real adventure in PCB geometry to be sure.
The process described resulted in a list of LED positions spiraling out from the center. To simplify layout of the PCB traces, the LEDs were renumbered to zig-zag from one side of the board to the other - from the side where the DIN (Data In) pin "enters" to the side where the DOUT (Data Out) pin "exits" the board.
The KiCad design files and the final Gerber files for the PCB can be found here.
RGB LED Fibonacci Spiral Kit
In addition to the exclusive PCB, the kit includes 64 addressable RGB LEDs and a set of five male header pins.
The LEDs (aka NeoPixels) are specifically 5mm round WS2812B LEDs with diffuse lenses. These are available in different sizes and different pin orderings. The PCB only supports the 5mm size with the pin order shown in the image.
For basic operation of the Spiral LED panel, only one set of five header pins is required. The pins should be placed at the header featuring the DIN (Data In) pin. The three remaining five pin headers are only used for mounting stability (for example, on the optional Badge PCB) or for chaining off of the DOUT (Data Out) pin.
Surface mount pads for 30 decoupling capacitors are included for completeness, but these have not been used in any of our testing and no problems have been encountered. The pads (C1...C30) can accommodate 0.1uF ceramic capacitors in SMD1210 size surface mount packages.
Step 5: Fibonacci Spiral LED Kit - Assembly
Start by loading this test program onto the XIAO by pasting it into code.py:
import board
import neopixel
num_pixels = 64
pixels = neopixel.NeoPixel(board.D10, num_pixels)
pixels.brightness = 0.2
while True:
pixels.fill((0, 0, 255))
As you might guess, this will turn 64 NeoPixels attached to I/O pin D10 all blue.
Next, unplug the XIAO and carefully solder at least the four header pins as shown in the illustration. Tacking the pins onto the top of the castellation pads as shown is not necessary, but it makes them a little easier to remove if you wish to later "surface mount" the XIAO module.
Solder five header pins to the Fibonacci Spiral PCB being sure to use the header location with the DIN (Data In) pin at the center. The long side of the header pins as well as the black plastic insulator should be placed onto the side of the PCB with the capacitor pads. The short side of the header pins should barely extend through to the side of the PCB with the thick white border around the outside edge.
Three jumper wires can be used to connect the XIAO to the Fibonacci Spiral PCB: 5V to V, GND to G, and D10 to DIN.
Carefully Install LEDs One at a Time
The PCB silkscreen has 64 small white circles marking the outline of each LED. The "flat side" orientation indicator is very hard to see and doesn't even correspond to the particular four-pin LEDs in the kit, so be sure instead to follow all of the component orientation notes provided here...
The LEDs mount such that the lens of each LED is on the side of the PCB with the thick white border around the outside edge and the pins are soldered on the side of the PCB with the capacitor pads.
For each LED, examine the length of the four leads and the location of the flat edge on the LED lens. Compare these to the pinout image for the LEDs to determine which pins are which.
The DIN pin of each LED goes in the square hole on the PCB which is also the hole closest to the five pin header with the DIN pin. The DOUT pin of each LED (the pin closest to the flat edge on the LED lens) goes into the hole on the PCB closest to the five pin header with the DOUT pin.
Starting at D0 and incrementing each time, solder one LED onto the PCB and then power the system on to run the program code above. If all of the LEDs do not turn on, check for solder shorts and opens. It helps to add a small number of LEDs at a time, test them, and iterate. This makes any soldering problems easier to identify and repair along the way.
Carefully continue this process of mounting and testing one (or two or three) LEDs at time until all 64 LEDs are soldered in place and tested using the always blue code above.
Rainbow Demo
The attached rainbow demo.py code demonstrates three different patterns for displaying colorful rainbows using all 64 NeoPixels.
Attachments
Step 6: Special Badge Project
With Summer on the way, some hardware makers direct their creative juices towards the badgelife. While testing the HackerBox 0091 Fibonacci Spiral LED Kit, we realized that it could make a pretty cool badge. We whipped up this PCB with battery support to mount the LED Spiral onto, added a lanyard hole, et voila - badge mode!
Our prototype PCB worked great on the first shot, so we've shared all of the design files and component specs below. And by the way, those KiCad PCB files can be customized into your own badge concept..3..2..1..GO!
We have ordered a small production run of the PCBs and corresponding sets of the other badge components. They should be here early next month. A limited quantity will be available as "badge bundles" here. The rest will be coming with us to DEF CON 31. You can find our table in the Vendor Room and follow us on twitter to know where/when we might just pop up with various electronic goodies.
Fibonacci Spiral LED Badge BOM:
- Exclusive Spiral LED Badge PCB (KiCad design files and final Gerber files)
- 5V DC/DC Boost Converter Module (Amazon)
- Three Slot AA Battery Holder (Digi-Key Part Number HM5217-ND)
- Hook and Loop Strap 20mm wide (Digi-Key Part Number RKW-12-9-BL-ND)
- SMD DPDT Slide Switch (Digi-Key Part Number 401-2002-1-ND)
- 1M SMD1210 Resistors (Digi-Key Part Number A130238CT-ND)
- Four Female 5-pin Headers (Digi-Key Part Number 2057-RS1-05-G-ND)
- Additional Male Header Pins (Digi-Key Part Number 664-G800W268018EU-ND)
Assembly Notes
Solder the two 1M SMD resistors into place. These are pull-down resistors allowing IO pins D7 and D8 to operate as capacitive touch inputs.
Solder on the DPDT slide switch, which is used to switch between BATTERY and USB power modes. The USB power mode isolates the battery from the circuit, which is also used to turn the badge off when USB power is not connected.
Solder on the XIAO microcontroller module using the 14 castellated pads.
The DC/DC Boost Converter Module pumps up the output from the three battery cells to 5V. Check "jumper resistors" A and B on the DC/DC Boost Module. Both positions A and B need to be OPEN to set the output voltage to 5V. If either is shorted (by either a solder blob, or a small resistor) you can just gently heat it with your iron and wipe the pads clear.
Clip four single positions from the male header strip for mounting the DC/DC Boost Converter Module to the Badge PCB. We suggest leaving the black plastic insulator between the power module and the Badge PCB. We also suggest cutting the pins flush against the back of the badge PCB prior to soldering so that the result is nice and smooth and doesn't snag while the badge is being worn.
Solder the four female 5-pin headers to the Badge PCB. Again, we suggest cutting the pins flush against the back of the badge PCB prior to soldering for a nice, smooth finish.
Cut and solder three additional sets of 5-pin male headers (for four sets total) onto the Fibonacci LED Spiral PCB. These will ultimately plug into the female headers on the Badge PCB.
The three-slot AA battery holder provides power to the Badge via the DC/DC boost converter. The power solution is designed for traditional alkaline batteries and does not provide a safe mechanism for recharging the batteries. Using cardboard, plastic, or tape, insulate the back of the battery holder since it will sit against the solder side of the Fibonacci LED Spiral PCB. Trim the wires of the battery holder down to about 6cm. Strip and tin the last 2mm of each wire. Solder the red wire to BAT+ pad and the black wire to the BAT- pad.
Loosely weave the hook-and-loop strap through the slots around the space for the batter holder. Once the two PCBs are pressed together, the strap can be tightened down against the battery holder. Hook-and-loop strap (about 2cm wide) is secure, resealable, and looks very nice, but zip ties, ribbon, or other (preferably non-conducting) material can used here as well.
Demonstration Code
Once power is applied, the rainbow demo code used above will start running again. It should work just fine since the Badge PCB also uses IO pin D10 for the LED chain. For battery powered operation, consider something like the badge demo.py code attached here. This demo uses the D7 touch pad to switch between full rainbow spirals and a reduced power "sparkle" mode that only lights up 20 of the 64 LEDs at any given time, thus considerably reducing consumption of the battery supply.
Attachments
Step 7: Cyber Voice Recorder Kit
This cool Cyber Voice Recorder kit was designed by our friends over at Cyber City Circuits.
In addition to showing how to assemble the kit, their video is a really nice review of soldering techniques.
There are a few minor variations in component markings between the HackerBox kit and the original Cyber City Circuits kit...
The first resistor shown in the video is a beige resistor with three color band markings:
"yellow, purple, red" designating "47 followed by two zeros" = 4,700 = 4.7K
The HackerBox kit has this same resistor.
The second resistor shown in the video is a beige resistor with three color band markings:
"brown black red" designating "10 followed by two zeros" = 1,000 = 1K
However, the HackerBox kit has a blue resistor with FOUR color band markings:
"brown black black brown" designating "100 followed by one more zero" = 1,000 = 1K
The third resistor shown in the video is a beige resistor with three color band markings:
"brown black yellow" designating "10 followed by four zeros" = 100,000 = 100K
However, the HackerBox kit has a blue resistor with FOUR color band markings:
"brown black black orange" designating "100 followed by three more zeros" = 100,000 = 100K
The five ceramic (yellow/orange) capacitors are marked on the PCB and specified in the Cyber City documentation to be 0.1uF ceramic capacitors marked "104". However, the HackerBox kit has 0.01uF ceramic capacitors marked "103". Either value works fine.
Regarding component orientation: The resistors, ceramic capacitors, and two push buttons can be inserted in either direction (they are not polarized). However, the other components have a required orientation. Be careful to follow the documentation (and the video) to make sure the components are inserted correctly.
The completed Cyber Voice Recorder provides a very fun lo-fi sound playback toy that runs on a simple 3V coin cell power source. The circuit is based on the ISD 1820PY chip in a DIP14 package. The datasheet for the chip is only available in Chinese, so we have attached a machine-translated English version of the PDF datasheet.
Cyber City Circuits
Four months ago, we presented HackerBox 0086 in collaboration with Cyber City Circuits, providers of a wide range of engineering services including product design, prototyping, PCB assembly, reverse engineering, and training.
Cyber City Circuits is a disabled veteran owned small business. They are a great team to work with.
If you have a project that might benefit from their expertise, just reach out to Sales@CyberCityCircuits.com
Attachments
Step 8: Spiral Out. Keep Going.
We'll ride the spiral to the end and may just go where no one's been. Spiral out. Keep going.
We hope you are enjoying this month's HackerBox adventure into electronics, computer technology, and hacker culture. Reach out and share your success in the comments below or other social media. Also, remember that you can email support@hackerboxes.com anytime if you have a question or need some help.
What's Next? Embrace the HackLife. Get a cool box of hackable gear delivered right to your mailbox each month and enjoy a generous member discount. Surf over to HackerBoxes.com right now to sign up for your monthly HackerBox subscription.
Please consider sharing this free Instructable with others who may be interested in learning about these subjects. We really appreciate your support and "word of mouth advertising" is the greatest compliment that we receive!