This past weekend I finally got around to playing with the "9 degrees of freedom" sensor board (SEN-10724) I'd purchased from sparkfun.com. I'm not sure if it makes sense to call it that, but what you get is a 3-axis gyro, a 3-axis accelerometer and a 3-axis magnetometer. The gyros give you information about rotational acceleration, the accelerometer measures linear acceleration, and the magnetometer works like a 3-axis compass.
The circuit off to the side there shows how I managed to get it hooked up and talking through my Arduino UNO. The short of it is this: it's a 3.3V device (well, 3 devices) and it needs pull-up resistors (I used 4.7K) on the data and clock lines in order to function. It's wired up to the analog inputs 4 and 5 on the Arduino board, which is what the provided "Wire" library uses to talk to devices like this, that use the I2C protocol.
Honestly, I'm a little bit unclear as to how it's actually able to talk to the sensor stick/IMU (inertial measurement unit) without doing level conversion between the 5V Arduino and the 3.3V IMU, but it does seem to work reliably in this configuration. If I were doing something more significant (a production board, for example) I'd probably be a bit more careful about matching the signal levels.
The Wire library for Arduino is just a basic library for talking to I2C devices. Getting into the specific interfaces is another matter, though for a quick start, I used the HMC588L compass library provided by Love Electronics in the UK. This was enough to get me started and verify that I was able to communicate with the magnetometer. There's a pretty decent tutorial on that page on how to use the library, though the sample works pretty well as-is. If you have trouble compiling the sample code, I found that for some reason it has a period (".") at the very beginning of the file - remove that period to make it compile.
Quick update - looking at the example .pde file in linux using hd (hex dump), it turned out there were three unprintable characters at the beginning of the file. The easiest way I found to fix the problem was to remove any odd characters before the /* at the start of the file, then save it as a new sketch. That new .pde file can then be used to replace the original example .pde file in the library, or you can just use the fixed version in your sketchbook.
hey thx man! i think ur blog will help me a lot ^^
ReplyDelete