Adafruit LSM9DS0 9-DOF Port to SPARK

Hi All!

I am starting off my Spark adventure with trying to get the 9-DOF Adafruit LSM9DS0 (http://www.adafruit.com/products/2021?&main_page=product_info&products_id=2021) to work on Spark.

I realize that I cannot take the Adafruit libraries 1:1 to Spark (I got the SSD1306 OLED to work through the ported files on this forum - thanks!), but I am hoping the problems I am currently having in compiling are simply related to including other dependent libraries in the wrong way.

Reading https://learn.adafruit.com/adafruit-lsm9ds0-accelerometer-gyro-magnetometer-9-dof-breakouts/wiring-and-test it seems like I need the following libraries:

So I have copy-pasted these files into the IDE environment, now having:

  • Adafruit_Sensor.cpp
  • Adafruit_Sensor.h
  • Adafruit_LSM9DS0.cpp
  • Adafruit_LSM9DS0.h
  • lsm9doftest.ino

I followed the example of another thread to replace “Arduino.h” in the listed files above with:
define ARDUINO_H
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
…but I hasn’t resolved all my issues.

I removed the “Wire.h” file believing it is part of Spark environment anyway, and I removed “SPI.h” since I am using I2C.
#include <Wire.h>
#include <SPI.h>

I am a bit skeptical to #include “avr/pgmspace.h” in the "Adafruit_Sensor.cpp, mainly because I don’t know what it does (flash related??).

I am just brushing off my Very old C++ programming skills, so bare with me…

Files can be found here: https://github.com/heon74/LSM9DS0_9DOF:

When I compile I get errors as below…can anyone point me in the right direction?

Thanks!

In file included from Adafruit_LSM9DS0.cpp:15:0:
Adafruit_LSM9DS0.h:194:27: error: ‘boolean’ has not been declared
void write8 ( boolean type, byte reg, byte value );
^
Adafruit_LSM9DS0.h:194:41: error: ‘byte’ has not been declared
void write8 ( boolean type, byte reg, byte value );
^
Adafruit_LSM9DS0.h:194:51: error: ‘byte’ has not been declared
void write8 ( boolean type, byte reg, byte value );
^
Adafruit_LSM9DS0.h:195:5: error: ‘byte’ does not name a type
byte read8 ( boolean type, byte reg);
^
Adafruit_LSM9DS0.h:196:5: error: ‘byte’ does not name a type
byte readBuffer ( boolean type, byte reg, byte len, uint8_t buffer);
^
Adafruit_LSM9DS0.h:247:5: error: ‘boolean’ does not name a type
boolean _i2c;
^
Adafruit_LSM9DS0.h: In member function 'virtual void Adafruit_LSM9DS0::Sensor::getEvent(sensors_event_t
)’:
Adafruit_LSM9DS0.h:226:46: error: ‘millis’ was not declared in this scope
(_parent->*_eventFunc)(event, millis());
^
Adafruit_LSM9DS0.cpp: In constructor ‘Adafruit_LSM9DS0::Adafruit_LSM9DS0(int32_t)’:
Adafruit_LSM9DS0.cpp:22:3: error: ‘_i2c’ was not declared in this scope
_i2c = true;
^
Adafruit_LSM9DS0.cpp: In constructor ‘Adafruit_LSM9DS0::Adafruit_LSM9DS0(int8_t, int8_t, int32_t)’:
Adafruit_LSM9DS0.cpp:34:3: error: ‘_i2c’ was not declared in this scope
_i2c = false;
^

Hi @heon74,

Please read the thread on Forum Tips to learn how to paste code in the forum with properly formatting. :wink:

I’ll try porting this library and post the results here


UPDATE

I managed to fix most errors and left with one issue. The library uses a specific SPI Control Register in Arduino and makes it hard to fix

Adafruit_LSM9DS0.cpp: In member function 'bool Adafruit_LSM9DS0::begin()':
Adafruit_LSM9DS0.cpp:80:16: error: 'SPCR' was not declared in this scope
     SPCRback = SPCR;
                ^
Adafruit_LSM9DS0.cpp: In member function 'void Adafruit_LSM9DS0::write8(bool, byte, byte)':
Adafruit_LSM9DS0.cpp:366:18: error: 'SPCR' was not declared in this scope
       SPCRback = SPCR;
                  ^
Adafruit_LSM9DS0.cpp:375:7: error: 'SPCR' was not declared in this scope
       SPCR = SPCRback;
       ^
Adafruit_LSM9DS0.cpp: In member function 'byte Adafruit_LSM9DS0::readBuffer(bool, byte, byte, uint8_t*)':
Adafruit_LSM9DS0.cpp:416:18: error: 'SPCR' was not declared in this scope
       SPCRback = SPCR;
                  ^
Adafruit_LSM9DS0.cpp:427:7: error: 'SPCR' was not declared in this scope
       SPCR = SPCRback;
       ^
make: *** [Adafruit_LSM9DS0.o] Error 1

I have digged the STM32 SPI registers a little but there’s nothing directly compatible.

This might take some time to fix…

Instead of wasting time, I have commented out the SPI code for now

You should see the library in the Web IDE under ADAFRUIT_LSM9DS0

So for now, only I2C would work.

Let me know how it goes :wink:

Sweet!!

The only thing I had to do in order to make it compile was to remove “Adafruit_LSM9DS0/” in the include PATH “Adafruit_LSM9DS0/Adafruit_LSM9DS0.h” in the .ino file.

See successful result below - I appreciate your help, I and will take your advise and read the formatting rules!

1 Like

I am having the same issue here with lsm9ds0
Am using intel edison board
And an important fact that i would like to share that am a starter in cpp
@heon74 do you mind sharing the details… if Makefile is availble that would be so much helpful to me…

expecting you reply soon…