Monday, February 14, 2011

Accelerometer & Compass

No, it's not a B/W TV from the 50's. However Felix the Cat was one of the very first images transmitted to a TV screen.

I wanted to mess around with an accelerometer and this is what I came up with - before getting waylaid making Geiger Counter Kits.

From the beginning, I have to say that this was one of the most frustrating projects I've ever worked on. I consider myself a "completer" but several times, I had the desire to just dump the damn thing in a box, and say to hell with it. I'll try to spare the details of that side of the project.

I had a few goals in mind:
  • to learn about accelerometer and compass modules
  • to make a LiPo battery operated project
  • to use a graphic LCD and a menu system
  • and maybe make something I could put in my car
Lets start with the battery side of the thing. I wanted to be able to charge the LiPo, and I also wanted a constant 3.3V for Vcc and the Aref voltage. For the LiPo charger I used a MAX1555 wired per the datasheet.

Since the voltage on a LiPo can vary on both sides of 3.3V (3.0-3.7V), I decided I needed a "buck-boost regulating charge pump". (It's possible I didn't need one, but the name was so cool . . ..) I discovered the MAX1759 and also wired it per the datasheet. Soldering the tiny uMax package to a piece of proto board was an exercise in tedium.

I didn't want a toggle or slide power switch. I wanted a push button On/Off and I also wanted to Pololu Pushbutton Power Switch - it does all those things. I am working on a homemade version of this switch using an ATtiny85 that I will post here soon.  I added an ATmega328, with all pins broken out, and LCD and FTDI connectors.
automatically power it off from the uC if there was no movement for awhile. And of course, I didn't want to use much power to monitor the switch when the power was off. The solution was the

At last! A shield that actually looks like a shield! This round board fits over this square board. After cutting two notches in it to access the LCD and FTDI connectors it was actually fit for a Gladiator - at least until I added the HMC6352 compass (I2C), MMA7361 accelerometer (analog) and DS1621 temperature sensor (I2C).

Finally, the graphic LCD and joystick. After a few flaky Nokia cell phone faceplates, I got a less flaky version of the Nokia 5110 graphic LCD. For the joystick I used a neat trick I learned from nuelectronics that switches resistors with the joystick so the 5 positions can be sensed by only one analogue input.

A wise man once told me "a project is only as good as it's case". (Actually no one told me that.) Long ago, I made a faceplate out of copper clad PCB board. Why not a whole case? 3D soldering! I also had some vintage phenolic board and some copper foil. I cut the copper clad board and mitered the edges. I soldered the box up from the inside. It solders very well. (I cranked up the iron to 425C.) I used the copper foil to attach and solder the phenolic board on the bottom. In a lot of ways, the case was the most rewarding part of the project. If there's anything worth learning here, this technique might be it.

So that's the hardware side. I'm less proud of the software side. I discovered that coding for the accelerometer and compass quickly make you wish you didn't sleep on your desk during geometry. In addition there's the low pass filtering, running average and . . . the dreaded Kalman filter (actually I didn't use one). I'll post the code at the end here, but if your smart, you won't download it. The menu system is sorta nice though. I got the basis from nuelectronics. I also wrote some simple graphic utilities.

Functionally - well, it needs some work, but he's a rundown of the screens . . .

The main menu . . .
(The accelerometer screen is boring. So is Debug.) The calibrate screen calibrates the compass - 2 revolutions in 20sec.

The compass screen shows degrees and ordinals.
There is also a temperature display.

The performance screen shows acceleration (right of center) and deceleration (left of center.)
The line through the bar sticks at the max recorded.

The roll and pitch screen shows, you know what.

Here's the sketch.


  1. My your fast! I'm just typing this up now!
    For now, you can find some here . . .

  2. The case looks great. I love the look of that old stuff, it's pretty stylish.

  3. Thanks Justin.
    Yes, it's a little "Jules Verne" - steampunk.
    I think the technique has lots of possibilities.

  4. I'm glad you posted some info on an accelerometer to the Arduino. I was planning on posting a tutorial about the ADXL345. However, I have already posted a tutorial on the IDG500 to the Arduino here:

  5. nice post, some photos are missing

    1. Thanks. Didn't see any missing photos on this post but I'll try another machine.

  6. There are certainly a variety of particulars like that to take into consideration. That could be a great point to convey up. I supply the ideas above as common inspiration however clearly there are questions just like the one you carry up the place crucial factor will likely be working in honest good faith. I don?t know if best practices have emerged round things like that, however I'm sure that your job is clearly recognized as a fair game. Both boys and girls feel the affect of just a second’s pleasure, for the remainder of their lives. casino play