Adafruit ADS1015 ADC Library for Spark?

I’m trying to port the Adafruit ADS1x15 libary to Spark. I’ve got the 16 bit ADS1115, but the libraries are written for a few versions. The problem is that I’ve got no clue what i’m doing. I’ve searched and searched the forums here to no avail. I can program in a few other languages, but these compiled languages really throw me for a loop. I am failing first to understand how to even use libraries that don’t exist. I started trying to use an example Arduino SOS library to learn and use in place of the Tinker app, but I even failed there.

My ultimate goal is to be able to use my ADC, but I genuinely wan’t to know how to port libraries on my own, I just don’t know where to start and have the experience to do so.

  1. To test code, don’t I just click the + button and add the .cpp and .h file code then “verify”?
  2. Do I replace #include <Wire.h> with #include "application.h" or #include <application.h> or something else?

Here are some source links:
Adafruit ADS1x15 library
Adafruit ADS1115 16-bit ADC product page

Thanks in advance for advice or help!

Some useful starters can be found here


and in the connected GitHub repo

With the hints and tips in there I wouldn’t see any problem porting that library.

Just one thing in addition to that. For the .cpp file you could do this

/**************************************************************************/
/*!
    @brief  Abstract away platform differences in Arduino wire library
*/
/**************************************************************************/
static uint8_t i2cread(void) {
#if defined(SPARK) || (ARDUINO >= 100)
  return Wire.read();
#else
  return Wire.receive();
#endif
}

/**************************************************************************/
/*!
    @brief  Abstract away platform differences in Arduino wire library
*/
/**************************************************************************/
static void i2cwrite(uint8_t x) {
#if defined(SPARK) || (ARDUINO >= 100)
  Wire.write((uint8_t)x);
#else
  Wire.send(x);
#endif
}

I had found the Library List + Porting How To and I’m sure my answers will be there in the future, but for now, I’m looking for some very rudimentary help to even get going. Can anyone answer my 2 questions?

In that guide however, what would be helpful would be a complete walk through, like taking a simple application and creating a library from it. It would be almost identical to the Arduino library tutorial I referenced that converts a the tinker app to a version that uses a custom user created library.

Writing a Library for Arduino

First: If you use the Web IDE, then YES. Copy/Paste your code into the respective files and add an #include statement in your .ino file.
Second: That is exactly what you will have found already in the GitHub link above

#if defined (SPARK)
  #include "application.h"
#else
  #if defined(ARDUINO) && ARDUINO >= 100
    #include "Arduino.h"
  #else
    #include "WProgram.h"
  #endif

  // This line is only required for Arduino, since on Spark it's already
  // done via application.h
  #include "Wire.h"  // this line is added for your particular case

#endif

And no need to #include "application.h" inside you .ino file, since this will be done by the preprocessor.

And inside Adafruit_ADS1015.cpp I’d comment out this part, since this is already done via the Adafruit_ADS1015.h

/* ***** no need for double action ******
// #if ARDUINO >= 100
//  #include "Arduino.h"
// #else
//  #include "WProgram.h"
// #endif
//
// #include <Wire.h>
*************************************** */
1 Like

Thanks, I’ll try it out tonight.

@ScruffR, I really need to get to that porting guide! So much to do and so little time :stuck_out_tongue:

@peekay123 and @estrauss, I have added some hints in the above respect to @harrisonhjones 's repo and filed a Pull Request.

Maybe till then, you want to have a look at the changes at
https://github.com/ScruffR/Spark-Ported-Libraries

If you have any more quick suggestions, I’d try to work them in and do another PR.


Just seen that Harrison has already merged my PR :wink: :+1: