Tuesday, December 11, 2012

Jingle Bells 2012

Time to add some holiday cheer to the house! Every time you visit bot-thoughts.com a bell will ring in my office.

And there's that thing with the angel, too. Anyway...

This time around I decided to go with a complete self-contained solution, a great excuse to finally break out my Raspberry Pi and get it set up.

Yes, it's true, using an 8-cog microcontroller and a full on mini UNIX SBC constitutes absurd overkill for such a ridiculously simple task as ringing a bell...

To set up the Raspberry Pi I downloaded and installed Raspbian, then installed Apache.

I'm using one of my newly assembled eeZee Propeller boards to control the servo just like last time.

This time instead of a serial command, the Prop counts active transitions on one of its pins.

That signal comes from GPIO4 on the Raspberry Pi. The GPIO is toggled with a call to a REST service provided by webiopi whenever a python CGI script is called on the Pi's web server. The CGI script is called by an iframe on my blog.

Raspberry Pi GPIO pinout


Propeller Code

Here's the highlighted version, a screen capture from the Spin tool. One cog counts active transitions on P20 using a variable in hub memory. The main cog rings the bell by moving a servo back and forth count times. 


Here's a pastebin version of the code you can look through.


Python CGI Script

The python CGI script uses urllib2 to run an authenticated call to the webiopi REST API to send a pulse out of GPIO4. First it checks to see if the GPIO pin is set as an output. If not, it sets it as an output. Then it makes a call to the pulse function.




Source Code

Gotchas

I ran into a lot of gotchas along the way, like any project I undertake (I fail repeatedly so you can learn...). Between problems with iPhone/Dropbox/Picasa uploads, LDO regulator pinout problems on the new Propeller boards, anti-virus, user account control, a BSoD and a host of other problems on the new computer, and more, this took way longer than it needed to.

The worst was that my ActionTec M1000 router kept tacking on .domain.actdsltmp to every dns query so I couldn't test my Rasspi's web server with DynDns.com. The solution, after searching for quite some time, was to put the modem into transparent bridged mode and to go back to using my wireless router as the main router for the home network.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.