In Learning to Use I2C and Magnetometer not fried, I talked about interfacing the MAG3110 magnetometer and MQA8452Q accelerometer to an Arduino. For both, I’m using breakout boards from Sparkfun Electronics.
I checked today that there are no problems when I connect both devices to the same I2C bus.
The first test was very simple: I put both the breakout boards into a breadboard and wired them together, then tried running each of the programs I’d written for the chips separately. Result: no problems—worked first time.
I then tried merging the programs (cleaning up any naming conflicts) so that both could be run from the same code. After a few typo fixes, this also worked fine
I think I’m now ready to hand over the software to the students to use for their robot.
I still need to put the i2c.h, i2c.cpp, and accel_magnet code in some public place for others to use (perhaps on github? maybe on my web pages at work?) [UPDATE 2012-jan-31: I have put the libraries and the sample code for the accelerometer and magnetometer at http://users.soe.ucsc.edu/~karplus/Arduino/]
One thing that is still missing is doing tilt correction for the compass heading. Since the ROV is not expected to remain level (the accelerometer is intended to be used in a feedback loop to adjust the pitch, with anything from -90° to +90° being reasonable), getting a good compass heading requires rotating the magnetometer readings into the horizontal plane. Only one of the students in the robotics club has had trigonometry or matrix math, so I’ll have to work with him to get him to figure out how to do the tilt correction. It may be simplest conceptually to compute pitch and roll angles first, then rotate twice, rather than trying to do the whole tilt correction in one step (especially since the Arduino does not have matrix libraries).
- Learning to use I2C (gasstationwithoutpumps.wordpress.com)
- Soldering problems (gasstationwithoutpumps.wordpress.com)
- Magnetometer was not fried (gasstationwithoutpumps.wordpress.com)
- Tilt compensation when reading a digital compass (hackaday.com)
Tagged: accelerometer, Arduino, I²C, magnetometer, robotics, SparkFun, SparkFun Electronics
[original story: Gas station without pumps]