Python and the 555 Blinking Eyes in the Bushes

Blinking Eyes
LED blinky eye units consisting of craft popsicle sticks and pipe cleaner anchors deployed in a bush.

For Halloween, I had wired the bushes in front of my house with a dozen or so pairs of blinking LED eyes. Each pair of eyes blinked at their own rate–all powered by an Arduino. After building these centrally-wired daemonic bush entities I wanted to be able to deploy a few more in remote bushes and trees without having to wire them up to an Arduino. So I turned to my good friend the 555 timer chip. 555 timers for the uninitiated are a very versatile integrated circuit that can be used in a variety of timer-related circuits.

I was looking to achieve a very specific blinking pattern and was having a hard time figuring out the optimal set of components to use. There are tons of calculators out there for figuring out the characteristics of a 555 circuit based on the values of the components you use. If you’ve ever tried using one of these calculators for this sort of project it can be very frustrating. I don’t actually care what the components’ values are; I’m usually not thinking about that side of the equations at all. What I really care about are the timing characteristics of the circuit in terms of how long a signal is high and how long it is low. I want my “on time” to be X seconds and I want my “off time” to be Y seconds. You figure out what components I need to plug in to get that behavior.

Most of the existing 555 calculators I was able to find take the component values (e.g. R1= 100k, R2= 150k) and then compute the frequency, time_high, duty cycle, etc. I would rather think about the behavior I’m after and plug in the time_high and time_low and receive the values of the components I should use to achieve such a circuit.

Hang on. Let’s turn the real world dial up one more notch. It just so happens, I don’t have a resistor measured at 183.45 Ohms to achieve the specific oscillation I desire. Maybe we could constrain the calculator to only consider component values for components I actually have in my possession. Give me the best possible fit for the components that I do have (or can get my hands on).

So, I whipped up a simple Python tool to help me optimize my component selection to best achieve my desired blinking pattern. Here is an example snippet that solves the 555 timing equations using my inventory of components and my desired signal characteristics:

from optimize_555.opt import optimize
target_high = 42  #42 seconds on
target_low = 15 #15 seconds off
R1, R2, C, time_high, time_low = optimize(target_high, target_low)

This results in a timing circuit that goes high for 45.7 seconds and then has a 15.2 second low. And the best part of it is it’s accomplished using components that I have in-stock. R1 is 200KOhm, R2 is 100KOhm, and C is 220uF. The system defaults to a set of commonly available components, but you can override and define your own inventory.

In its current form its a very thin wrapper around some basic SciPy functions. You can check it out over at github. If there is some interest, I hope to expose it through a web interface at some point to make it more accessible to non-programming, electronic hobbyists. Hope it helps and happy blinking!

PyCarolina Redux

We just wrapped up the inaugural PyCarolinas conference. I know I had a good time and it was great to see so many people in attendance not only from the southeast, but from across the US with even some international attendees.

PyCarolinas

Professor Gary Bishop of the Department of Computer Science at UNC Chapel Hill gave our first keynote on Saturday touching on accessibility and enabling technologies. It was an inspiring call to action. We as developers have tremendous power at our fingertips to make a difference in the lives of countless individuals around the world. Just do it and make it happen. Leave the committees out of it.

Lynn Root gave Sunday’s keynote, where she shared her experiences in joining and building communities. My favorite take away here on the simplicity of community and solidarity was, “Hey! You’re a nerd. I’m a nerd. Let’s hang out. Kthbai.”

Barry Peddycord III’s talk about Python in computer science education sparked a lot of offline discussion, which struck close to home given some of the educational technology initiatives I’m working on.

I missed Michael DeHaan’s talk on Ansible, but it did put it on my radar. While, I’ve made healthy use of Chef, Puppet, (and fabric), they’ve never felt just right and I would gladly jump ship to a better solution. So, I hope to check it out in the next few days.

I was cursing Fred Alger after his talk, Sysadmining Python to the Moon, for planting the seed that maybe I could build something and send it to the edge of space–it’s possible. Just what I need. It was a fun, inspiring talk and while I hope I can shake its effects, I have a feeling I may be revisiting it. You can check out his presentation materials over on github.

François Dion gave a fun and passionate talk about Raspberry Pis, their use in exciting kids, and how to seriously soup them up with all sorts of add-ons. I plan on following his work over at his Raspberry-Python blog.

David Ray and Julia Elman from Caktus also had great talks about working with designers, which sparked some good discussion. David presented django-comps, which looks like a simple, yet handy tool for serving a directory of static-y html files from a Django project. The idea is you can have a designer work within the same source repo as the project proper as they start building out comps/templates. This is an ideal setup for integrated rapid prototyping. Your project’s defined comps directory will show a list view of the available pages from which you can drill down. You can also easily zip things up for delivery to a client for offline review. I’m looking forward to checking this one out.

Another nice nugget came care of a lightning talk given by Simeon Franklin (@simeonfranklin). If you find yourself using optparse: stop. No really. Check out docopt. It looks like it may take a tremendous amount of pain out of writing command line utilities.

I think the first PyCarolinas event went swimmingly. A huge thanks to Calvin Spealman, Chris Calloway, UNC, the PSF, all the volunteers and the sponsors for making it happen. I’m already looking forward to next year’s!

PyCarolinas Attendees
PyCarolinas Attendees https://twitter.com/PyCarolinas/status/260075547537833984

Recap of the Squirrel Hordes

I gave my PyCon talk this weekend–“Militarizing Your Backyard With Python: Computer Vision and the Squirrel Hordes.” I was not prepared for the number of people who caught me after the talk and throughout the conference telling me about their own battles. Thanks again for all the recommendations about how to improve my firepower, tracking, and classification accuracy.

squirrel
Horde Scout (source:wikipedia)

As requested I’ve posted the presentation on SlideShare and here’s the final squirrel encounter video and the actual PyCon Presentation.

One great resource that was really helpful for getting ideas about sentry guns is Project Sentry Gun. There is Wiring and Processing code to get you started as well as a premade Arduino shield if you’re interested. The folks at Servocity were also very helpful in sizing servos for my project.

As time permits, I’ll post some additional articles detailing the various steps of my project that folks seem to be interested in.

Thanks all. Good luck and don’t get captured.