Adafruit I2C/Sensor/MMA8451 Library?

Sorry for my noob question.

I am trying to connect an Adafruit accelerometer breakout board (MMA8451 Triple Axis Accelerometer) to a Spark Core.

In their nice tutorial Adafruit mention 2 libraries

  1. MMA8451 library
  2. Adafruit_Sensor_Library

I think the Spark uses an ARM vs Arduino’s regular Atmel chips, so the architectures and hence libraries are not directly portable.

I did also see that the Spark build environment now has a whole bunch of libraries that kind people already ported (thank you, kind people :smile:)

It appears there is a slightly older version of the Adafruit sensor library there already, but not the MMA8451 accelerometer library. I suspect porting the latter is not a beginners project, although I am willing to spend some time on it to try. Is there some documentation in “porting libraries from Arduino to Spark” ?

Additional complication (perhaps, I really don’t know anything about I2C): this accelerometer apparently requires I2C with repeated-start support. Does the Spark have that (otherwise no point porting the library obviously)

Alternatively, if someone has already done this for the MMA8451, could I invite you to share the result on the Spark library ports ?

Thank you in advance
SparkToad

1 Like

There aren’t many differences between libraries. It’s probably easiest to learn by looking at a similar library that someone has already ported. Do you have a sensor to test with? I’ll see if I can do a quick and dirty port.

@SparkToad give this a try: https://github.com/mumblepins/Adafruit_MMA8451_Library. I haven’t yet published on the Web IDE, because I don’t know if it works yet, but it at least compiles, so that’s something. So if you could just add it to your code via the “contribute library” button, and don’t publish it, we’ll see if this works! For future reference, that was quite easy to convert. Mostly changing the includes, as the Wire code is included in the default Spark libraries, and instead of including “Arduino.h,” we include “application.h”

1 Like

I’m having troubles to instanciate the Adafruit_MMA8451 object in the application. The linker is giving to me this error:

…/src/application.cpp:44:55: error: invalid conversion from ‘Adafruit_MMA8451*’ to ‘int32_t {aka long int}’ [-fpermissive]
Adafruit_MMA8451 mma = new Adafruit_MMA8451(0x12345678);
^
In file included from …/src/application.cpp:28:0:
…/src/Adafruit_MMA8451.h:82:5: error: initializing argument 1 of ‘Adafruit_MMA8451::Adafruit_MMA8451(int32_t)’ [-fpermissive]
Adafruit_MMA8451(int32_t id );
^
make: *** [obj/src/application.o] Error 1

I’m trying to instantiating this way, because doing as it was specified in Adafruit’s Arduino made example didn’t work neither.

Doing it Adafruit’s way, the error I got was:

/home/aritz/Spark/core-firmware/build/…/src/application.cpp:44: undefined reference to `Adafruit_MMA8451::Adafruit_MMA8451(long)'
collect2: error: ld returned 1 exit status
make: *** [core-firmware.elf] Error 1

Does anyone have similar problems?? Or someone who already made it work, does anyone knows what may the problem be??

This is maybe a silly suggestion, I’m guessing – Hmm, did you try casting that value to an int32_t ?

Adafruit_MMA8451 mma = new Adafruit_MMA8451((int32_t)0x12345678);

Thanks,
David

Yes, Dave I already have tried this, but the error is still there.

I think it’s a class instantiate error, but despite I have tried modifying the class constructors, changing the way I instantiate the object etc. but I couldn’t get anything clear.

I have tried instantiating the object in a different way, using “new” command, but I also had errors:

Adafruit_MMA8451 mma = new Adafruit_MMA8451(0x12345678);

…/src/application.cpp:44:55: error: invalid conversion from ‘Adafruit_MMA8451*’ to ‘int32_t {aka long int}’ [-fpermissive]
Adafruit_MMA8451 mma = new Adafruit_MMA8451(0x12345678);
^
In file included from …/src/application.cpp:28:0:
…/src/Adafruit_MMA8451.h:82:5: error: initializing argument 1 of ‘Adafruit_MMA8451::Adafruit_MMA8451(int32_t)’ [-fpermissive]
Adafruit_MMA8451(int32_t id );
^
make: *** [obj/src/application.o] Error 1

Thanks,