Monday, May 28, 2012

Sunday, June 20, 2010

3D Video on the Cheap

So the other day I was thinking about how 3D images are put together because we got a new 3D TV at work. It occurred to me that I had all the crap at home to build a small 3D video rig myself since over the last several years both of my daughters asked for and got some cheap Flip Video cameras. They're the original Flip Video camera, the 640x480 25fps ones.

I went to Pini's Hardware and picked up a few items to build a small stereo camera rig. It's comprised of a piece of cheap wood (a wooden garden stake), some half inch wooden dowel, some quarter inch furniture glides and some T-nut fasteners.

I assembled them like this:





It turns out the that "camera shoe" bolt is really just a standard 1/4" bolt and you can go to the hardware store and get a bolt that'll mount a camera anywhere.  It's not some special format like I thought maybe it was.

Here's what I bought at Pini's.  I got enough stuff to make two of these (or screw up one and make one good one, which is generally how I roll.)


Hit "Read More" to hear all about it and see some sample movies.


Sunday, February 21, 2010

The Brushduino

Ever have an idea that people tell you "you should TOTALLY patent that!" Well, I did, and they did, and I thought about it... but instead I decided to open source the whole thing. It seemed like kind of an obvious idea to me and going after a patent made me feel kind of greedy. Besides, all of my prototyping was done with open source tools!

Anyways, I hope someone can improve upon this. I think it's a useful thing.

The Story

My daughters don't brush their teeth long enough, if left to their own devices. When my wife or I brush their teeth, we do a nice thorough job that takes a little while but when the girls do it themselves, they tend to cut it short. Timing them doesn't help, as they just stand there and chit-chat until the timer goes off. It's not that they don't brush their teeth LONG enough, it's that they don't brush their teeth WELL enough.

It occurred to me that if could make something that monitored how WELL they brush their teeth---and maybe even guided them through the process a little---then they'd eventually establish better habits for the future. I started thinking about what I could build that would help them and settled on the notion that an accelerometer was the perfect sort of thing to keep tabs on what constitutes a brush "stroke" while they're in there brushing their teeth. All I'd need to do is come up with a little hardware and software to make it happen.

About the Hardware

For my birthday last year, I got myself an Arduino starter kit from www.adafruit.com and hadn't used it for anything yet. I was curious about the Arduino platform and have read a lot about it. I figured it was time to build something on it and this toothbrush thing seemed like the perfect fit.



I started looking for a low-cost accelerometer I could base my project on. I found one with a breakout board on Adafruit and one on Sparkfun but I didn't want to spend that much. Plus, it needed to be small---I wanted this thing to fit on the end of a toothbrush. I continued scouring the web and found this article over on Hack a Day for Digital Dice. This was based around the Freescale MMA7260QT and he fearlessly did all of the fine soldering work himself. I figured I could do that too. I ordered up a couple of MMA7260QT's from Mouser and a couple of the MMA7368LT's (BGA package version) and set to work with 30 AWG tynar coated solid core wire. This stuff is usually used for wire-wrapping, but I like to use it for low-current point to point stuff and general purpose project wire.

I wired one of the MMA7368LT's up to a .1" pin header so I could start experimenting.



It's pretty fiddly work and requires lots of swearing. I drink a lot of caffeine, which makes it even harder. I recommend finding great inner peace before you begin. Some solder paste also helps.




I got everything going with the Arduino just jumpering things around and with a bit of breadboard. It all went very quickly compared thanks to the Arduino environment which took care of a lot of the usual setup I normally go through (soldering up a voltage regulator, breaking out the SPI pins for programming AVR chips, setting fuses, burn-and-test-and-burn-and-test, etc.) It was nice!

If the Arduino is the brain of this project and the accelerometer is the eyes, then the Adafruit ProtoShield is the heart. It's only like $13 and it's brilliant.


It's basically all LED's. There are 6 white LED's that correspond to the six regions of the mouth that I want to highlight, there are four green LED's for showing progress and there's a speaker I pulled out of some broken toy that's there to entertain the children while they brush. The multi-strand wire connected to the three analog inputs on the Arduino also supplies 3.3v and ground to the accelerometer. The cable itself is an old ADB keyboard cable from my old Mac SE/30 from back in the day. It's been laying in my junk box for ages. There are also some current limiting resistors for the LED's and a bunch more of that lovely AWG30 solid core wire I like so much.

At the toothbrush end of the cable, I encased the whole thing in hot glue to keep it safe from water and from yanking by children:

This "puck" on the end was meant to be attached to the toothbrush handle via some mechanism (I ended up using rubber bands, which was only somewhat successful and I hope to improve upon) and held in the user's hands.

For an enclosure, I used a cool plastic enclosure I got from PAC TEC a few years ago as a free sample. It was perfect for housing the Arduino with attached ProtoShield and had a 9 Volt Battery compartment too. I had to modify the battery compartment and I added a barrel connector so I didn't have to solder to the Arduino at all.

To allow the indicator lights to show through the case to the front and still remain waterproof, I used some more hot glue. I drilled holes roughly the size of the LED's directly above where they would fall once installed in the case, filled the holes with hot glue, and snipped off the tops and bottoms to be flush against the case on the top side and flush against the LED's on the bottom side. For the reset button, I used the same technique, but lubricated the hole so the hot glue piece can slide up and down. It all proved to be pretty water tight and while the hot glue is a little opaque, it's clear enough to transfer the light up to the surface where they can see it. It's a sort of a "light pipe" type of thing.

Above you can see the barrel connector for the arduino peeking out and the SPST slide switch I installed in the side of the case.

I repurposed some orange suction cups from a cheap nerf hoop knockoff toy I got as a Christmas present one year to stick the enclosure to the girls' mirror in the bathroom to keep it at eye level and keep it out of the water.

Here it is installed over their sink:


When you fire it up, it plays the opening bars of the Super Mario Brothers theme song while randomly flashing the white LED's. Then it starts instructing on what area of the mouth to brush.


I draw a mouth on a piece of paper and glue-stick it to the front. That way I can rotate the pictures out and keep them funny/interesting. The green LED that's lit rotates around between the four as each "stroke" is counted. A "stroke" is defined as hard acceleration in one direction followed by hard acceleration in the opposite direction within a specified time window. I tweaked the parameters of what defines a "stroke" until I got pretty good results. It still picks up false strokes when they're moving the toothbrush around but it does a pretty good job. At least---good enough for this purpose.


Each time a section of the mouth has been brushed sufficiently (stroke count was based on experimentation and dentist recommendations) a few more bars of the Super Mario Brothers theme song is played (along with light show) and then the next white LED starts flashing. It's easier to see the pattern than it is to describe it. The section they're supposed to be brushing at any point in time is blinking with the already-brushed portions of the mouth lit fully on.

Here's a video of the whole process with me fake-brushing my way through it. Pardon the nausea-cam photography, I couldn't find my little tabletop tripod.


video

It works pretty well! And my first Arduino project was a smashing success. Let's hear it for easy floating point number support on microcontrollers.

My next step is to replace that puck of hot glue on the end with a Sugru "cup" that they stick on the end of the toothbrush. I was lucky enough to get some Sugru for Christmas (actually, after Christmas) and have been itching to use it for something electronic. For those not familiar with Sugru, it's an air-curing silicone putty made by a snazzy little outfit in the UK.


I'll post again once I have the Sugru version going. I just ripped out of few of the wires to the accelerometer when cutting the hot glue off so I have to go back to the workshop for a while. :-/

Eventually I'll replace the Arduino with a couple of voltage regulators, a pushbutton and an ATmega328 and make this piece of hardware fully "legit." Or maybe I won't.

About the Software

Coding for Arduino is easy-cheesy compared to working directly with WinAVR or Atmel's AVR Studio. For one thing, you get printf() which is HUGE! I used LED indicators to debug previously. Being able to log output to a scrollback is an immense boon. It's really pretty luxurious! The Arduino environment is basically a front end for a WinAVR backend and it also gives you some pretty awesome libraries to use straight out of the box.

For the software, I needed to light pretty lights, play pretty music and most importantly count brush strokes.

For those of you who have worked with three axis accelerometers, you know that gravity is always represented in the reading. To get a good sense of movement around three space, you need to subtract out the gravity component from the readings you're getting. This is harder than it sounds if you consider that in my case the toothbrush could be oriented any which way and therefore the gravity could be registering along any axis or any combination of axes.

To solve this problem, I turned to a cheap-o solution which is to use a sort of bargain basement "high pass filter" to remove the gravity component. Since gravity is going to be constant, it stands to reason that whatever elements of motion that the accelerometer is registering, the ones that have been going on for a long time (low frequency data) should be ignored while the recent and rapid changes (high frequency data) should be allowed to go through for analysis. I did a little searching around and found a small Objective C code snippet in the iPhone developers' realm that did just the thing I needed... simulated a high pass filter:


// Read the 3 axes analog values from the accelerometer
int rawX = analogRead(analogXPin) - 512;    // read the value from the sensor
int rawY = analogRead(analogYPin) - 512;    // read the value from the sensor
int rawZ = analogRead(analogZPin) - 512;    // read the value from the sensor

// Our High Pass filter works better with signed floating point values
float floatX = (float)rawX,
floatY = (float)rawY,
floatZ = (float)rawZ;

// Low pass filter
float kFilteringFactor = 0.1f;

// We're keeping 90% of the rolling value and adding in 10% of the new value each
// time. This filters out recent values and retains historical values.
rollingX = (floatX * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
rollingY = (floatY * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor));
rollingZ = (floatZ * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));

// High pass filter

// Now we remove the historical values to emphasize current values more.  The high
// pass filter helps us remove gravity from the reading so we can get orientation-
// independent acceleration values from the device
accelX = floatX - rollingX;
accelY = floatY - rollingY;
accelZ = floatZ - rollingZ;



My processed ( accelX, accelY, accelZ ) vector now represents interesting accelerometer values to feed into a little stroke counter routine.

For the music side of the project, I found the Arduino Playground "freqout()" function, which I modified to handle rests and a wider range of note values. I then found someone's sheet music transcription of the Super Mario Brothers theme song and converted it to data.

Here's the full source code of the Arduino sketch. This was compiled against arduino-0017 but should work with the latest too. Full source after the break below:

Tuesday, March 24, 2009

Happy Ada Lovelace Day!

From PedgeBank:

http://www.pledgebank.com/AdaLovelaceDay

Ada Lovelace Day is an international day of blogging to draw attention to women excelling in technology.

Women's contributions often go unacknowledged, their innovations seldom mentioned, their faces rarely recognised. We want you to tell the world about these unsung heroines. Whatever she does, whether she is a sysadmin or a tech entrepreneur, a programmer or a designer, developing software or hardware, a tech journalist or a tech consultant, we want to celebrate her achievements.

It doesn't matter how new or old your blog is, what gender you are, what language you blog in, or what you normally blog about - everyone is invited to take part. All you need to do is sign up to this pledge and then publish your blog post any time on Tuesday 24th March 2009. If you're going to be away that day, feel free to write your post in advance and set your blogging system to publish it that day. We will gather as many of the posts together on the day as we can, and we'll let you know exactly how we're going to do that nearer the time.

For ongoing updates about Ada Lovelace day, please follow us on Twitter, join our mailing list or see our blog.

http://findingada.com/

http://twitter.com/FindingAda

http://groups.yahoo.com/group/findingada

Who was Ada?
Ada Lovelace was one of the world's first computer programmers, and one of the first people to see computers as more than just a machine for doing sums. She wrote programmes for Charles Babbage's Analytical Engine, a general-purpose computing machine, despite the fact that it was never built. She also wrote the very first description of a computer and of software. Anything wrong with this pledge? Tell us!

Tuesday, December 4, 2007

Lucky's Beepy Ball II!

UPDATE! Scroll to the bottom to see the results of the first trial run!

My dog is blind. Well, mostly blind---he can see a few feet and light and dark---but for most intents and purposes, he's blind. He's not blind in old age, but blind congenitally---he's only 3. His name is Lucky. As a golden retriever, he's obsessed with getting, keeping, carrying, fetching a ball shaped object of any sort. I set out to make a ball that beeps that he can find easily since his hearing is very acute now that he's been fully blind for a while.

I scratched my original design for the Lucky Beepy Ball that was built around a LM556 timer chip and a handful of components (four resistors, two capacitors, and two signal transistors) as being a little too heavyweight for putting inside a ball. I did a lot of head scratching, reading, and doing other builds to learn more and finally settled on a very simple design: 1 ATtiny13V microcontroller, one piezo speaker, a small battery, and a switch. You can't get too much simpler than that.

The Atmel ATtiny13V was PERFECT for this job, as it had a low pin count (it's an 8 pin ATtiny) and operated well in a wide range of voltages. It can operate normally at between 1.8v and 5.5v (the 'V' model of the ATtiny13 is the low voltage version) and is plenty fast (I run mine at 4.8MHz on the internal oscillator). Best of all, it can source and sink at least 20mA on its digital output pins, and has a nice 8 bit timer built in that is easy to program for interesting bleepy sounds.

First I prototyped my design on a small piece of breadboard. All the ATtiny13V REALLY needs is the Vcc connection on pin 8, the GND connection on pin 4, and the two legs of the piezo speaker on pins 2 and 3, but I used the breadboard as my programming harness as well so you can see the 6 pin ISP header at the top. It took a little experimentation to get the beep sound the way I wanted it.

I wanted a beep sound that was easily audible by a dog under a lot of conditions. I figured a chirp would probably work the best. It would start at a high frequency above human hearing but dog-audible, and then decrease in frequency over time until it got low enough so that the wavelength was long enough to have good travel properties through tall grass. Long wavelength sound travels greater distances and can pass through solid objects better than short wavelength sound, so I wanted to take advantage of this property. I wanted alternating periods of chirping and silence so that it was easier for Lucky to triangulate the position of the sound. With a constant chirping, I was concerned that the sound reflection would interfere with his ability to locate the source.

20071126110347833_1_original.jpg

Here are the parts all laid out and ready to assemble. This build was going to be free-formed (point to point wiring) instead of boarded on a piece of experimenters board/veroboard since it needs to be compact and fit inside a ball or Kong ball of some kind.

20071126110347833_2_original.jpg

After programming the ATtiny13V with my chirpy sound code, I ruthlessly hacked its legs off with a wire nipper. This was surprisingly painful for me to do... there's something about defacing a MCU that physically hurts. I wanted unused pins to be out of the way to reduce the possibility of a short and to keep them from interfering with other parts as I put everything together.

20071126110347833_3_original.jpg

The battery I'm using is a 2.4v NiMH battery that I salvaged out of a tiny radio controlled car (one of those Hot Wheels-sized radio control cars that you dock with the transmitter to charge it.) I hadn't used the radio control car much before it broke, so I took it all apart and saved a few select pieces from it. This battery only stores 70mAh worth of charge, but then I don't anticipate that the ATtiny13V and the piezo are going to really need all that much. Plus it was the perfect size. I soldered right onto it at each end.

20071126110347833_4_original.jpg

I brought the positive lead from the "bottom" of the battery up to the center pole on the SPDT switch so I can turn this thing off when we're done playing ball. I soldered the switch's metal housing directly to the negative side of the battery by using a little liquid solder flux (I have a solder flux pen I use for things like this) to get everything to stick.

20071126110347833_5_original.jpg

Next, I mounted the ATtiny13V directly on the switch, soldering the Vcc pin (pin 8) directly to one side of the switch. Then I soldered the GND pin (pin 4) directly to the metal housing. Pins 2 and 3 that you can see in the right hand picture are going to be wired up to the piezo speaker.

20071126110347833_6_original.jpg

Here the speaker is wired to the MCU and the wiring is done.

20071126110347833_7_original.jpg

Now it's time to hot glue this mess to make it more shock resistant and to keep everything in place. I'm using a typical craft hot glue gun to turn this all into a big capsule shaped insert that I can put inside a "Kong" brand dog toy to play fetch with.

20071126110347833_8_original.jpg

... to be continued ...

 

Spooky Halloween Light Dimmer

Here's a quickie image gallery of my Halloween Door Light Dimmer system I cobbled together for a spooky Halloween gag.

The basic idea is that I'd use a distance sensor to spot people walking up the sidewalk to my house and slowly dim the lights as they get closer and closer. When they're standing there at the door, I wanted them to be surrounded by almost-darkness with the white christmas lights flickering dimly while I handed out candy.

To achieve this effect, I knew I'd need a reliable distance sensor that could spot a humanoid/child up to 20 feet away and then I'd need some way to control lights running off of AC current.

I sought out the MaxBotics MaxSonar EZ-1 board to handle the distance sensing (http://www.maxbotix.com/MaxSonar-EZ1__FAQ.html). It's a clever single-board controller for a 40kHz ultrasonic transducer. It uses a single-transducer model rather than the two-sensor style of Devantech's. I've never used a Devantech sensor, but the MaxBotics model fit my budget and was carried by SparkFun, so I ordered it up.

The controller board supports three different output formats for distance sensing information: Serial, PWM, and analog. I chose to use the analog output and the ATmega8's built-in ADC to get my distance information.

20071102102103855_1_original.jpg

Here are the subsystems, labelled for your protection.

20071102102103855_2_original.jpg

Here's the outlet box I built. With the help of the guy at Pini's Hardware here in town, I got it up to building code as well as getting it functional. It's four separate lines on the four outlets.

There was something extremely satisfying about labeling the outlets "BIT 0" and "BIT1" and so on. They were just bits on one of the ATmega8's output ports!

20071102102103855_3_original.jpg
Outlet Box

For controlling the lights, I checked out some options out there for controlling house current from TTL that use triacs and optocouplers. One of the better ones I found was the SEMITONE "Open Dimmer" project. http://semitone.sourceforge.net/wiki/index.php/Main_Page

Rather than take chances on my first foray into house current, though, I opted to buy a pre-made board. One of my favorite electronics suppliers, Futurlec, had a great board they made themselves. It was cheap at $25.

http://www.futurlec.com/AC_Opto_Output_4.shtml

I doubted I could make one as cheaply and the construction seemed very solid and had just what I needed. It's driven by TTL signals and has two separate connectors for interfacing to your uC board. It's optically isolated, fuse-protected, and uses screw terminals for my AC lines. Perfect!

20071102102103855_4_original.jpg


Relay Board

Here's a picture of the MaxBotics sonar range finder, on the left, and the 8 LED debugging output device on the right. I plug a ribbon cable with 8 SMD LED's with 1k SMD current limiting resistors wired to common ground with one LED per bit on PORTB of the ATmega8. I write to these bits to help debug things.

20071102102103855_5_original.jpg

Here's a closeup of the transducer:

20071102102103855_6_original.jpg

Here's the ATmega8 controller board I use for most of my projects. Click on it for the Really Big version.

20071102102103855_7_original.jpg

And here it is again with ports labelled.

20071102102103855_8_original.jpg

Because I got started late, I had to do the build in 2 days (actually two evenings, and one morning) and got it working Halloween morning at 9:45am--just in time to scoot off to work.

I think it was a big success. My Halloween guests were suitably baffled by the inexplicably dimming and flashing lights and it created a great atmosphere for handing out treats.

...and I didn't manage to burn the house down or sustain a filling-rattling electric shock in the process. Always a plus! ·

Pumpkinlight!

I put together a simple AVR-based device to stand in for the tried-and-true pumpkin candle this year. It uses two high-output (12,000 mcd) white LED's driven (a little too hard) by a regulated 5v supply that's shared with an ATtiny13v. All of this runs off of a 9v battery and should last for days given the tiny amount of current it draws.

The bill of materials isn't super long, and I had everything on hand so putting it together was pretty easy. I free-formed the first one, wrote the AVR Studio assembly code, then went back and made a proper schematic and built the second one. The first one is a lot uglier than the second due to all the rework and the extra wiring for the ISP connection.

C1 10uF
C2 100uF
G1 AB9V
IC1 ATTINY13V-10PU
IC2 LMS8117AMP-ADJ
LED1 High output white 5mm
LED2 High output white 5mm
R1 150
R2 470
R3 120
R4 120
R5 10k This is a 10k for a pull-up on the RESET pin
S1 Small SPDT sliding switch
T1 2N3904 Any small signal transistor will do
T2 2N3904 I used the 2N3904 because I have a big bag of them

Here are all of the materials required, assembled in marching order:

20071018173736317_1_original.jpg
Here's the schematic:

20071018173736317_2.gif

Here's the finished product (the second one... after I knew what I was doing. My layout still sucks, but it all fits and is fairly orderly.)

20071018173736317_3.jpg