I live in the UK and have never seen a native Firefly or glow worm - I'm not even sure if we get them here.


Some years back I visited North Carolina to visit friends and was amazed to see fireflies flashing away in the garden shrubs ...if only I could bring that magic to my garden in summer by making some RGB LED 'fireflies'.


My Initial Design

Some years back I used the Microchip techsheet AN1606 and the Configurable Logic Cells (CLC) of the PIC16F1509 microcontroller to make some Christmas decorations. These decorations used individual WS2812 RGB LEDs that I individually wired together from mass PCBs like those below.

Image result for ws2812 rgb 100 pcs


I wrote all the code for that project in assembler which was quick and did the job but later I wanted to add extra functionality and that became more difficult.


Last Year's Festive Lights

I ported the code across to C, aiming to use the free Microchip XC8 compiler. I still kept the real core routine that wrote the required pixels quickly to the CLC as assembler because I didn't want any interuptions to that and it had to be quick. I also moved to the PIC16F18857 device (which also has the CLC ). My initial design used the Microchip PIC to undertake the fast data dump and timing protocol to the WS2812 but was loaded from a Raspberry Pi via the SPI interface. The PI was acting as a quick Ethernet UDP packet grabber and those packets were generated from a open-source light sequencing program. That all worked really well indoors on the run up to Christmas. I moved it all outside and then had issue after another - mainly WiFi signal strength to the RPi2 B+. Eventually I reprogrammed the Microchip PIC to free style the lights to my own inbuilt patterns without any RPi or Ethernet requirement.


This Summer

Back to this summer and my fireflies. As the code is now easier to understand and manipulate I just reworked the EffectsFSR_Twinkle function to use a single colour, in my case I designated a pointer to a colour as pFireflyGreen. And in the space below is a video of them working once dusk fell. I'm almost happy with those as they are but there could be improvements. I've called my project code the EnLighteningPixelEngine - as it can be manipulated for many different effects.



Future Planned Changes

The current code already contains a prototype function called EffectsFSR_Fireflies which I hope will be a more realistic effect. At present I am not calling it as I haven't finished it. The aim is to flash just a small number of LEDs but that they flash between 3-5 times before staying off for a while.


I also want to add a switch so I can cycle through some of the other available patterns or change the firefly colour to something more akin to the film Avatar.


I'm planning on getting a GraspIO and think that would be great if I could interact with the PIC code accordingly via my mobile.


Code and Circuit

I've uploaded my latest code to my Github page. Feel free to browse it, copy or branch accordingly to use it on your own designs. You should be able to use it with any of the 8-bit Microchip devices supported by CLC peripheral but would have to run the Microchip Code Configurator (MCC) again or adjust the port and register settings accordingly. You could likely also port it to the Atmel devices with Configurable Custom Logic (CCL) but that would need verifying.


I make no apologies for my code. It will be messy and not optimised (by me let alone the compiler). There are chunks of code not used but left in and ideas that are just commented out. I hope in time to tidy it up but there are some comments so it should be fairly easy to understand.


  • System.h contains much of the settings that may need adjusting for different numbers of LED.


  • Sequencer.c contains the main function, the Finite State Machine (FSR) which is legacy from when I was using the RPI and another FSR for controlling the effects.


  • Processor.c is the engine that runs the LED output and associated functions.


  • EffectFSR.c contains all the different effects I have been working on.


[To be continued]