Archive for June, 2009

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 (26)

Camera Axe

I made a new version of Camera AxeHere is my store where I sell them.

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. (UPDATE: Here is are some new photos I shot once I got my flash repaired. And here are some more.)

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 (76)