Error with SparkFun_ADS1015 library

Hello, I am using a raspberry pi 3 and Arduino 1.8.10. I am trying to build a sensor glove using the SparkFun_ADS1015 library.
The code I'm using is below:

#include <SparkFun_ADS1015_Arduino_Library.h>
ADS1015 fingerSensor;

void setup() {

  Wire.begin();
  Serial.begin(115200);

  if (fingerSensor.begin(Wire, 100000, ADS1015_ADDRESS_GND) == false) {
     Serial.println("Device not found. Check wiring.");
     while (1);
  }

}

void loop() {  
  uint16_t data;
  for (int finger = 0; finger < 2; finger++) {
    data = fingerSensor.getAnalogData(finger);
    Serial.print(finger);
    Serial.print(": ");
    Serial.print(data);
    Serial.print(",");
  }
  Serial.println();
}

(If you are wondering, yes it is copy and pasted)

I get this error message when trying to compile the code:


/home/pi/Arduino/Sketchs/GloveControllerOutput/GloveControllerOutput.ino: In function 'void setup()':
GloveControllerOutput:9:59: error: no matching function for call to 'ADS1015::begin(TwoWire&, long int, int)'
if (fingerSensor.begin(Wire, 100000, ADS1015_ADDRESS_GND) == false) {
^
In file included from /home/pi/Arduino/Sketchs/GloveControllerOutput/GloveControllerOutput.ino:1:0:
/home/pi/Arduino/libraries/SparkFun_ADS1015_Arduino_Library/src/SparkFun_ADS1015_Arduino_Library.h:114:10: note: candidate: boolean ADS1015::begin(uint8_t, TwoWire&)
boolean begin(uint8_t i2caddr = ADS1015_ADDRESS_GND, TwoWire &wirePort = Wire);
^~~~~
/home/pi/Arduino/libraries/SparkFun_ADS1015_Arduino_Library/src/SparkFun_ADS1015_Arduino_Library.h:114:10: note: candidate expects 2 arguments, 3 provided
Multiple libraries were found for "SparkFun_ADS1015_Arduino_Library.h"
Used: /home/pi/Arduino/libraries/SparkFun_ADS1015_Arduino_Library
Multiple libraries were found for "Wire.h"
Used: /home/pi/Downloads/arduino-1.8.10/hardware/arduino/avr/libraries/Wire
exit status 1
no matching function for call to 'ADS1015::begin(TwoWire&, long int, int)'


If you need any more details please ask me.

Thank you in advance,

Jai

The problem is that the code you found is written for the 1.0.1 version of the SparkFun ADS1015 Arduino Library, but you are using one of the 2.x.x versions of the library. A breaking change was made to the library's begin function in the 2.0.0 release:

You could roll back to the 1.0.1 version of the library, which will allow you to use your code as is. However, it's a fairly minor change that needs to be made to update the code to work with the new versions of the library. You only need to change this line:

if (fingerSensor.begin(Wire, 100000, ADS1015_ADDRESS_GND) == false) {

to:

if (fingerSensor.begin() == false) {

Although you can specify the i2caddr and wirePort arguments to the function, it is written to use ADS1015_ADDRESS_GND and Wire by default for these values, so there is no need.

Thank you so much, it works! :slight_smile:

Jai

You're welcome. I'm glad to hear it's working now. Enjoy!
Per