Teensey 4.1 and ADS1118

Fluxanode

Well-known member
I am trying to use the ADS1118 ADC. I am using the ADS1118 Library included in the examples with arduino, https://github.com/denkitronik/ADS1118. The program won't compile and is giving me the following errors.
The example program is ads1118example.ino. I tried the code change recommended by Christopher Mailer in the issue #12 with the same errors.

Note: the code will compile for a Uno.

Errors:
:\ChuckW\Documents\Microcontrollers\IC's modules and discreets\ADS1118\ADS1118_library-1.0.3\ADS1118_library-1.0.3\examples\ads1118example\ads1118example.ino:19:19: error: no matching function for call to 'ADS1118::ADS1118(int)'
19 | ADS1118 ads1118(CS);
| ^
In file included from D:\ChuckW\Documents\Microcontrollers\IC's modules and discreets\ADS1118\ADS1118_library-1.0.3\ADS1118_library-1.0.3\examples\ads1118example\ads1118example.ino:1:
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: candidate: 'ADS1118::ADS1118()'
38 | class ADS1118 {
| ^~~~~~~
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: candidate expects 0 arguments, 1 provided
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: candidate: 'constexpr ADS1118::ADS1118(const ADS1118&)'
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: no known conversion for argument 1 from 'int' to 'const ADS1118&'
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: candidate: 'constexpr ADS1118::ADS1118(ADS1118&&)'
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: no known conversion for argument 1 from 'int' to 'ADS1118&&'

Using library ADS1118 library at version 1.0.3 in folder: D:\ChuckW\Arduino\libraries\ADS1118_library
Using library SPI at version 1.0 in folder: C:\Users\ChuckW\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.1\libraries\SPI
exit status 1

Compilation error: no matching function for call to 'ADS1118::ADS1118(int)'

Code:
#include <ADS1118.h>

/**
*  Example for Arduino Library for Texas Instruments ADS1118 - 16-Bit Analog-to-Digital Converter with 
*  Internal Reference and Temperature Sensor
*  
*  @author Alvaro Salazar <alvaro@denkitronik.com>
*  http://www.denkitronik.com
*
*/

#include "ADS1118.h"
#include <SPI.h>

//Definition of the Arduino pin to be used as the chip select pin (SPI CS pin). Example: pin 5
#define CS 5

//Creating an ADS1118 object (object's name is ads1118)
ADS1118 ads1118(CS);


void setup(){
    Serial.begin(115200);
    ads1118.begin(); //Initialize the ADS1118. Default setting: PULLUP RESISTOR, ADC MODE, RATE 8SPS, SINGLE SHOT, ±0.256V, DIFFERENTIAL AIN0-AIN1

    /* 
     *  EXAMPLES:
     *  The lines above in this method are needed only if you want to change the default setting. Use them to fit your needs
     *  If you need to take care of noise and the ENOB (Effective Number of Bits) see the tables at the end of this file
     */

    /* Changing the sampling rate. 
       Available values: RATE_8SPS, RATE_16SPS, RATE_32SPS, RATE_64SPS, RATE_128SPS, RATE_250SPS, RATE_475SPS, RATE_860SPS */
    ads1118.setSamplingRate(ads1118.RATE_8SPS);             //Using the setter method to change the sampling rate
    //ads1118.configRegister.bits.rate=ads1118.RATE_8SPS;   //Driving the config register directly. Uncomment if you want to use this way

    /* Changing the input selected. 
       Available values: Diferential inputs: DIFF_0_1, DIFF_0_3, DIFF_1_3, DIFF_2_3. 
                         Single ended input: AIN_0, AIN_1, AIN_2, AIN_3*/
    ads1118.setInputSelected(ads1118.DIFF_0_1);             //Using the setter method to change the input selected
    //ads1118.configRegister.bits.mux=ads1118.DIFF_0_1;     //Driving the config register directly. Uncomment if you want to use this way

    /* Changing the full scale range. 
       Available values: FSR_6144 (±6.144V)*, FSR_4096(±4.096V)*, FSR_2048(±2.048V), FSR_1024(±1.024V), FSR_0512(±0.512V), FSR_0256(±0.256V).
       (*) No more than VDD + 0.3 V must be applied to this device. */
    ads1118.setFullScaleRange(ads1118.FSR_0256);            //Using the setter method to change the full scale range
    //ads1118.configRegister.bits.pga=ads1118.FSR_0256;     //Driving the config register directly. Uncomment if you want to use this way

    
    /* Setting to continuous conversion mode */
    ads1118.setContinuousMode();                            //Using the setter method to set it to continuous mode
    //ads1118.configRegister.bits.operatingMode=CONTINUOUS; //Driving the config register directly. Uncomment if you want to use this way

    /* Setting to single shot conversion mode */
    ads1118.setSingleShotMode();                            //Using the setter method to set it to "single shot conversion and power down" mode
    //ads1118.configRegister.bits.operatingMode=SINGLE_SHOT;//Driving the config register directly. Uncomment if you want to use this way

    /* Disabling the pull-up resistor */
    ads1118.disablePullup();                                //Using the setter method to disable the pull-up resistor in Dout
    //ads1118.configRegister.bits.pullUp=PULLUP;            //Driving the config register directly. Uncomment if you want to use this way

    /* Enabling the pull-up resistor */
    ads1118.enablePullup();                                 //Using the setter method to enable the pull-up resistor in Dout
    //ads1118.configRegister.bits.pullUp=NO_PULLUP;         //Driving the config register directly. Uncomment if you want to use this way
}


void loop(){
    Serial.println(String(ads1118.getTemperature(),6)+" C"); //Getting temperature
    Serial.println(String(ads1118.getMilliVolts(),10)+"mV"); //Getting millivolts measured in the input selected
    
    //Serial.println(String(ads1118.getMilliVolts(ads1118.DIFF_0_1),10)+"mV"); //Specifying the input to be selected
    
    delay(200); //You can use a delay to save power. The ADS1118 will be in power down state during all the delay time. Optional
    
}

/*
              Table 1. Noise in μVRMS (μVPP) at VDD = 3.3 V   [1]
                DATA RATE FSR (Full-Scale Range)
  (SPS) ±6.144 V        ±4.096 V     ±2.048 V       ±1.024 V        ±0.512 V        ±0.256 V
  8     187.5 (187.5)   125 (125)    62.5 (62.5)    31.25 (31.25)   15.62 (15.62)   7.81 (7.81)
  16    187.5 (187.5)   125 (125)    62.5 (62.5)    31.25 (31.25)   15.62 (15.62)   7.81 (7.81)
  32    187.5 (187.5)   125 (125)    62.5 (62.5)    31.25 (31.25)   15.62 (15.62)   7.81 (7.81)
  64    187.5 (187.5)   125 (125)    62.5 (62.5)    31.25 (31.25)   15.62 (15.62)   7.81 (7.81)
  128   187.5 (187.5)   125 (125)    62.5 (62.5)    31.25 (31.25)   15.62 (15.62)   7.81 (12.35)
  250   187.5 (252.09)  125 (148.28) 62.5 (84.03)   31.25 (39.54)   15.62 (16.06)   7.81 (18.53)
  475   187.5 (266.92)  125 (227.38) 62.5 (79.08)   31.25 (56.84)   15.62 (32.13)   7.81 (25.95)
  860   187.5 (430.06)  125 (266.93) 62.5 (118.63)  31.25 (64.26)   15.62 (40.78)   7.81 (35.83)

  
      Table 2. ENOB from RMS Noise (Noise-Free Bits from Peak-to-Peak Noise) at VDD = 3.3 V
                DATA RATE FSR (Full-Scale Range)
  (SPS)   ±6.144 V    ±4.096 V   ±2.048 V     ±1.024 V    ±0.512 V    ±0.256 V
  8       16 (16)     16 (16)    16 (16)      16 (16)     16 (16)     16 (16)
  16      16 (16)     16 (16)    16 (16)      16 (16)     16 (16)     16 (16)
  32      16 (16)     16 (16)    16 (16)      16 (16)     16 (16)     16 (16)
  64      16 (16)     16 (16)    16 (16)      16 (16)     16 (16)     16 (16)
  128     16 (16)     16 (16)    16 (16)      16 (16)     16 (16)     16 (15.33)
  250     16 (15.57)  16 (15.75) 16 (15.57)   16 (15.66)  16 (15.96)  16 (14.75)
  475     16 (15.49)  16 (15.13) 16 (15.66)   16 (15.13)  16 (14.95)  16 (14.26)
  860     16 (14.8)   16 (14.9)  16 (15.07)   16 (14.95)  16 (14.61)  16 (13.8)
  
  
  [1] Texas Instruments, "ADS1118 Ultrasmall, Low-Power, SPI™-Compatible, 16-Bit Analog-to-Digital 
  Converter with Internal Reference and Temperature Sensor", ADS1118 datasheet, SBAS457E [OCTOBER 2010–REVISED OCTOBER 2015]. 
  
  Note: This information is taken from http://www.ti.com
        Copyright © 2010–2015, Texas Instruments Incorporated
*/

I can compile for Uno but not Teensy 4.1.
 
Last edited:
Can someone using 4.1 try this and see if you have the same problems?

@PaulStoffregen do you have any suggestions?
 
Looked briefly at library source and it currently supports only AVR (Arduino UNO, etc.) and ESP32. You're getting "no matching function" because Teensy is neither AVR nor ESP32, so the library source is not being compiled at all. It looks like it wouldn't be too hard to adapt for Teensy, but you'd have to go through it, modify, and test.
 
Joe You are correct but in the GIT there is a code change recommended by Christopher Mailer in the issue #12 to make a change in the Lib. Change the #if defined(__AVR__) to #if defined(__AVR__) || defined(CORE_TEENSY) and that should allow it to run on a teensy. Apparently this is not working...

See https://github.com/denkitronik/ADS1118/issues/12
 
Joe You are correct but in the GIT there is a code change recommended by Christopher Mailer in the issue #12 to make a change in the Lib. Change the #if defined(__AVR__) to #if defined(__AVR__) || defined(CORE_TEENSY) and that should allow it to run on a teensy. Apparently this is not working...

See https://github.com/denkitronik/ADS1118/issues/12

That change was never made. I downloaded the latest release 1.0.3, made the substitution in the ADS1118.cpp/h files , and the basic example does build and run on T4.1. No other changes. I don't have an ADS1118, but perhaps you can try it?
 
Here are the modified files. Just replace the files in the 1.0.3 release with these.
 

Attachments

  • ADS1118.cpp
    13.8 KB · Views: 297
  • ADS1118.h
    8.5 KB · Views: 62
Thanks! It compiled but I still have these warning messages in red:

d:\ChuckW\Arduino\libraries\ADS1118_library\ADS1118.cpp: In member function 'uint16_t ADS1118::getADCValue(uint8_t)':
d:\ChuckW\Arduino\libraries\ADS1118_library\ADS1118.cpp:202:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
202 | for(int i=0;i<CONV_TIME[configRegister.bits.rate];i++) //Lets wait the conversion time
| ^~~
d:\ChuckW\Arduino\libraries\ADS1118_library\ADS1118.cpp:204:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
204 | count++;
| ^~~~~
d:\ChuckW\Arduino\libraries\ADS1118_library\ADS1118.cpp:174:28: warning: variable 'configMSB' set but not used [-Wunused-but-set-variable]
174 | byte dataMSB, dataLSB, configMSB, configLSB, count=0;
| ^~~~~~~~~
d:\ChuckW\Arduino\libraries\ADS1118_library\ADS1118.cpp:174:39: warning: variable 'configLSB' set but not used [-Wunused-but-set-variable]
174 | byte dataMSB, dataLSB, configMSB, configLSB, count=0;
| ^~~~~~~~~
d:\ChuckW\Arduino\libraries\ADS1118_library\ADS1118.cpp: In member function 'double ADS1118::getTemperature()':
d:\ChuckW\Arduino\libraries\ADS1118_library\ADS1118.cpp:258:31: warning: variable 'configMSB' set but not used [-Wunused-but-set-variable]
258 | uint8_t dataMSB, dataLSB, configMSB, configLSB, count=0;
| ^~~~~~~~~
d:\ChuckW\Arduino\libraries\ADS1118_library\ADS1118.cpp:258:42: warning: variable 'configLSB' set but not used [-Wunused-but-set-variable]
258 | uint8_t dataMSB, dataLSB, configMSB, configLSB, count=0;
| ^~~~~~~~~
 
Thanks! It compiled but I still have these warning messages in red:

Yes, the values configMSB/LSB are set but not used in both getADCValue() and getTemperature(). I don't know why that is, nor have I looked at the ADS1118 data sheet to try to understand what the library author did. Are you getting reasonable data values? If so, you can either live with the warnings or edit out the unused variables.

EDIT: the data sheet contains the text below, so it looks like the library is using this 32-bit (4-byte) data mode, and even though the configMSB/LSB are set and not used, you should probably leave them alone.

The data in a 32-bit data transmission cycle consists of four bytes: two bytes for the conversion result, and an
additional two bytes for the Config Register read back. The device always reads the MSB first.
 
Joe, sorry for the delayed reply, yes it is working and I am getting accurate data!
Thanks for your help.
 
Hi @joepasquariello and/or all.

I used the ADS1118 lib last year and it worked with the changes Joe helped me with in this post. But now i'm writing a new program and it is not compiling so I went back to the basic example that also worked and now i have errors compiling. As far as i know the only difference is i am using the latest teensy version called 0.60.3 in boards manager with Arduino 2.3.3.

Here are the errors i'm seeing:

D:\ChuckW\Arduino\libraries\ADS1118_library\examples\basicExampleAds1118\basicExampleAds1118.ino:17:19: error: no matching function for call to 'ADS1118::ADS1118(int)'
ADS1118 ads1118(CS);
^
In file included from D:\ChuckW\Arduino\libraries\ADS1118_library\examples\basicExampleAds1118\basicExampleAds1118.ino:10:0:
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: candidate: ADS1118::ADS1118()
class ADS1118 {
^~~~~~~
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: candidate expects 0 arguments, 1 provided
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: candidate: constexpr ADS1118::ADS1118(const ADS1118&)
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: no known conversion for argument 1 from 'int' to 'const ADS1118&'
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: candidate: constexpr ADS1118::ADS1118(ADS1118&&)
d:\ChuckW\Arduino\libraries\ADS1118_library/ADS1118.h:38:7: note: no known conversion for argument 1 from 'int' to 'ADS1118&&'

Using library ADS1118 library at version 1.0.3 in folder: D:\ChuckW\Arduino\libraries\ADS1118_library
Using library SPI at version 1.0 in folder: C:\Users\ChuckW\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.14\libraries\SPI
exit status 1

Compilation error: no matching function for call to 'ADS1118::ADS1118(int)'

Any help would be appreciated.
 
Can you check and make sure you are building for Teensy? The messages you posted say the SPI for SAMD is being used, and if you're not building for Teensy, there is no constructor of the correct form.
 
Thanks Joe! yeah I saw that, I am using teensy. So just now I added #define CORE_TEENSY in the ADS1118.h to see what happens and now it compiles again. Is the SAMD reference a problem? Like I said, nothing changed that i know of in the lib? Baffling. Now i guess i need to see if the hardware is working again.

Any additional comments or suggestions will be appreciated...
 
ADS1118.h has a #include "Arduino.h", and if you were building for Teensy, that would result in #include of "core_id.h", which has #define CORE_TEENSY. So, somehow, even if you are building for Teensy, the build is not using the Teensy folders.

I will install 2.3.3 and see what happens, but maybe someone else who already uses it can chime in here and explain why your build is bringing in SPI from the SAMD core instead of the Teensy core.
 
Yeah something is wrong, it's not reading the hardware correctly, no matter what the input voltage i get maxed out readings i.e. 32768 bits
 
Aw damm, somehow the board got changed to Arduino SAM under tools/board. I never work with that or any arduino board (only teensy 3.2 or 4.1) and it always is set to Teensy 4.1. I'm starting to think 2.3.3 is still buggy. Sometimes the settings change and i have to look over settings i would take for granted are not changing.
Still i'm not seeing the correct data.
 
Okay, but take out #define you added to ADS1118.h and make sure it builds now without errors. If it does, you'll know for sure you are building for Teensy, and you can move on to the next issue.
 
ok thanks i'll do that. So i shut down arduino and restarted it. Did a reload and it said it was compiling and uploading in the message line but there were no compiler messages and it acted like it was hung. I did a user abort, shut down arduino again, restarted and it worked this time and now the data is coming in correctly. What version of arduino are you and other people on here using and do you think 2.3.3 is stable?
 
Now Arduino is stuck and says downloading index: package_0.60.3_index.json. I rebooted my computer and am getting the same message.
 
I don't use the 2.x IDE for development, but I have it installed, and I occasionally update to the latest version. When I saw your message, I started 2.3.2 and accepted the update to 2.3.3. After that I updated some libraries, set the target to Teensy 4.1, and then built the ADS1118 example sketch. Everything worked fine. No issues.
 
ok, thanks. I had to uninstall and reinstall it to be able to compile, it was stuck and lost all of the boards in the manager.
Thanks for all of the help!
 
Back
Top