Error when calling function on object contained in 2D array

Hi all,

I am trying to get the temperature of various DS18B20 temperature sensors connected to the same pin.
When I compile it, it gives me "no matching function for call to DallasTemperature::setResolution(uint8_t [8][8], int)’ ". this error message occurs when the IDE is trying to compile the line containing “sensors.setResolution(Probe[thisProbe], 10)”.

I think that the problem lies in how I created a 2D array to contain all device addresses. I did this in order to be able to loop over the different devices when I call the temperatures.

Is there something wrong with the way I did it? My code is very long and includes lots of other stuff, so I tried to pick the relevant lines for my issue. The line DeviceAddress Probe[4][8] {…} is probably where the problem lies. Should I use pointers or something?

Thanks a lot!

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS_PIN 47 
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress Probe[4][8] { {0x28, 0x8A, 0xB1, 0x40, 0x04, 0x00, 0x00, 0xC7 },
  {0x28, 0xCC, 0x92, 0x40, 0x04, 0x00, 0x00, 0xB6 },
  {0x28, 0x4D, 0x8D, 0x40, 0x04, 0x00, 0x00, 0x78},
  { 0x28, 0x9A, 0x80, 0x40, 0x04, 0x00, 0x00, 0xD5 }
};

void setup() {
  Wire.begin(); 
  Serial.begin(115200); 
  SPI.begin();  
  sensors.begin();
  for (int thisProbe = 0; thisProbe < CellN; thisProbe++) {
     sensors.setResolution(Probe[thisProbe], 10)
  }

void loop() {
  sensors.requestTemperatures();
  for (int thisCell = 0; thisCell < CellN; thisCell++) {
     float tempC = sensors.getTempC(Probe[thisCell]);
  }

DeviceAddress Probe[4][8] declares a 2D array of 32 DeviceAddress typed elements.

A DeviceAddressis defined as typedef uint8_t DeviceAddress[8];

So you are not declaring 4 DS18B20 as you think you are.

Does the DallasTemperature object have a setResolution method that takes an [u]array[/u] of DeviceAddress as an argument?

If setResolution takes one DeviceAddress, and if you are getting that DeviceAddress from Probe, then the method call will look like setResolution(Probe[row][column]) .

I think the OP has only 4 sensors not 32.

Besides initializing SPI and Wire without including the libraries (and not needing them) and missing some closing } as text indentation shows it’s wrong, and not declaring CellN… - what he would need to declare is an array of 4 sensors. a Sensor is addressed through a DeviceAddress type variable which is defined as typedef uint8_t DeviceAddress[8];, so an array of 8 bytes.

Initialization then would be

DeviceAddress Probe[4] = {
  {0x28, 0x8A, 0xB1, 0x40, 0x04, 0x00, 0x00, 0xC7},
  {0x28, 0xCC, 0x92, 0x40, 0x04, 0x00, 0x00, 0xB6},
  {0x28, 0x4D, 0x8D, 0x40, 0x04, 0x00, 0x00, 0x78},
  {0x28, 0x9A, 0x80, 0x40, 0x04, 0x00, 0x00, 0xD5}
};

and the code could look something like this:

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS_PIN 47
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress Probe[4] = {
  {0x28, 0x8A, 0xB1, 0x40, 0x04, 0x00, 0x00, 0xC7},
  {0x28, 0xCC, 0x92, 0x40, 0x04, 0x00, 0x00, 0xB6},
  {0x28, 0x4D, 0x8D, 0x40, 0x04, 0x00, 0x00, 0x78},
  {0x28, 0x9A, 0x80, 0x40, 0x04, 0x00, 0x00, 0xD5}
};

byte CellN = sizeof(Probe) / sizeof(Probe[0]);

void setup() {

  Serial.begin(115200);
  sensors.begin();
  for (int thisProbe = 0; thisProbe < CellN; thisProbe++) {
    sensors.setResolution(Probe[thisProbe], 10);
  }
}

void loop() {
  sensors.requestTemperatures();
  for (int thisCell = 0; thisCell < CellN; thisCell++) {
    float tempC = sensors.getTempC(Probe[thisCell]);
  }
}

Thanks a lot! Indeed I hadn't realized that if I wanted to make an array containing 4 DeviceAddress objects, I only needed a 1D array. Makes perfectly sense, and solved the problem. PS: sorry for having forgotten some lines in the sample code and included unnecessary lines, these are used for other parts of the code!

Thanks again, Best.

Good ! happy it helped