Realtime Graphing of Accelerometer/Gyroscope Data

During my naive days as a university student the only time I graphed data was when some professor required a graph in the lab report. Back in those days I always just looked at the numbers to see what what was happening. It wasn’t until I worked on much more complex real world problems that I admitted graphing the data can help. It’s ironic that as I’ve become a better engineer I’ve realized how important it is to take advantage of every crutch I can fine. These days I graph just about every kind of data I see. Want to know when all the office birthdays are? Let me graph that out for you…

Graphing data lets my mind understand what is happening much faster/better the raw numbers. I know there are some less experienced programmers/engineers that need to learn this. The holy grail for software is real time graphing of the data your application is using. So often people add this sort of feature in at the end, but I think there are benefits to doing it first since it reduces debugging time. At my job we have a whole team dedicated to real time graphing of the data processed by our 3D graphics processors. I am always extra friendly to the people on this team because I fully realize how much easier they make my job. In short I’m a graphing fan boy so it should be no surprise that I wrote some graphing software for my hobby projects. I did this as the first step in a much larger autonomous flying vehicle project that I’m working on.

Since my ultimate goal is a flying vehicle I knew I’d need an inertia measurement unit (IMU). I wanted something with accelerometers to measure acceleration and gyroscopes to measure rotation. After some research I found the ADXL330 is a good accelerometer and the IDG300 is a good gyroscope. I use this Sparkfun 5 degrees of freedom (DOF) device that has both of these chips integrated onto a single small board. These chips measure acceleration along all three axises (x,y,z) and the gryroscopes measures pitch and roll. This means I am missing yaw, but I decided I can add an electronic compass in the future to get this data. I have an Arduino so that is the microcontroller I used.

With all the hardware figured out I already knew that taking this many inputs into a project and expecting it to do what I want was not going to happen on my first try. So to make the debugging less frustrating I decided to graph out all these signals. I will probably add some derived data to these graphs in the future as I get further on this project, but I think it makes sense to share this simple version of the generic graphing software before things get overly complicated.

I used the open source Arduino SDK to compile the code for my microcontroller. Here is the code I wrote for the Arduino. This code reads the sensors and then writes this data onto the serial bus. This software lets you figure out the frequency you want to refresh this data and then will sample the sensors as many times as it can while hitting this refresh frequency. Multisampling helps reduce sensor noise. The reason I didn’t want to send every sensor value over the serial bus is because that it too much data. For my uses I limited the refresh frequency to 100 times per second.

The graphing was done with the open source Processing language. I had never used Processing before, but I found it very easy to use and in a few hundred lines of code got some pretty nice graphing functionality. In a nutshell Processing is a java based language with a bunch of drawing and IO helper functions. Here is the graphing code I wrote for Processing. Besides graphing the data in real time, this software also supports logging all the data to a file and applying a smoothing filter to the data. I wrote this code pretty cleanly so it should be easy to add and remove more data to the graphs.

Here’s a movie of me shaking the sensors in a few different directions and you can see the graphs react accordingly. I’ll let you derive your own conclusions, but it looks like I have a good deal of work ahead of me.

Comments (1)

Camera Axe

Camera Axe is open hardware and open software project that helps you get some of those difficult to capture photographs. It can use various sensors like light triggers and sound triggers to activate a camera or a flash. Here are a few sample images of the things this hardware has captured.

Here is a gallery with more pretty pictures. I apologize that some of them are a little blurry. I dropped and damaged my flash about a week ago and don’t have the funds to buy a new one right now. The flash now does a few micro pre-flash outputs before the full flash is triggered. This is is why some of the images have a weaker ghost images in them causing a blurry appearance.

These are just a few images I’ve used to test this software/hardware. The possible uses range from taking pictures of wildlife while you’re not there to photographing a bullet piercing an apple. The fact that everything is open source offers advantages over solutions that are being sold today (beyond the cheaper price). As an example lets say you want to take pictures of wildlife at sunrise/sunset. You could modify the software so the light sensor only actives the camera at light levels that represent sunrise/sunset and then you could use the microphone to actually detect animal movement. Since the hardware is easily understood you can add new sensors as needed, one sensor I’ve thought about making is piezo pressure sensor.

Camera Axe Component List

Here is a list of the components you need to make Camera Axe.

Sparkfun
Break Away Headers $2.50
Mini Push Button Switch $0.35
Serial Enabled 16×2 LCD $24.95
16 MHZ Crystal $1.50
ATmega328 with Arduino Bootloader $5.50
DIP Sockets Solder Tail – 28-Pin 0.3″ $1.50
5V Voltage Regulator $1.25
Optoisolator with Darlington Driver – 1 Channel $1.25
0.1 uF Capacitor (4) $1.00
22 pF Capacitor (2) $0.50
10 uF Capacitor (3) $1.35
RF Link 2400bps Receiver – 315MHz $4.95
3-Pin Screw Terminals 3.5mm Pitch (2) $3.00
Super Bright LED – Green (4) $3.80
DIP Sockets Solder Tail – 8-Pin $1.50
Diode Rectifier – 1A 50V (2) $0.30
Custom Circuit Board PCB $21.43
Mouser
NPN Transistor (2) $0.54
Plastic Enclosure $7.62
3.5 mm Audio Jack (4) $1.40
Push Button Switch (6) $7.80
1M Ohm Potentiometer $0.90
Op Amp $0.33
9V Battery Holder $1.05
1/4 Watt Resistors * 47 (1) * 220 (4) * 1K (1) * 10K (14) * 100K (1) $2.52
McMasters Carr
#2 Spacer – 3/16″ OD, 3/16″ LENGTH (4) $1.04
#4 Spacer – 3/16″ OD, 5/16″ Length (4) $1.16
Undersized 4-40 Nut (4) $3.28
Undersized 2/56 Nut (4) $5.23
2-56 Bolt – 5/8″ Length (4) $4.64
4-40 Bolt – 3/4″ Length (4) $5.09
Total Cost $119.23

Getting the bill of material cost significantly under $70 should be pretty easy if anyone want to make 10’s of these. Many of the parts above start significant volume discounts at pretty low quantities. Also some of the hardware from McMasters I only needed 4 of something but I had to buy a pack of 100 so building multiple (or finding a supplier where you could buy 4) would decrease the price by about $15. You could reduce the cost the the PCB from $21.43 to about $6.50 if you ordered them in quantities of 17 from BatchPCB’s supplier Gold PhoenixPCB (I’d really suggest using BatchPCB until you know what you’re doing). Lastly, redesigning the board to use surface mounted parts would lead to large cost savings.

Camera Axe Hardware

I designed this circuit and PCB board in Eagle. Eagle is a powerful circuit and PCB design tool. You can get a free version for non-commercial use. This is the first PCB I ever designed and must say that Eagle combined with these four great Sparkfun tutorials (1, 2, 3, 4) really got me up to speed. I then sent my design to BatchPCB. It took a little over a month to get my test board back, but it worked great. Here are my eagle files for this project and the Girber files I sent to BatchPCB. If you install the free version of Eagle you can look at and modify my schematic and board layout. Below is a picture of this boards schematic for those who don’t want to install Eagle to look at it.

Being my first board I made a few mistakes with the PCB that I’ll correct if I ever print more boards. Luckily all my mistakes were minor and the board I printed works fine.

  • Rename “Light” to “Sensor” on the silkscreen since that is a better description.
  • One of the bolt holes is one grid point off center so I should make sure all the bolt holds are centered.
  • I should label the value of the Potentiometer on the silkscreen (1M ohm).
  • The silkscreen for the RF receiver is missing +5 for one of it’s pins.
  • The LEDs are too bright and the 220 ohm resistors should be replaced with something larger.
  • The schematic is correct, but the parts I used for the focus and shutter are ECB transistors.  These have an odd pin layout for transistors (1=emitter, 2=collector, 3=base).  Switch these to a normal transistor (1=collector, 2=base, 3=emitter).

After I got the PCB back, it was just a matter of soldering all the components in place. If others want to build this and want more detailed directions on soldering the circuit board components into place, I may be willing to write an instruction guide to assist in this.



Enclosure

To make the enclosure I designed the holds I needed to drill and the few places I needed to cut with my Dremel in Inkscape. Then I just printed that out onto some sticky paper and had the pattern I needed to cut out on the box. This worked out pretty slick. Here is the cutout pattern I designed (drill/cut template, final sticker template).



Software

I used an ATMega328 with the Arduino bootloader for my microcontroller. This means I could use the very popular and easy to use open source Arduino development environment. I used version 0014, but newer versions are usually backwards compatible with older ones. You can download the Arduino development software here.

In order to download software to this board you will need this programming dongle.

Here is the software I wrote for this project. I’ve created this video that demonstrates some of the features of this software.

Flash Trigger

Female Hotshoe (Cheaper ones available, but this one has is good quality) $16.50
3.5 mm Extension Cord $5.24
External Flash (I assume you already have one)
Total Cost $21.74

This allows you to plug the flash into Camera Axe. While Camera Axe can trigger your camera directly, if you need an instantaneous capture you should use the flash. This page gives the expected shutter lag for many cameras. The flash reacts to it’s triggering in well under a millisecond.

Notice: Camera Axe assumes you have an EOS compatible flash. Some older flashes use high voltages to trigger them. If you use one of these high voltage flash units you will likely blow Camera Axe’s optoisolater and need to replace it. I use a Canon 580EX flash, but there are many other options. Here is a list of flashes that should be safe.

Camera Trigger

Plug to trigger your camera (Price varies by plug (see below) under $5.00
Audio cord with 3.5 mm plug $3.15
Total Cost $8.15

The higher end Canon DSLR cameras (20D, 30D, 40D, 50D, 5D, 1D) have a a special Canon Plug called N3. I have not been able to find this plug for sale anywhere, but you can buy a cheap Chinese trigger for these cameras on Ebay for under $5 and use the N3 plug from it. I have a 30D so this is what I demonstrate here. Canon’s lower end cameras (300D, 500D, 1000D) use the much cheaper and easier to get 2.5 mm jack. I’m not sure what Nikon use, but I’m sure a little research will figure that out.

Sound Sensor

Electret Microphone $0.95
Audio cord with 3.5 mm plug $3.15
Total Cost $4.10

Electret microphones like this need some serious amplification. Luckily I put all that amplification on Camera Axe’s PCB. You can adjust the sensitivity of the microphone with the potentiometer on Camera Axe’s PCB. Just play with it until you find a sensitivity you like.

Light Sensor

Photo Transistor $0.42
Audio cord with 3.5 mm plug $3.15
Total Cost $3.57

Most photo transistors filter out visible light and only trigger on IR light. I did some searching and found this one that triggers on visible and IR light. This is nice because one of the uses I had for this was to use it in conjunction with a cheap $5 laser pointer (search Google or Amazon) to create a laser trigger. All you do is point the laser at this and when the beam is broken you trigger the camera or flash.

Another good use of the this sensor is taking pictures of lightning. It will make getting night time lightning less work and you can even get daytime lightning which is something human reflexes can’t manage.

Remote Control

RF Link Transmitter – 315MHz $3.95
Other parts ???
Total Cost ???

I put a receiver in Camera Axe so I could trigger it remotely. The transmitter I put in along with this receiver should have a range of about 200 ft, but I have not verified this distance yet. I did verify the remote works at closer ranges by putting together a breadboard circuit to verify it. The circuit is extremely simple since this device just needs power, ground, and a serial transmit wire to send the it the signal. Maybe I’ll make a nice remote someday, but until then you’ll need to design your own if you need this feature. Here is the Arduino software I used to test this feature.

Comments (13)

DIY Outdoor Time-Lapse Photography

Update: Check out my latest Camera Axe project for a much more robust device that handles this.

There is a beautiful overlook of Worcester Massachusetts near my home.  I wanted to build a weatherproof camera box that automatically takes one picture an hour so I can make a time lapse video of the changing seasons.  One requirement was to keep it cheap and already had a Fuji F30 point and shoot camera.  If I had a Canon Powershot I would have used CHDK, but instead I hacked this together using an Arduino and my F30 camera.

The basic premise is to run an Arduino as a timer and once an hour it turns on a relay.  The reason for the relay is minimize power usage while the Arduino is running as a timer.  When the relay is powered up the servo and camera also get turned on. Then the Arduino uses a servo to turn on the camera and take a picture.  A 5 volt regulator is used to make sure the system could provide enough current to the servo and camera.  After seeing how little current my camera draws, I realized I could have used the 5 volt regulator on the Ardunio board, but the regulator is cheap so there is no harm in using it like I did.  You want to make sure the coil on the 5 volt relay you choose uses less than 40 mA or you will exceed the max current draw from an Arduino pin which could damage the Arduino after extended use.  If you want to use a relay with a greater than 40 mA current draw you should use a circuit like I described in this article.

This project only cost me $20 for the cheap lawn mower battery because I already had the camera, Ardunio, servo, 5v regulator, power plug, wire, wood, and paint. If you had just the camera and Arduino then a trip to Radio Shack and Home Depot would get you the parts you need for about $25.

Here is a block diagraph showing my system.

Here is a test video I made with it. The software I used to splice together the jpg images was the free JPGVideo. The video was just a quick indoor test of the system. I set it to take a picture every two minutes and it took about six hours for the ice to melt. This gave me about 180 images that I converted to this video. Next, I am going to use it to record a hardwood floor installation and then I’m going to setup outside to record the seasons. If I get any really cool videos I’ll try to update this article with them later.

Some of the most interesting data I collected during this project was the current use from the 12 volt battery.  The current draw when the relay is off is only around 0.07 mA.  I had no idea the Arduino used so little power (0.84 mW)!  The current draw when the relay and servo are on is around 210 mA.  The current draw with the relay, servo, and camera is around 300 mA. But remember these higher current draws only happens for a few seconds while you are taking a picture.

Below are some picture of the box I made. Note that these pictures were taken before I put on a plexiglass cover over the camera.  You can see I put a cheap lawnmower battery in there.  I’m not sure how long it will last, but I ran it for over 2 weeks and everything is still fine.  I suspect it would run much longer.  Just doing some napkin calculations yield 0.07 mA * 24 + 300 mA * 20/60/60*24 = 42 mA per day.  These batteries don’t say how many Amp hours they hold, but I’d be shocked if it’s under 10 which gives me 238 days of use.  This doesn’t matter to me though since my memory cards need to be swapped out every 2 weeks.  Another option for longer run times would be attaching a small solar panel to this system.

Here is the Arduino code I used:

// Maurice Ribble
// 3-5-2009
// http://www.glacialwanderer.com/hobbyrobotics
// This program uses a servo to triger a camera to take a picture every x minutes.
// The code depends on the built in servo library.  Arduino version 0013 has it.

#include 

// This is the pin you need to attach the servo to (only 9 and 10 are valid)
#define SERVO_PIN           9
#define RELAY_PIN           2

// These are the servo values that correspond to camera controls
// These will need adjusting for each setup
#define CAMERA_ON           100
#define CAMERA_PIC          80
#define CAMERA_NUEUTRAL     90

#define MINUTES_BETWEEN_PICS 1

Servo g_servo;

void setup()
{
  pinMode(SERVO_PIN, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);

  // Use serial to help debug
  //Serial.begin(9600);
  //Serial.println("Setup");
}

void loop()
{
  static int minutes = MINUTES_BETWEEN_PICS; // Start with a picture so we know it's working

  if (minutes >= MINUTES_BETWEEN_PICS)
  {
    digitalWrite(RELAY_PIN, HIGH);
    g_servo.attach(SERVO_PIN);
    g_servo.write(CAMERA_ON);
    delay(5000);
    g_servo.write(CAMERA_PIC);
    delay(5000);
    g_servo.write(CAMERA_ON);  // My camera turns off if you press on again
    delay(5000);
    g_servo.write(CAMERA_NUEUTRAL);
    delay(1000);
    g_servo.detach();
    digitalWrite(RELAY_PIN, LOW);

    delay(44000);
    minutes = 1;
  }
  else
  {
    delay(60000);
    ++minutes;
  }
}

One future improvement I might make is to add a light sensor so I can take pictures only during a sunset. Anyone else have other ides for improvements? Let a comment with your ideas.

I left out some of the details like the power plugs I used for my camera because every camera will be different, but if you have questions just ask and I’ll do my best to answer them.

Comments (9)

Build Your Own Electric Spinning Wheel

If you want to buy a this machine rather than build it, check out my storefront to see if I’m currently selling any.  If I’m not you can email me about buying one.  Otherwise keep reading for details on how to build your own.

This article is dedicated to Emily.  Without her love of spinning and knitting wool I wouldn’t have had willing test subject for my wacky spinning wheel contraptions.

Intro to Basic Spinning Wheel Mechanics

All spinning wheels have a bobbin and a flyer.  The bobbin holds the spun yarn and the flyer is what twists the yarn onto the bobbin.  The big drive wheel on non-electric spinning wheels is just there to help spin the flyer faster.  The electric spinning wheel is much smaller because a small electric motor spins fast enough to eliminate the need for the big drive wheel.

There are a wide variety of spinning wheels.  The one I choose to make is the Scotch Tension design.  This version uses a brake on the bobbin to control how fast the uptake of the yarn happens.  The uptake of the yarn is how fast it is put onto the bobbin.  A slower uptake means the yarn will have more twists per foot.  Different types of yarn require different amounts of twisting.

This simplification leaves a lot out and you can read more about spinning wheels on Wikipedia or by searching google.

The main advantage to an electric spinning wheel is that it can be made smaller and is thus more portable.  Another advantage is that getting a good well balanced mechanical spinning wheel can be tricky and an unbalanced wheel isn’t as easy or fast to use.  I’ve found that electrical ones can be built for between $50 and $150.  Mass produced electrical spinning wheels cost $2000 and cheap looking pvc ebay models sell for $300-$500.  I really feel this market is being exploited and it would be awesome if this article starts a little more competition.

Overview Iterations

Like most engineering problems it took me a few iterations to get everything working well.  Below are the five versions it took me to get everything working well.

One

This version was never completed.  It never spun any wool, but it helped me understand the workings of the bobbin and flyer.

Two

The second iteration worked well and it cost me around $50.  It used a cheap surplus AC motor.  The big problem was that this version was it was constant speed and Emily wanted it to go a little faster.  I tried adding a resistor based dimmer switch to my system to control speed of the motor.  The dimmer switch’s packaging specifically said not to use it with motors.  While I thought I knew better, but it turned out that I didn’t.  I seemed like it was going to work, but after a little while the switch released it’s magic smoke molecules.  If you don’t need variable speed I’d suggest getting an AC motor like this.  At $10 this motor is a steal.  You can use a standard lighting switch to turn it on and off.  I also wired in a switch to reverse the motor which can be useful since you spin yarn in one direction and then ply strands of yarn together in the other direction.

Three

This version changed to an AC sewing machine motor so that we’d have variable speed and I made a nice box to make it more portable.  I used this $35 sewing machine motor.  The problem is that the AC motor did not have enough torque at lower speeds.  I knew that AC motors didn’t have as much torque as DC motors at slow speeds, but thought that it would be good enough.  I was wrong.  I’m sure some a bigger AC motor would work, but this one did not cut it.  At high speeds it worked fine because there was more torque, but high speeds were too fast for an mortal spinner’s hands.  It was amusing watching Emily try and keep up with the high speeds :-)

Four

Version four used this dc motor, power supply, and motor controller.  I had avoided DC because it’s more expensive, but it’s still only around $100 with these parts and I’m sure with some searching cheaper parts could be found.  One issue I had to solve is that the motor controller by default pulsed at 260 hz which gave caused an annoying hum.  I increased the pulse frequency on the motor controller so it was outside the human hearing range by replacing the 470K ohm R5 resistor with a 47K ohm resistor.  In theory this reduced the efficiency of the motor, but it still seemed to have enough power for my needs.  This version worked fine for a few minutes and then the magic smoke molecules were released.  I never liked this motor controller so my next version needed to buff up the motor controller.

Five

I kept the box the same as my last version.  All I did was change to using the SyRen 10A motor controller and put this battery in parallel with the power supply.  The reason I put the battery in parallel is to protect and sink the energy from the SyRen regenerative motor driver.  Here is a good tutorial with a little more info about this. An added benefit of the battery is you can use the spinning wheel for an hour or two in remote locations.  This has turned out to be very useful for Emily.  I’ve been extremely happy with the SyRen motor controller and if I ever need a high quality motor controller in the future I’ll certainly consider using this or one of the other SyRen controllers.

The best news is that this version of the electronic spinning wheel works great!  Here is a video of Emily using it.

Electric Spinning Wheel Design

The motor and electronics I used are linked above.  I used these pulleys (smaller, bigger) from McMaster.  I also order these aluminum pipes (smaller, bigger).  The rest is just wood, bolts, washers, a spacer, an elastic strap, glue, and 6 inches of 1/8×3/4″ aluminum bar.  I got all this stuff from Home Depot.  I estimate the total cost to be around $150 and this would be less if you built more than one since there is a lot of extra material left after the build.  I’m also sure I could find cheaper versions of many of the parts if I did more searching.

Here is a diagram of the my electric spinning wheel.

Flyer Design

The bobbin can freely spin on the flyer.  If there was no brake on the bobbin then it would spin at the same speed as the flyer and the yarn would get very twisty, but it would never get put onto the bobbin.  The scotch tension brake causes the bobin to spin more slowly than the flyer allowing some twist to the yarn and some uptake.  Uptake is the term of the yarn getting pulled onto the bobbin.  If you applied a full break so the bobin never spun then there would only be uptake and the yarn would have no twists which would also not work.  Spinners know that they need to adjust the Stotch tension brake to get a good mix of uptake and twist.  The less twists in the yarn the fluffier it is.  Knitters will want different amounts of twists in their yarn depending on what they are knitting.

Here is a diagram and picture the explains my flyer/bobbin design.

That should do it.  If you have any questions let me know in the comments secontion and I’ll try to answer them.

Update

I’ve made some improvements by adding nylon bushings, a box to hold the electronics, and a redesign of the frame.  Here are some pictures.

The last picture shows how I added some straps to the frame.  This makes the electric spinning wheel extremely easy to move.  This has been a big plus with spinners who often what to move it around.

Here is a video showing how to use the spinning wheel.


Here is a video showing how to setup and adjust the spinning wheel.

New part list:

There are nylon bushings that I got from home depot.  These are embedded into the box to help reduce noise.  They are 3/8 inch long, have in inner diameter of 1/2 and an outer diameter of 1 inch.  The important part here is the inner diameter and the other 2 dimensions could change if needed.  I had to cut out a notch so the pipe that holds the bobbin could slide into these.

The bobbins are no longer made using aluminum pipe.  They use 2 short pieces of this nylon tubing as spacers.  You need to run a 1/2 inch drill threw these spacers a few times so they spin freely on the 1/2 aluminum pipe.  Then these spacers are glued into this larger nylon tubing.  Then just like before you put some wooden circles onto the bobbin and your done.

Comments (35)

Rube Goldberg Card Suffling Failure

“I have not failed.  I’ve just found 10,000 ways that won’t work.” ~Thomas Edison

At my real-pay-me-to-solve-problems job, failure happens from time to time.  As an engineer it’s important to recognize when a problem can’t be solved in a reasonable manor.  Obviously the more important the problem, the higher the criteria for “reasonable”.  It’s not surprising to me that some of my hobby projects don’t work out.  Heck, it would be boring if everything just worked.  I’ve decided to share this learning experience with others.

The goal of this project was to design a card shuffling machine.  The topic came up when a friend informed me that there are two categories  of shuffling devices on the market.  The cheap $20 plastic shufflers you can find at Target, and the $1500+ professional solutions.  Both systems are fairly controlled systems, and I thought it would be more interesting to take a Rube Goldberg approach. My card shuffling machine used physical environmental factors (ie air flow) to randomize the cards.  In a nutshell my idea was to use a big fan to blow a deck of cards around in a box similar to how those bingo or Powerball lottery machines work.  Then after the cards had been randomized I’d have a series of shoots, doors and sensors to get all the cards face down in a nice stack.

I made a prototype of what I thought would work.  Here is a video describing how it works.

Here is a link to a higher quality downloadable video.

To get things working reliably I’d need to do a few more iterations of the slides and figure out how to make a small, powerful and cheap fan. I have ideas on how to get around all my known problems, but I believe solving all the problems could turn into a much bigger effort than I had expected when I started this project.  Basically I’ve decided I’m not interested enough in this problem to work through these problems I’ve found.

I have a lot of other things I’d like to work on so instead of focusing on this project, I’ve decided to cut my losses and move on to other things.  If anybody else decides to pick up this project and improves on it let me know.  I’d love to hear about any related past or future projects. I was surprised that my google searches didn’t turn up any projects like this.

Comments (8)

« Previous entries Next Page » Next Page »