Last week, I posted a demo on building impBot, a simple pan/tilt servo "robot" controlled via the internet with the electric imp. At the time, all I had for controlling said robot was a potentiometer in a box, which made the overall usefulness a little underwhelming. This week, I've got a demo on how to build a better way to control the impBot (or just about anything else, for that matter) by creating an internet-connected joystick using one of Sparkfun's thumb joysticks.
These thumb joysticks are wonderfully simple, and have a select button along with the X and Y axis outputs; they're just like the analog controls on your playstation controller (quite possibly the exact same part, actually). Fully interfacing to one with the imp takes just three signal wires (X, Y, Button), 3.3V from the Electric Imp Breakout Board's regulator, and ground: 5 wires. The hardest part about the whole thing is just getting the whole apparatus packed up attractively in a box.
Once you've got this project all set up, you've got an internet-connected X-Y control with a select button - twice as powerful as the controlBox + a button!
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: What You'll Need
- Electric Imp
- Electric Imp breakout board
- Enclosure: I used a Hammond 1593PBK hand-held instrument enclosure with battery holder
- A bit of perfboard. Plated is easier to solder.
- A SPDT switch (for power)
- Some 4-40 screws (4 of them, actually)
- Some foam tape
- A bit of heat shrink tubing
A drill. You'll need a few important bits:
- A center punch and a small hammer for marking and starting holes
- A 1/8" drill for starting holes and drilling mounting holes in your perfboard
- A drill sized for your SPDT switch. Mine was 3/16"
- A hole cutter, 1" , to make a hole for the joystick
- A 4-40 tap and tap handle for threading the mounting holes for the joystick.
- A dremel or similar for cutting a slot for the imp and cutting down your perfboard
- A respirator or mask - don't cut FR4 (the material your perfboard is made of) without one! If you're not cutting FR4, you won't need this.
- Soldering iron and solder
- A heat gun for shrinking heat shrink. A hair dryer will do in a pinch
- Angle cutters and wire strippers
- Adjustable wrench
- Philips-head screwdriver
- A smartphone running the free electric imp app to "blink up" your imp onto your network
- A computer to access the electric imp planner (http://plan.electricimp.com)
- A free electric imp developer account for planner access (just sign up and you're good to go)
Step 2: Getting Started: Preparing Your Breakout Board
- Remove tall components from the breakout board, if necessary
- Add three leads for the X, Y, and Button inputs to the electric imp
- Add leads for power and ground to the joystick
- Connect the power select switch to the breakout board
- Connect the battery pack to the breakout board
If you're using the sparkfun breakout, no male pin headers for the power select jumper are populated, but you still have a USB header that's going to get in the way. Let's remove that first. To get it off of there, the best thing to do is heat the whole area, then gently push the connector off the board, taking care not to lift the pads in case you'd like to put it back on there. Here's what I did:
- (optional) Use some solderwick and a soldering iron to get most of the solder off of the pads. There are four big mechanical pads at each of the four corners of the connector, and five small pads along the back of the connector
- Break out the heat gun and turn it up. If you've got a preheater that you can place the board on top of, this will help too. Heat the area evenly with the heat gun until the solder on all of the pads flows - you'll see it become shiny.
- Keeping the heat on the part, gently nudge the connector off the board with tweezers, then pull the heat gun away.
- Use angle cutters to cut the header pins off right at the board.
- One by one, heat the pads with the soldering iron. With the iron still on the pad, use a solder sucker to remove solder (and the remaining bit of header pin) from the joint.
- If the solder sucker can't get the hole clear, you can use tweezers to pull the bit of remaining pin out of the hole while heating it with the soldering iron.
Cut 3 pieces of wire, 4" to 6". You can use any three colors, but I recommend not using red or black. Following the color convention used in the breadboard diagram:
- Blue wire for the Y axis
- Yellow wire for the X axis
- Purple wire for the button
- Strip about 1/8" of insulation off of each end of each wire.
Solder the wires to the appropriate pin on your breakout board (follow the labels silkscreened on the breakout board):
- Blue to pin1
- Yellow to pin2
- Purple to pin5
- To solder them down easily, I recommend you place all three wires through the holes with the board upright, tape them in place with a bit of kapton tape, then flip the board over, solder them in, and trim the excess with angle cutters.
- Using the same procedure, solder a 4" to 6" piece of red wire to the 3V3 terminal on your breakout board, and a 4" to 6" piece of black wire to the GND terminal (either one is fine, but things will look cleaner if you use the one right next to the 3V3 terminal)
- Cut three pieces of wire, 4" to 6", red, yellow, and purple, and strip 1/4 of insulation off of each end
Solder each to one of the three power select holes on your breakout board, just like you did with the leads for the joystick. Trim the excess off the back of the board when you're done.
- the red wire goes to the center terminal
- Purple wire to the terminal labeled "BAT" (Battery)
- Yellow wire to the terminal labeled "USB" (USB power supply)
- Cut three 1/2" pieces of heat shrink and slide them over the wires, down toward the breakout board.
Tape your switch down to something to hold it in place, and solder the three leads to it. Red wire goes to the center pin on the switch, purple and yellow to the sides (either side is fine). To solder to the switch:
- Heat the pin you're trying to solder to
- Flow a little solder onto the pin on the switch.
- Put down the solder and pick up the wire you're going to connect to the switch terminal. Tweezers can be helpful for this as they'll keep you from burning your fingers.
- Heat the pin on the switch again until the solder flows and slip the wire through the hole in the center of the lug on the switch
- Remove the heat, let the solder cool before letting go of the wire, and trim the excess
- With the switch all soldered, slide the heat shrink back up and over the solder lugs on the switch, and use a heat gun to shrink it into place.
- Tape your breakout board to something to hold it in place
- Heat the P+ pad and flow a bead of solder onto it. Put down the solder and pick up the red wire on the battery pack.
- Heat the P+ pad back up until the solder flows, holding the stripped end of the red battery pack wire against it.
- Remove the heat and hold the wire in place until the solder cools
- Repeat with the P- pad and the black wire on the battery pack.
Step 3: Prep the Case to Mount the Joystick
IMPORTANT: WE NEED TO TAP THE HOLES IN THE *BOTTOM* HALF OF THE CASE. That is, the half with the battery door. The four holes we're tapping are in the mounting bosses on the inside of the bottom half of the case. They form a square 1.1" by 1.1" and are in the half opposite the battery door.
- Break out the 4-40 tap and mount it in the tap handle.
Carefully tap the four mounting holes in the bottom of the case with the tap.
- Holding the tap very, very steady and applying firm downward pressure on the tap handle, place the tap in the center of the hole in the boss you're going to tap.
- I recommend holding the tap still and actually turning the case itself on the table. It's just easier to keep the tap vertical this way.
- The tap will draw itself into the hole as it cuts the threads
- Tap until you hit the bottom of the boss. It's maybe 1/4" of thread.
- Repeat for each of the four holes
IMPORTANT: WE'RE CUTTING THE CLEARANCE HOLE IN THE *TOP* HALF OF THE CASE. That is, the half that *does not* have a battery door in it. We'll be cutting the hole in the end OPPOSITE the end with the place where the imp and battery pack will sit.
Clamp the top half of the case in a vise and measure out from the edges of the flat surface. You want to center the hole between the left and right sides, about 1.2" from either edge of the flat top of the case. The hole will be about 1" from the end of the case - that is, from the end OPPOSITE the end where the battery pack will sit.
- Measure and mark the hole position
- Centerpunch the hole you're going to drill
- Drill an 1/8" starter hole.
- Use the 1" hole cutter to cut... a 1" hole!
- Clean up the edges of the hole with sandpaper or an x-acto knife
Ok, the enclosure is ready for the joystick! We need to install the imp breakout board next, so check out the next step.
Step 4: Mount the Breakout Board in Place
IMPORTANT: WE'RE MOUNTING THE IMP AND CUTTING THE SLOT IN THE *TOP* HALF OF THE CASE. That is, the half with no battery door. The imp sits right under where the batteries will go.
First, we need to mark out the slot for the imp and cut the slot with the dremel. I recommend using the cutoff wheel tool on the dremel for this.
- Put a 1" long piece of foam tape on the bottom of the enclosure on the battery-pack side. Leave the backing on the top side (don't expose the adhesive).
- Set the breakout board on top of the tape and slide the imp socket up to the edge of the case. Mark out the outline of the imp slot on the inside wall of the case. I used an x-acto knife for this.
- Remove the imp breakout board from the case. Mount the case in a vise, if you've got one. If not, secure it in place with a healthy dose of tape or similar.
- Cut out the marked area from the inside of the case with the dremel. Cutting from the inside keeps the outside looking clean. Clean up the excess with the x-acto knife when you're done.
- Peel off the backing on the foam tape and mount the breakout board in place.
- Cut three short pieces of foam tape, each about 1/4" in length. Place two on the inside wall of the case, above the imp breakout board along its long side. Place the third on the inside wall of the case, centered above the pin terminals on the end of the breakout board.
- Peel the backing off the tape and set the battery pack on top of the imp breakout board, not touching the tape.
- Slide the battery pack into the corner of the case so that the two sides facing the tape contact the tape at the same time. This is a little tricky, take it slow and careful.
Step 5: Mount the Joystick on Some Perfboard (making a Joystick Breakout)
First, let's prep the perfboard:
- Mark out the outline of the board you'll need, 1.5" by 1.5". It's 15 rows by 15 rows if you're using standard .1" pitch perfboard. See the images for a mechanical drawing.
Drill holes for the four mounting points. Use a 1/8" drill. You can use existing holes in the perfboard as your starter holes, which makes things really easy.
- The holes are in a square pattern, 1.1" by 1.1" (11 rows apart)
- IMPORTANT: WEAR A RESPIRATOR WHEN CUTTING FR4. That's fiberglass and other nasty stuff! You don't want that in your lungs!
- Drill or dremel holes for the four mechanical mounting points on the joystick. They form a square, .6" by .6"; center the pattern on the board. Again, you can use the existing holes as starter holes. The 1/8" drill may be a bit large for this if you're going to drill them out, so use something smaller if you've got it.
- You can dremel or saw the perfboard to the outline you need. Respirator required!
- Pop the joystick onto the board! The pin pattern isn't a *perfect* fit, so watch the pins and guide them carefully into the board with tweezers if necessary.
- Flip the whole thing over and put a big blob of solder on the bottom of each of the mechanical pins in the corners to hold it in place.
- Orient the joystick as it will be oriented in the box. I recommend that the X-axis potentiometer be on the bottom, placing the Y-axis potentiometer on the right side.
Cut and strip a short (1" or so) piece of red wire. Push the stripped ends through the perfboard from the top side, leaving the exposed wire on the bottom side. The goal here is to connect the rightmost pins on the two potentiometers (we'll then wire 3.3V in from the breakout board to these two pins). Solder into place as follows:
- Push the wire through a hole adjacent to the pin you want to solder to
- Flip the board over
- Fold the exposed wire onto the pin you're trying to solder to
- Heat the pin and wire together with the soldering iron and flow some solder onto the joint
- Trim excess wire
- Repeat step 2 with a piece of black wire, connecting the leftmost pins on the two potentiometers
- Using the same procedure as with steps 2 and 3, connect the leftmost pin of the x-axis potentiometer to the bottom-right pin on the button (if you're looking at the joystick from the top).
- Connect pin1 on the breakout board (blue wire!) to the center pin of the Y-axis pot
- Connect pin2 on the breakout board (yellow wire!) to the center pin on the X-axis pot
- Connect pin3 on the breakout board (purple wire!) to the bottom-left pin on the button (again, looking at the joystick from the top)
- Connect GND on the breakout board (black wire!) to any of the pins you've wired together with black jumper wires on the joystick (leftmost pin on either pot, bottom-right pin on the button)
- Connect 3.3V on the breakout board (red wire!) to the rightmost pin on either potentiometer.
Step 6: Assemble!
Mount the joystick to the bottom half of the case (where you tapped the holes).
- Set it in place, orienting it as you did when you wired up the board (x-axis pot on the bottom, y-axis pot on the right side)
- Screw the four 4-40 screws into the holes you tapped
- Tuck the wires out of the way. You can secure them with tape if you need to.
- Install the power switch in the end plate. Remove the nut from the threaded portion of the switch (if installed), feed the switch through the 3/16" hole you drilled, and secure it in place with the nut. Tighten gently with an adjustable wrench.
- Slide the plate into place with the slots at the end of the case
- Math the two halves of the case up and secure them together with the four flat-head screws that came with the case
- Install two UltraFire lithium-ion batteries in the battery case. Note that these are 3.6V each, not the typical 1.5V you get with a AA alkaline battery. This means the supply voltage to the breakout board is 7.2V, which means the on-board regulator gets to do its job and make 3.3V for the imp.
- Slide the battery door into place.
- Install an imp
Step 7: Blinkup and Planner
- Open the electric imp app on your smartphone and sign in to your account. If you don't have one yet, sign up at http://plan.electricimp.com.
- Add your wireless network to the electric imp app by providing the SSID and password.
- Hold the screen of your phone up to the end of the (powered on) electric imp and hit "send blinkup" in the electric imp app.
- The screen of your phone will flash white and black for a few seconds. What's happening here is that the SSID and password for your network are being sent to the imp so that it knows how to connect to the internet.
- The imp will blink green once after it successfully receives this information. If it blinks red quickly three times immediately after the blinkup is sent, it didn't get the info and you need to try again. Check out forums.electricimp.com for more help if you have trouble.
- The imp will then perform DNS with your router to get online. It will blink red as it looks for the network, then begin to blink red to orange as it performs DNS. Finally, it will blink green once it has connected to the internet and phoned home to the imp service.
- If you've never connected this breakout board before, it will just say "BLANK"
- If you've connected an imp in this breakout board before, it will say the same thing it said last time you connected
- Open a new tab in your browser and go to https://github.com/tombrew/ei-fw-tom/tree/master/demos/joystick. Copy this code to your clipboard.
- Back in the planner, click the "code" button at the top of the screen.
- Click the big "+" button on the top left to create a new firmware.
- Name your new firmware. I called my "april.joystick".
- Now you'll see the electric imp IDE in your browser. Paste the code into the window and hit "save" (the disk button at the top-right). When the code has saved, click "plan" at the top to go back to the planner.
- Click the settings button in the top-right corner of the blue box that represents your joystick. A popup will appear showing your firmwares.
- Click the drop-down to display your firmware list and select the new april.joystick firmware.
- In a few seconds, the imp will start to run the new firmware and the text in the planner will change to "APRIL JOYSTICK"