MPL115A2 Library

Has the MPL115A2 Arduino library ( https://github.com/adafruit/Adafruit_MPL115A2 ) already been ported to Particle (Core)?

Or can I use the MPL3115A2 library? I guess not because the code looks a bit different.

Well I have given it a go and tried to upgrade the library for Particle ( https://github.com/jacealot/Adafruit_MPL115A2/tree/my-test-branch ). I’m not able to test this at the moment, but will this weekend. Lets hope it works :wink:

Have you had a look if the MPL3115A2 library is compatible with your sensor?

It’s also available on Particle Build

But a quick browse through your repo seemed OK.
Just out of curiosity, why have you decided to change the static functions into non-static? Did the Particle Wire class not play well with static?

One thing you might want to consider for future ports is, that you could keep the original Arduino functionality and just add the Particle specifics by use of conditional compiling (#ifdef .. #endif).

e.g.

#if defined(SPARK)
 #include "application.h"
#else
 #if ARDUINO >= 100		
  #include "Arduino.h"		
 #else		
  #include "WProgram.h"		
 #endif		
 #include <Wire.h>
#endif
...
static uint8_t i2cread(void) {		
  uint8_t x;		
  #if (ARDUINO >= 100) || defined(SPARK)		
  x = Wire.read();		
  #else		
  x = Wire.receive();		
  #endif		
  //Serial.print("0x"); Serial.println(x, HEX);		
  return x;		
}		
2 Likes

Hi Jacealot,

Did you have success with the Adafruit MPL115A2? I’m trying to get it running with the Photon but haven’t been successful. Would love to hear and learn from your experience.

Thank you! Todd