Evil Bouncie Ball Shooter (Halloween Pi)

30 Oct 2015


I had so much fun shooting trick-or-treaters with silly string last year that I decided to up the ante this year with an “Evil Bouncey Ball Shooter”. Before diving into the details, here’s the final product in action at our local “Trunk or Treat”:

Here are the frankensteinian electronics:

Building this thing was quite an adventure. So much so that I decided it merited a quick blog post. So without further ado, let’s dive in…

The Brains

Here’s the (mostly) full schematic:

For the rest of the Atmega8 connections, refer to my post about my Atmega8 bare bones dev board.

As you can see from the schematic below, there are actually two separate CPUs in this project: a Raspberry Pi and an Atmega8. Why two brains? Why not!? Actually, I had originally planned on doing the whole thing with just the Pi, but it turns out that the Raspberry Pi A only has one PWM channel, and that’s needed to run the audio headphone jack, but I needed PWM to control my servo as well. So that’s why I had to throw the Atmega8 in there. Kind of a shame, but I have them lying around, so why not.

The Mechanics

As you can tell, mechanical design is not my strong suit. It took several revisions of the ball feeder design until I got something reliable.

I think the neatest part of the mechanical design ended up being the ball rate limiting mechanism:

Yes, that is a hex key serving as a ball stopper. Best use I’ve ever found for a hex key…

The Circuit

It’s been a few years since I’ve done any microelectronics so I needed a bit of a refresher on MOSFETs… I was having issues getting my solenoid to actuate with a MOSFET driven by one of my Pi’s GPIOs:

The issue was that the MOSFET I was using actually needs 10V to be switched on. I mistakenly thought that the gate-source threshold voltage (which is 2-4V for this MOSFET) was all I needed to switch the MOSFET on. Luckily, we have electronics.stackexchange.com these days and the fine folks over there set me straight in no time. What I needed was a MOSFET driver between the GPIO and the MOSFET. After throwing this guy in there I was in business. I also could have switched to a logic-level MOSFET but the MOSFET driver was shipping faster so that’s what I went with.

I2C for Inter Chip Communication

The Raspberry Pi and Atmega8 talk to each other over I2C.

Servo Control

The servo is controlled with a standard servo control signal (5-10% duty cycle PWM wave @50Hz). As I mentioned earlier, this had to be done on the Atmega8 since doing it on the Pi conflicted with its audio output.

At first my servo was behaving somewhat erratically. Suspecting a bad control signal, I used my bus pirate to measure the frequency of the PWM signal. Sure enough, it as bad. It was exactly half the frequency I needed. After rechecking my math and counter settings I finally determined that my Atmega8’s clock must be messed up. Sure enough, my clock fuse settings were incorrect. Here’s the patch to fix them. The bus pirate is so handy…

Distance Sensor

I’m using this distance sensor, connected to the Pi, to determine how far away the unsuspecting trick-or-treaters are. The way you use this sensor is by requesting a ping by asserting the echo trigger pin, then watching how long the echo pin stays high. That time is equal to the time it took for the sensor to get its own ping back. Multiply that by the speed of sound (and divide by two due to the fact that the ping traveled to the subject and back) and we’re in business. The (somewhat hacky) code that does this is on the Pi here.

See also: the datasheet.

Bootup

I wrote a simple systemd service file to get things running as soon as the Pi boots up. Works like a charm, and even lets me see all my mpg123 subprocesses in a nice little tree view. Sorry, systemd haters, I’m kind of a fan :).

Source Code

The code is all on GitHub.

Handy Resources

Here’s a list of some handy resources I used for this project:


Comments
blog comments powered by Disqus