Arduino-powered Bionic Leg
Origins
In the summer of 2015, I tore my ACL doing judo, which led to surgery, which led to me wearing a full-leg brace for a few weeks. When I went back to work, more than one person commented that the brace looked cybernetic, and that it would be cool if it lit up and made some robot noises. I had been looking for a good maker project to get into, and so the bionic leg project was born. |
What does it do?
As of this writing, it has two functions: to light up LEDs and to play robot noises. Both those functions are triggered by motion, which is detected by an accelerometer. It also has a master control switch to turn it on and off, and it plays power-up/power-down noises when the master switch is toggled. It does have a third, minor function which is looking really, really cool. |
Here's a demonstration of the functionality. I go through turning it on, showing the lights/sounds triggered by motion, and then muting/unmuting it. The red flash indicates when mute has been toggled.
How do I make one?
The rest of this page is dedicated to detailing how I modified the brace. It's not in Instructables-level detail, but it should be a good jumping-off point if you'd like to make something similar for yourself.
The rest of this page is dedicated to detailing how I modified the brace. It's not in Instructables-level detail, but it should be a good jumping-off point if you'd like to make something similar for yourself.
Materials
Electronics
Besides the brace, I sourced all of these from Adafruit.
|
Tools
Links are just for reference. Use what you've got or what you can find easily.
|
Decorative Components This section is optional - do what you'd like to decorate. This is what I used.
|
Wiring Diagram
Creating the Sub-components
Before you begin, it's important to choose the placement of the Flora, as that will affect the wiring of the other gadgets. I put mine on one of the Velcro straps on the lower leg:
Step 1: Attaching the accelerometer
I chose to attach the accelerometer right next to the Flora. With the way the Velcro strap works, it ends up on the back of my calf, where it will move a lot in relation to the rest of my leg. I started off by sewing the connections, but ended up abandoning that because the Velcro straps are really difficult to sew to. There's a layer of adhesive between the two Velcro layers that makes it really difficult to get a needle through. I ended up bypassing the sewn connections with regular stranded-core wire, although I left the sewn connections as fasteners.
Connections :
I chose to attach the accelerometer right next to the Flora. With the way the Velcro strap works, it ends up on the back of my calf, where it will move a lot in relation to the rest of my leg. I started off by sewing the connections, but ended up abandoning that because the Velcro straps are really difficult to sew to. There's a layer of adhesive between the two Velcro layers that makes it really difficult to get a needle through. I ended up bypassing the sewn connections with regular stranded-core wire, although I left the sewn connections as fasteners.
Connections :
Accelerometer |
Flora |
SCL |
SCL |
SDA |
SDA |
3V |
3V |
GND |
GND |
Step 2: Wiring the LED string
The first thing to do is to actually create the strand of LEDs. (If you're using a regular strand of LEDs that actually comes in a string, you can skip to the next part. This only applies if you're using the little sewable single-pixel Neopixels).
The wiring for these guys is dead simple: wire all the positive pads together in series, the ground pads together in series, and the signal pads together in series. The only thing you have to make sure of is that the signal line runs in the same direction through all the pixels. There's a little arrow silkscreened onto each pixel - make sure they all face the same way along the line. Adafruit has some excellent tutorials on how to wire Neopixels if you're confused. You should end up with a strand of LEDs like this:
The first thing to do is to actually create the strand of LEDs. (If you're using a regular strand of LEDs that actually comes in a string, you can skip to the next part. This only applies if you're using the little sewable single-pixel Neopixels).
The wiring for these guys is dead simple: wire all the positive pads together in series, the ground pads together in series, and the signal pads together in series. The only thing you have to make sure of is that the signal line runs in the same direction through all the pixels. There's a little arrow silkscreened onto each pixel - make sure they all face the same way along the line. Adafruit has some excellent tutorials on how to wire Neopixels if you're confused. You should end up with a strand of LEDs like this:
With just 5 LEDs, it's fine to run the strip off of the 3V pin. If you have any more than 10 or so, you'll want to get a level shifter to bring it up to 5V. I would recommend powering up the Flora and loading one of Adafruit's example sketches from the Neopixel library to test your wiring. The library can be found here: https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library. That page also has lots of guidelines to handle Neopixels in general. They recommend putting a capacitor across the + and - lines and a resistor on the signal line, but...I didn't do that, and nothing exploded :).
Connections:
Connections:
LED strip |
Flora |
GND |
GND (any one will do) |
+ |
3v3 |
Signal |
TX( D1) |
Step 3: Wiring the sound unit
The best guide for wiring the sound unit and amplifier is this one from Adafruit: https://learn.adafruit.com/wearable-flora-powered-tardis-costume-dogs/wiring. The only thing that's different in this project is that I omitted the wire going from DREQ on the sound board to SCL on the Flora. For some reason, that connection (which I believe is to handle interrupts) prevented the sound board from ever initializing, so I couldn't play any sounds at all when it was connected. The downside of leaving it out is that you can't stop a sound in the middle - it queues sounds one after the other, rather than playing them simultaneously. For my purposes, this wasn't a deal-breaker.
I attached the sound unit to the inside of one of the side struts of my brace. I sewed the corners of both the sound board and the amplifier to the foam padding on the inside of the knee brace:
The best guide for wiring the sound unit and amplifier is this one from Adafruit: https://learn.adafruit.com/wearable-flora-powered-tardis-costume-dogs/wiring. The only thing that's different in this project is that I omitted the wire going from DREQ on the sound board to SCL on the Flora. For some reason, that connection (which I believe is to handle interrupts) prevented the sound board from ever initializing, so I couldn't play any sounds at all when it was connected. The downside of leaving it out is that you can't stop a sound in the middle - it queues sounds one after the other, rather than playing them simultaneously. For my purposes, this wasn't a deal-breaker.
I attached the sound unit to the inside of one of the side struts of my brace. I sewed the corners of both the sound board and the amplifier to the foam padding on the inside of the knee brace:
I also attached the speaker to the amplifier at this point. Since the amplifier comes with a screw terminal, it's really easy to just attach one speaker wire to the positive connection and one to the negative.
Connections:
Connections:
Amplifier |
Sound board |
L+ |
LOUT |
R+ |
ROUT |
L- |
GND |
R- |
GND |
At this point, it would be a really good idea to load up a few sample sketches and make sure all the components are working properly. I also tested the battery to make sure it could handle all of the components at once. If you are using a battery, make sure to flip the switch on the Flora itself to let it accept non-USB power. It's a little black tab near where the battery plugs in.
You will also need to provide power and ground to the amplifier.
Connections:
Sound board |
Flora |
3v3 |
3v3 |
GND |
GND |
MISO |
MISO |
MOSI |
MOSI |
SCLK |
SCLK |
CS |
D10 |
SDCS |
D12 |
XDCS |
D6 |
Step 4: Wiring the push button
The last component to assemble is the lit power button. I wired mine so that the LED ring is on when the button is pressed, and off when it's released. It can also be wired the opposite way, or so that the LED is always on. This post has an actual wiring diagram: https://forums.adafruit.com/viewtopic.php?f=8&t=79448 I added a resistor to the + line, but to be perfectly honest, I can't remember why :).
Step 5: Adding support for two I2C devices
The Flora needs to communicate with two I2C devices: the accelerometer and the sound board. To make that work, you have to add two pull-up resistors, one from SCL to +V, and one from SDA to +V. I used two 10,000 ohm resistors soldered directly to the Flora.
Fabrication
Once all the electronics were working correctly, I started attaching them to the brace and making them look a bit cooler.
Speaker
The first thing I did was to mount the speaker directly on the knee joint. Since the amplifier was on the inside of the knee joint, I just pulled the speaker around to the other side of the strut. To attach it, I used one of the 5mm snaps. I superglued one side of the snap to the speaker back. Then I tried to superglue the other side of the snap to the outside of the hinge, but I was having trouble getting a good bond between the two surfaces. To fix that, I glued a tiny piece of felt to the hinge, and glued the snap to that instead. That gave it a pretty high profile, but it does work as a fastener now.
Speaker
The first thing I did was to mount the speaker directly on the knee joint. Since the amplifier was on the inside of the knee joint, I just pulled the speaker around to the other side of the strut. To attach it, I used one of the 5mm snaps. I superglued one side of the snap to the speaker back. Then I tried to superglue the other side of the snap to the outside of the hinge, but I was having trouble getting a good bond between the two surfaces. To fix that, I glued a tiny piece of felt to the hinge, and glued the snap to that instead. That gave it a pretty high profile, but it does work as a fastener now.
Button unit
The lit button is the only piece that has some real fabrication to it. To make the housing, I used the bottom of an empty water bottle that I had my husband spray paint matte black. I cut a hole in the bottom center of the bottle and pushed the button through it so friction held it in place. To get the whole assembly to fit to the frame, I had to shave off some of the plastic button casing, as well as small pieces of the water bottle so that it would all sit flat against one of the struts. This is the strut before/after from the inside of the brace:
To attach the whole assembly to the frame, I cut two pieces of wire hanger about 10 cm long. I cut four holes in the sides of the water bottle and pushed the pieces through them, sandwiching the strut between the wire pieces and the button assembly. They're just friction fit, but they're also not going anywhere. To disguise the wires, I took some silver acrylic paint and gave them a few coats. This is what the whole thing looks like from the outside:
LED strip
I decided to leave the LED strip only temporarily attached so that I could change its placement easily if I wanted to. I just attached tiny pieces of hook-side Velcro (cut off of one of the straps) to the backs of the first and last LEDs. Because there are plenty of places to attach Velcro to on the brace, I left long wires attached to the LED strip for maximum flexibility in placement. For the photos at the top of the page, I attached the strip to the outside of my lower leg.
I decided to leave the LED strip only temporarily attached so that I could change its placement easily if I wanted to. I just attached tiny pieces of hook-side Velcro (cut off of one of the straps) to the backs of the first and last LEDs. Because there are plenty of places to attach Velcro to on the brace, I left long wires attached to the LED strip for maximum flexibility in placement. For the photos at the top of the page, I attached the strip to the outside of my lower leg.
Wires
At this point, I had a whole bunch of loose wires running the length of my leg. To make that a little more photogenic (and safer!) I needed some cable ties. To get some suitably mechanized-looking ties, I dug up some silver twist ties and wrapped them around bundles of wires at about 15cm intervals. Those looked a bit too shiny, so I mixed some black acrylic paint with water and applied a few coats of that to each wrap, letting the paint dry in between every time. Here are two of the wraps with the paint wash applied:
At this point, I had a whole bunch of loose wires running the length of my leg. To make that a little more photogenic (and safer!) I needed some cable ties. To get some suitably mechanized-looking ties, I dug up some silver twist ties and wrapped them around bundles of wires at about 15cm intervals. Those looked a bit too shiny, so I mixed some black acrylic paint with water and applied a few coats of that to each wrap, letting the paint dry in between every time. Here are two of the wraps with the paint wash applied:
That's it for fabrication! The next step is to load the sounds up and write the code.
Media
I sourced my sounds from AudioJungle, one of Envato's daughter companies. They were about $1 apiece, and some of them came with multiple sounds per file. For the movement sounds, I used three sounds in the final project: a power-up noise, a power-down noise, and a motion noise.
The VS1053 library can only support file names up to 8 characters long. Rename your media files so that they have fewer than 8 characters and load them up on your SD card. Put the SD card into the slot for it on the VS1053 board.
The VS1053 library can only support file names up to 8 characters long. Rename your media files so that they have fewer than 8 characters and load them up on your SD card. Put the SD card into the slot for it on the VS1053 board.
Software
This was built with the Arduino IDE v. 1.6.4, available here: https://www.arduino.cc/en/Main/OldSoftwareReleases#previous. As of this writing, the most recent version is 1.6.7, but while I was developing, it was 1.6.6. I used 1.6.4 because they had made a lot of changes to the compiler with 1.6.6, and the sound card examples didn't play nicely with the new version. Adafruit customer service recommended downgrading to 1.6.5 or 1.6.4. (For the record, the error got while trying to compile any VS1053 project was:
Code Editor
Libraries
The libraries and sources I used are the following:
The libraries and sources I used are the following:
Library |
Source |
Wire |
Included with the Arduino IDE, but you may need to explicitly #include it in your main .ino file to get things to work. |
SPI |
Included with the Arduino IDE |
SD |
Included with the Arduino IDE |
Adafruit_VS1053 |
|
Adafruit_NeoPixel |
|
Adafruit_LSM303 |
And here's the code:
BionicLeg.ino
Tips and Tricks
In no particular order:
In no particular order:
- The VS1053 library can only support file names up to 8 characters. It won't warn you if the file name is too long, it just won't play the file. Keep that in mind when naming your files and putting them on the SD card!
- This project shares a lot of wiring in common with Adafruit's dog TARDIS costume project. It's worth a read if you don't understand what's going on here. (Linked above in sound board section).
- I recommend setting up and testing all of the components separately before trying to run them all togther. I set up the accelerometer first, then the NeoPixels, then the sound board.
- I believe that the sound interrupts are destined not to work reliably for the same reason that NeoPixels and servos don't play well togther. Long story short, the NeoPixels have very tight timing, and disable interrupts during data writes. The sound library relies on interrupts for some of its functions, so there are potential clashes happening all the time. The issue is well-documented here: https://learn.adafruit.com/neopixels-and-servos/overview
Thanks for reading! If you build something similar, I'd love to see it!