Step 1: Building ImpBot: What You'll Need
- The Electric Imp API for configuring and controlling Pulse-Width Modulation (PWM) is quite straightforward and intuitive
- Many servos, like the A0090 micro servo in the pan/tilt mechanism I used here, run great on a 4.5V to 6V supply - which means you can power your electric imp breakout board and servos from the same small power supply
- A note on this: you may have less luck if you attempt to run the imp and servos off of a USB power supply. While the supply voltage is just fine, a USB power supply may not provide the necessary current, depending on what you're using.
- You don't need any additional components: power, an imp, and a servo, and you're all wired up.
- Everything is really small!
- An imp (rather obviously)
- An electric imp breakout board (I used an "April" dev board from electric imp, but the Sparkfun breakout is identical)
- Two A0090 micro servos
- A pan/tilt bracket
- A small piece of stripboard for connecting things cleanly
- A pair of CR123 batteries
- A pair of CR123 battery clips
- Some headers and heat shrink tubing to keep things neat
- A box I had handy. Something 4" square by 1.5" deep or more should be just fine for you. You'll want to cut some holes in it, so get one made out of something reasonably easy to cut.
- A SPDT (Selector) Switch, which I wired up to select between USB and battery power. Since I don't have USB power connected, it serves as a power switch
- A soldering iron and some solder
- Heat gun for shrinking heat shrink
- A big, heavy pair of scissors for cutting up the stripboard. If you're going to saw this stuff (you probably don't want to), wear a respirator. FR4 dust is toxic.
- A pair of angle cutters.
- Some double-sided foam tape for securing stuff to the bottom of the box
- Small adjustable wrench
- Dremel - great for cutting a hole for the pan servo in the top of the box
Step 2: Making a Compact 6V Supply From Two CR123 Battery Clips
- Take a good look at your clips and note which side is marked as positive and negative. Most of these clips are mechanically functional in either direction, but the markings are helpful if you use them, so go ahead and take note of that now.
We're going to solder the positive tab on the bottom of one clip to the negative tab on the bottom of the other. The tabs on the side that we DON'T solder together must not touch, however, or they'll short your batteries out. Let's go ahead and cut them off now.
- Orient your battery clips as shown
- Cut the positive tab off the bottom of one clip
- Cut the negative tab off the bottom of the other
- With the appropriate tabs cut, we need to solder the remaining positive tab to the remaining negative tab. Before we do that, though, we need to put a piece of foam tape between the two clips to hold them together. Tape together as shown.
- NOW go ahead and solder the remaining two tabs together as shown.
Add wire leads to connect your battery pack to your imp breakout board. For convenience, we can now think of your battery pack as one big battery (with two CR123s inside it). The "positive tab" henceforth refers to the positive side that IS NOT soldered to the negative side of the other battery. The same goes for the negative side - we mean the negative terminal of the battery clip that IS NOT soldered to another battery clip.
- Solder a short (1" to 1.5") piece of red wire to the positive side of your battery pack.
- Solder a slightly longer (1.5" to 2") piece of black wire to the negative side of your battery pack.
- Put a piece of foam tape on the bottom of your breakout board and use it to secure your breakout board to the top of your battery pack.
- Connect the positive (red wire) side of your battery pack to the "P+" terminal on your breakout board.
- Connect the negative (black wire) side of your battery pack to the "P-" terminal on your breakout board.
Step 3: ImpBot: Schematic and Getting Started
For tips and tricks on soldering to plated holes on your breakout board, male pin headers, and solder lugs, check out the controlBox instructable. To keep things moving, I'm not going to go through the whole soldering procedure here in the same depth.
The servos already come with female socket headers, so we can avoid soldering them completely by just putting some male pin headers down on the perfboard. I also added a pair of wire leads to my breakout board for Vin and GND, which I wired to male pins. I put a four-pin female socket down on the perfboard (I only needed two pins, but four-pin sockets were the smallest I had).
I also happened to have male pin headers on my breakout board already, so I was able to use test leads with single-pin female sockets on both ends to connect the PWM signals on the breakout board to the appropriate pin on my perfboard that way.
Without belaboring the point further: you can connect the lines however you prefer. The easiest way, if you're starting with bare boards, is probably just to run a wire from your breakout board to the perf board for each of:
- Power (Vin, 6V)
- Pin 1 (the PWM signal for the pan motor)
- Pin 2 (the PWM signal for the tilt motor)
- Solder two three-pin male headers to your perfboard
- Use small pieces of wire to connect the middle pin of each to the 6V supply from your breakout board
- Use the same technique to connect the right pin of each three-pin header to ground on your breakout board.
- You can run the PWM signal for each motor directly to the remaining pin on each header from the breakout board.
That's the functional part of this project! If you want a power switch for your robot, you can add that too:
- Solder a 4" to 6" piece of wire to the center pin of the three-pin header used to select USB or Battery power on your imp breakout board. If there is no header on your breakout board, you can solder this wire right to the plated hole in the center.
- Solder another two 4" to 6" pieces of wire to the USB and BAT connections
Connect these three wires to your toggle switch:
- The wire from the center pin (or center hole) should be connected to the center pin on the toggle switch
- The remaining two wires go to the two outer pins on the switch - which side is which does not matter.
- As always, I recommend using heat shrink on these connections to keep things neat.
Step 4: Into the Box
Naturally, I recommend you check your servo's dimensions and measure out the cuts you're going to make accordingly, but I've provided a quick diagram of the dimensions I used for my A0090 servo. The dimensions shown are measured values from the body of the servo itself; I cut wide of these. In addition to making a cutout for my servo's body, I made a notch for the cable to the tilt servo. I cut the notch big enough that some additional wiring will fit comfortably; the goal is for the robot to be able to hold something like a light or a camera or a marshmallow-roasting stick or whatever the case may be.
NOTE: I highly recommend drilling the mounting holes for the servo before making the servo body cutout with the dremel. The top of the enclosure is stronger without a big hole in it, and it will make your drill work easier and more accurate. Better still; there's no danger of the drill walking to the edge of the cutout and blowing through the wall between the mounting hole and the cutout if you haven't made the cutout yet. Center-punch your holes before drilling for accuracy and drill to 1/8".
I highly recommend using a drill to drill the four corners of the rectangle prior to cutting along the edges with a dremel. With a cut-off wheel, getting into the corners without overshooting and making unsightly marks is quite difficult. By pre-drilling the corners, you give the dremel end points to cut lines between. This also seems to help with reducing the amount of melted plastic blown back into the cut by the cutoff wheel. Try starting with an 1/8" hole at each corner.
Once you've got the cutout in the enclosure, you can drop the pan servo into the cutout and secure it. You may need to remove the pan/tilt bracket from the top of the pan servo in order to get at the mounting screws.
While you're working on the enclosure, now's a good time to make a hole for the power switch, if you added one. The switch I used required a 3/16" hole in the enclosure. Center punch, drill with the 1/8" drill first, then finish with the 3/16" drill. If you have a lot of burrs around the hole, you can clean up with sandpaper, an X-acto knife, or (my personal favorite) you can gently deburr the hole with a countersink tool. Remove the hex nut from the switch shaft, feed the switch through the hole, and secure with the nut by gently tightening with a a small adjustable wrench.
Feed the cable for the tilt servo through the notch in the lid, secure both of the servo headers to the pins on your board inside the case. Lower the lid onto your enclosure and secure it.
Alright, let's add a little bit of code to make your robot controllable.
Step 5: The Source Code: Your Robot's Firmware
To grab the source code, head to https://github.com/tombrew/ei-fw-tom/blob/master/april-dualServo.nut. Copy the code to your clipboard, then head to plan.electricimp.com and sign into planner. Now follow these steps:
- Click the "code" tab at the top of the planner window in your browser
- Click the big "+" button at the top of the code window
- Give your new firmware a name. I used "april.dualServo", as our breakout board design is called "April"
- Paste the code from github into the IDE that appears
- Click the save button in the top left of the IDE window
- Click the "plan" button in the top left to go back to the planner view
- Blink up your impBot to put it on your wifi network. A blue box will appear in your plan. If you haven't blinked up an imp in your breakout board before, the blue box will say "BLANK", as the imp service does not have any firmware to run on the board until you assign one.
- Click the settings button (a little box with a picture of some sliders on it) in the top-right corner of the blue box representing your impBot
- In the popup box that appears, click the drop-down menu to show all the firmware you have available to run on this imp
- Select the firmware you created by pasting in code from github
- The imp will begin to run your code in just a few seconds. The words "APRIL DUAL SERVO CONTROLLER" will appear in the blue box once the imp is configured.