Hi all,
To keep my code manageable I've split it in numerous files and libraries, and of course have to pass information around. I'm now running into a big problem passing a reference to the ADS1015 library from my main script into the library where it has to be used.
(sorry, can't post full code - way too big - and I still haven't uploaded it to github).
.ino file snippets:
#include <Adafruit_ADS1015.h>
#include <HydroMonitorMaster.h>
Adafruit_ADS1115 ads1115(0x48);
HydroMonitorMaster master;
void setup() {
Wire.begin();
ads1115.begin();
master.enableThermistor(0, NTCSERIESRESISTOR, THERMISTORNOMINAL, BCOEFFICIENT, TEMPERATURENOMINAL, ADCMAX, &ads1115);
}
Then in HydroMonitorMaster.h:
#include <Adafruit_ADS1015.h>
class HydroMonitorMaster
{
public:
void enableThermistor(unsigned char, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, Adafruit_ADS1115*);
};
and in HydroMonitorMaster.cpp:
void HydroMonitorMaster::enableThermistor(unsigned char sensorPin, unsigned int seriesResistor, unsigned int NTCNominal, unsigned int BCoefficient, unsigned int TNominal, unsigned int ADCMax, Adafruit_ADS1115 *ads) {
useWaterTempSensor = true;
waterTempSensor.begin(settings.WaterTempSensor, sensorPin, seriesResistor, NTCNominal, BCoefficient, TNominal, ADCMax, &ads);
return;
}
When I try to compile this, I get the following compiler error:
Arduino: 1.8.1 (Linux), Board: "Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 4M (1M SPIFFS), ck, Disabled, None"
/home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp: In member function 'void HydroMonitorMaster::enableThermistor(unsigned char, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, Adafruit_ADS1115*)':
/home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp:125:130: error: invalid conversion from 'Adafruit_ADS1115**' to 'uint8_t {aka unsigned char}' [-fpermissive]
waterTempSensor.begin(settings.WaterTempSensor, sensorPin, seriesResistor, NTCNominal, BCoefficient, TNominal, ADCMax, &ads1115);
^
In file included from /home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.h:14:0,
from /home/wouter/Arduino/libraries/HydroMonitor/src/HydroMonitorMaster.cpp:1:
/home/wouter/Arduino/libraries/Adafruit_ADS1X15-master/Adafruit_ADS1015.h:151:3: error: initializing argument 1 of 'Adafruit_ADS1115::Adafruit_ADS1115(uint8_t)' [-fpermissive]
Adafruit_ADS1115(uint8_t i2cAddress = ADS1015_ADDRESS);
^
exit status 1
Error compiling for board Generic ESP8266 Module.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
The ADS1115 library gets initialised in the .ino sketch, here the I2C address is passed as well. Then this already instantiated object has to be passed to the master library for further use (it's supposed to get passed on again to yet another library, where the actual sensor is read - one piece for each sensor, up to four different sensors on one ADS1115).
When passing the reference to the master.enableThermistor, it appears that the library tries to instantiate again. Of course this doesn't work (no way to give the I2C address), and of course it shouldn't happen at all because this object should have been instantiated already.
Now I must admit that I still don't fully understand references/pointers and may be doing something totally wrong, but this is at least what I want to happen. Initialise my external ADC (and, related, a port extender - haven't tackled that one yet but should go the same way), then pass the reference of the object to whichever part of my code needs it.