Shop OBEX P1 Docs P2 Docs Learn Events
Simple Library for LSM9DS1 IMU ported to SPIN — Parallax Forums

Simple Library for LSM9DS1 IMU ported to SPIN

Hi all,

Off and on for the past month or so, I've been trying to convert Parallax's C library for their LSM9DS1 module to SPIN. I think this was mostly to scratch an itch, at first, but it felt rewarding to reach "milestones" throughout the conversion process (not having any prior experience transpiling code to SPIN, or having any real experience talking to a device over SPI, for instance), so I stuck with it and now have something that works for each sensor within the IMU.

I can't find where I got the original C code from now, though could have sworn it was in the Simple Library before. It is a "Test Harness" written by Matthew Matz. During the conversion process, I created and used a separate object (lsm9ds1-test-methods.spin) to test each method, one at a time, until its output was the same as the original C version's, as built in SimpleIDE. I'd originally intended to just discard it once the Test Harness was complete, but I've decided to include it, since I see value in using it as a tool to just display live data from the IMU.

To try either object, you'd have to of course change the constants that define the pin assignments for the IMU (and the LED's, if you wish). I've also included an archive of both the test harness code as well as the method test code I used during the development to make it easier for others to use. Note that I don't yet have an object written, meant to be used as a "drop-in" child object to a top-level project (think "imu.start", "imu.readGyro", etc). At the moment, it is just a 1:1 conversion of the original C test harness. The methods are all work-alikes of the original C functions, with the same names.

I realize code to support some (or all) of the basic functionality of the IMU may have already been written by someone in SPIN, but I couldn't find it at the time I started this.

I owe a lot of thanks to Dave Hein for cspin, as it made converting the code far quicker than I could have done by hand! Also Brett Weir, for the SPIN Standard Library, something I like the idea of (along the lines of a "Gold Standard" that comes up in discussions here from time to time) and of course PropellerIDE.

So in case anyone finds it useful, the code lives at https://github.com/avsa242/lsm9ds1-spin

Cheers,
Jesse

Comments

Sign In or Register to comment.