Some people find inertial sensors confusing. They work like magic, measuring unseen forces.
Of course, accelerometers measure accelerations. I dare you to tell someone that and not have one of you feel like an idiot. The eye-glazing should be well on its way by the time you get to magnetometers and how they measure magnetic force.
I wanted a gadget that I could use to explain the differences between accelerometers, gyroscopes (angular rate sensors), and magnetometers. I had an Adafruit IMU sitting on my desk (bought on spec for a client who abandoned it). I'm pretty sure I can find a way to shed some light on how these sensors are used.
I got the system working a while ago. But I'm going to take it apart today.
I put together the system with an Arduino UNO, the IMU, and BlinkM. I added a USB battery power supply.
There are four modes: accelerometer, gyro (rate sensor), magnetometer, and off.
In accelerometer mode, X is red, Y is green, Z is blue. (The XYZ -> RGB transform is consistent through the entire project.) When you set it on the table, it glows steady. When you move it gently, there is a change but the primary color is in the direction of gravity.
Initially, I used an accelerometer double tap to change modes. Not only was this unreliable, it meant I couldn't show what the accelerometer sees when you tap it: usually an impulse of light, often white, sometimes a little directional.
I switched to a button. That also meant I did not need to use my modified sensor code, I could use the Adafruit 9-DOF Arduino code directly.
So a button press takes me to gyro mode (rate sensor mode) and suddenly the device goes dark.
Oh, I forgot to mention the housing. I fussed about that in my last project post so it seems like I should give an update. I put it in a tennis ball canister. (My beagle was pleased to receive the leavings from that purchase.) And then I put paper around the outside to diffuse the light.
The good news is that this all fits. The bad news is that it barely fits. I've scraped my hand a few times trying to get it in place. The worse news is that with all those things packed in, the impact of the light is lost a little. There are lots of shadows on the outside making it even more difficult to see except in very low-light conditions. It loses something from my original concept (which was a ring, I should remind you.)
Back to gyro mode: it is dark until you move it. Unlike accelerometers with their persistent pointing toward the earth and occasional blip from you, gyros are only interesting when you move them. By turning or swinging the can, I can show X, Y, and Z as RGB. Also, it becomes much more difficult to get white out of the light. (I'm still dizzy from trying.)
Pushing the button (it is pretty small, a friend saw this demo and didn't know how I was doing it, was confused about the mode switches. This is good because I want this to seem sort of like a magic trick but back because she was more focused on that than the explanations. Also, I put the button on the X axis for the sensor so it is easy for me to find (Z is the long ways on the canister)....
Let me try that again: Pushing the button again puts you in magnetometer mode. This is the naming inspiration (North Star). When you are facing north, the light is white, east is green and west is red. South is dark. I use tilt compensated magnetometer heading (oh Adafruit, thank you for making those calculations readable!).
However, with the too big battery and too big board, I'm not happy with the project. I got a BLENano for work and have an extra one. I plan to redo it with that and a small battery, maybe I can get rid of the shadows. Given the size... maybe it is small enough... hmmm...
Oh, and yes, I do plan to use the BLE part of the Nano. I have some ideas for Python scripts that plot accel, gyro, mags in real time. Ah, who am I kidding? I wrote some scripts for work and plan to rewrite them for you.
I know my second project log is not where I'm supposed to say "I chose the wrong parts" but realistically, this project is based on scraps on my desk. Of course those were the wrong parts. Sometimes that's all you have. Naw, let me rephrase to be more honest: usually the wrong parts are the only ones you have. Engineering means carrying on.
Though my issue seems to be the large battery won't fit in my box with its cable plugged in.
Yes, the battery came off my desk, the MEMS Industry Group has nice giveaways. This USB rechargeable 2500mAh battery seemed like a good way to avoid charging issues. Plus, it can supply that monstrously bright BlinkM MaxM. And it fits in the box, just not with the cable attached.
I suppose, really, there is no reason to use the MaxM other than its awesome (blinding) power. I could use the MinM that is on my breadboard for testing. Or I could use a NeoPixel like all the cool kids do. Or I could do something simpler (cheaper) and use an RGB led with PWM control. I have both 5V and 3V versions of those around here somewhere and I have plenty of pins on the board to do the drive.
Really, I have too many pins. The Arduino board is overkill. I started out with the Trinket but decided its ATTiny meant more time optimizing and less time making it do what I want. On the other hand, there is the Trinket Pro. It seems like the best of both worlds.
Of course, at that point, with a smaller LED, smaller board, along with the IMU that was already reasonably small... well, at that point we are looking at pocket monster territory. I've heard something about pockets and Trinket Pros. Hmm... I wonder where that was.
I suppose after I finish this Lantern of Inertial Awesomeness, I'll make the Tinkerbell version, possibly even carry it to amaze potential clients. But not quite yet. I'll use the parts I have to do this thing, maybe I'll pretend I'm on Junkyard Wars and my desk is, well, the junkyard. That comparison is more apt than I'd like to admit so I'll slink off to write some code now.
I ordered an Adafruit 9-DOF IMU board for a client who went on holiday vacation before signing the contract so now I've got this board burning a hole in my pocket. Given how much I spent at their site, Adafruit sent along a free Trinket board. At the same time, I was starting slides for a presentation entitled "Introduction to Inertial" and working out scheduling details to have ThingM's Tod Kurt on our Embedded podcast. Combine all these things and what do you get?
One thing you don't get is something that will easily fit on a ring. Still, if it could, what would I want it to do? Maybe I'll even get boards made...
The idea stemmed from a magnetometer first. I've read about anklets with several cell-phone motors and a magnetometer that subtly teaches you which way is north. I'd love a little ring that glowed white when I was facing north, red when west, and green for east. It would be dark for south. It would be a neat little beacon.
Never mind that the almost-always-on LED will drain a battery fairly quickly so ring mounted will need to be easily rechargeable. Never mind that I'll need an accelerometer to tilt compensate the magnetometer (oh! must add why to the presentation!). Of course, adding an accel does give me a way to turn it off and on.
Well, if I'm to make the ring, I need to write the code. Hardware is not my forte but if I get it working well, I can probably get help laying out an ATtiny and a magnetometer/accelerometer chip. Though, as long as I've got a whole IMU to play with, I might as well use it all.
I spent a few days stripping the Adafruit sensor code of anything I considered unnecessary (floating point? gone! functions that make the sensors interface generic? gone!) so it would fit on the ATtiny in the Trinket (5000 bytes of code space! whee!). And then I wised up and realized I was going to spend all my time making atan2 tables, I should do the prototype on a regular Arduino.
It is funny how 32k feels HUGE and the ATmega is blazingly fast compared to the ATtiny. I stopped rewriting the Adafruit code and started writing the code I wanted. This was a good decision as it gives me more time to play (and since that's what this is for me, making it seem like work was a good way to get frustrated and move on to another, more fun project).
I think the accelerometer mode should be the simplest. It should glow red if gravity is felt in the X direction (positive or negative), green if Y, blue if Z. This would let me talk about how accelerometers are used as gravity sensors the majority of the time. While free fall detection and actual acceleration are interesting, mostly we want our devices to know which way is down. (Since I'll use double taps to move between accel, gyro, mag, and off modes, discussing gestures will be natural.)
For the gyro mode, the LED will light proportionally to how fast the rate sensors see movement. This will go nicely with my notes about how rate sensors are only useful when things are moving.
The mag mode will be the North Star implementation I described before.
I started out wanting a ring on a Trinket. Now I want a multi feature demo tool in a box.