Instructables

New Jar of Fireflies

When I ran across the Jar of Fireflies Instructable sometime this past summer, I knew I had to build it.  Full credit to Keso for an excellent set of instructions!  I wouldn't have gotten to the point of developing the firefly behavior without such a solid base for building the hardware, as well as firmware to start it out with.  If you have already built a firefly jar according to those plans, it should be straightforward to reprogram it with my firmware to change its behavior.

I wanted to go a step farther when I built the firefly jar as a Christmas present.  My goal was to have multiple fireflies interacting, including males that sometimes synchronize with each other, and females that respond to the flashes of males. I also wanted to base it on the behavior of our backyard firefly, Photinus pyralis , the common Eastern firefly, which is also one of the best studied.  I wrote my own software for the microcontroller to simulate this behavior.  The full project is documented here , but this Instructable should be enough to follow.

The latest version of the firmware is available on GitHub .

You will need two things to use this software:
Both of these are outside the scope of this Instructable.  For the first, please refer to the detailed instructions at the original Jar of Fireflies .  If you need help with programming the AVR, a good place to start is the AVR tutorial from Adafruit .

I tried making a video to demonstrate the flashing behavior.  The quality isn't great (it's from an iPhone, and I reduced the quality to upload it):



 
Remove these adsRemove these ads by Signing Up
LadyBarbara1 month ago

I wish I understood what all this means I would love to make this

aliasjanedoe4 months ago

Never mind the part about the boot sequence not working. My chip had just failed to overwrite and still had it disabled.

aliasjanedoe4 months ago

The boot sequence has never worked for me. It's just ignored.

Also, I think it would be neat to have the boot sequence actually run the entire cycle once with the settings adjusted faster. Like a quick preview. Then go into the real thing. Anybody know how to do this? I mean, I know how to make it go faster, but not how to make it do that once and then start and loop the real thing only. I'm using ATtiny85, so there should be enough space to repeat the entire code, right?

aliasjanedoe5 months ago

I want the fireflies to stay on a little bit longer, but when I change PULSELEN from 20 to 40, I get LEDs which get stuck steady on for over a minute every now and then. I think this is happening when a new cycle starts. Can anybody help?

kjordahl (author)  aliasjanedoe5 months ago

It is rather hard wired in the C code, I'm afraid. You're overrunning the end of the pulse arrays. You'll also have to change the length of the arrays mpulse and fpulse to be length 40 to match (and pad them out to stay on longer in the meantime). You always want the last value of each array to be 0 to keep the LED off between pulses. Otherwise you can make the pulse look like anything you want.

OMG, I actually understood that! And it works! THANK YOU! :)

Now they are all off between cycles. However, there's a full minute where nothing happens before they start up again. Is there an easy change to make them begin again sooner?
kjordahl (author)  aliasjanedoe5 months ago
A full minute between flashes? Or after a full cycle of building up to all 6 LEDs flashing? Either way, it shouldn't be that long. There are some other timing variables set up in the init() function you could play with.
Yes, it's after all six flash together and before the single flashing starts again. This was with no changes to the code. I thought it had gone into sleep mode early, but then it started again. I timed it the next time and it was just over a minute where absolutely nothing lit.

Unrelated, is there a proper way to disable sleep mode? I can set it to a negative number and tell it the count has to be less than that, and that works, but is there a better way?

Also, is there only ever one female? Can I make it randomly have more?

And is there a way to make it randomly select between several different mpulse and fpulse choices?

Anyway, thanks so much for your help. I actually have it working in a way that I really like. I'm just curious about how much I can tweak it.
kjordahl (author)  aliasjanedoe5 months ago

On line 170, it sets nmales=0 after each full cycle, so it will appear all off until the first male randomly turns up. If you make that 1, it will always have at least 1 going.

Your method works fine to disable sleep, you could also just take out the "if(bigcount>=SLEEPAFTER)" statement entirely in the main loop to eliminate it.

Adding more females would take some larger changes in the logic. It's certainly possible, but that's up to you.

Choosing different pulses is certainly possible as well, you'd have to decide when it's going to choose which pulse. At the beginning (or each time through the full cycle) would be fairly straightforward.

Glad you enjoy it!

Mine works! Thanks for sharing!
essplode2 years ago
Thanks, I preferred this pattern over the original
seth1473 years ago
On your prototype board do you have a socket that the ATtiny85 chip is sitting in? If it is i cant seem to find one anywhere. Do you happen to have a part number if that is what you are using. :)
kjordahl (author)  seth1473 years ago
Sorry it took me so long to reply. I think I used Digi-Key part no. 3M5461-ND.
I can't seem to get the firefly software unzipped. could anyone send me a makefile or an unzipped set. Thanks ~Corry
kjordahl (author)  RabbidSquirrle3 years ago
Sorry you had trouble with the zipped file. I have put the firmware up at github, where it should be easier to browse and get in a format you can use.
godfish4 years ago
I just got all the parts today, I have a question on your picture with all the LEDs on the board in step two you have five resistors on the board but in the schematic you show 3? maybe the other resistors are for the batterys?
kjordahl (author)  godfish4 years ago
The schematic is correct.  On the prototype board, there are two pairs of 20 Ω resistors (each pair connected in series), to make 40 Ω each, which matched better with the LEDs I used on that on that board than the 100 Ω used on the surface mount board.

You may want to adjust the values of those resistors depending on the exact LEDs you use.


bxridley4 years ago
The code (firefly.hex) from the original Keso Firefly jar works with this schematic and an ATTiny45, but I get no response using pyralis.hex.    This is my first effort building, using, coding AVR, etc, so I may be missing something crucial.  I'll experiment and let you know if I find a solution.
kjordahl (author)  bxridley4 years ago
It seems to be the case that the current version of pyralis.hex I have posted does not work on an ATtiny45.  I'm not sure why that is right now, previous versions worked fine for me.  I will look into it when I get a chance.

Sorry about that.  You might try compiling it yourself, changing the Makefile appropriately (set DEVICE = attiny45).

I've changed the text above to reflect that for now.
kjordahl (author)  kjordahl4 years ago
I think I understand the issue.  It seems that a .hex file compiled for ATtiny45 will work fine on an ATtiny85, but not vice versa (even if it is <4k).  I had gotten complacent when I found I could compile for either, but haddn't realized that the .hex files aren't completely interchangeable.  I have changed the Makefile as I suggested above and recompiled, and it works for me now on both the ATtiny45 and the ATtiny85.

I've updated the link on my website so that the pyralis.hex file there should work on both now, but you can always recompile it for your own hardware if that doesn't work for you.

 ThX!  Like you, I am starting from the ground up so I can actually understand what I am writing/programming, but I REALLY wanted to compare/contrast the behaviour of your fireflies vs the original Keso code.  I didn't have any green SMT LED around, so I used red SMT LEDs and made a jar of evil red blinky flies.
 It worked!  Thanks so much!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!