DallasTemperature.h does not find device

Hi

I am trying to use a 3 wire thermocouple with the aid of OneWire.h and DallasTemperature.h. For test purposes it is on a basic Arduino UNO with signal wire on Pin2 (but is destined for Nano33 IoT when I can get it to work).

I used oneWireSearch and found address as {0x28, 0xE6, 0xD0, 0xBB, 0x00, 0x00, 0x00, 0xDE}.

When I use single.ino, it does not find the address, getting the following message on serial monitor:

14:55:49.789 -> Dallas Temperature IC Control Library Demo

14:55:49.789 -> Locating devices...Found 0 devices.

14:55:49.953 -> Parasite power is: OFF

14:55:49.953 -> Unable to find address for Device 0

14:55:49.953 -> Device 0 Address: 0000000000000000

14:55:49.953 -> Device 0 Resolution: 0

14:55:49.953 -> Requesting temperatures...DONE

14:55:52.189 -> Error: Could not read temperature data

When I try to follow the guidance in single.ino to change the address I get the error message below.

Lines 45 and 46 in single.ino

// Note that you will need to use your specific address here

insideThermometer = { 0x28, 0xE6, 0xD0, 0xBB, 0x00, 0x00, 0x00, 0xDE };

Error message

/Users/mikedale/Documents/Arduino/ArduinoTemperatureControlLibrarymaster/examples/Single/Single.ino: In function 'void setup()':
/Users/mikedale/Documents/Arduino/ArduinoTemperatureControlLibrarymaster/examples/Single/Single.ino:46:72: error: assigning to an array from an initializer list
insideThermometer = { 0x28, 0xE6, 0xD0, 0xBB, 0x00, 0x00, 0x00, 0xDE };
^
exit status 1

Compilation error: assigning to an array from an initializer list

I am now completely lost!!!


```cpp
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// arrays to hold device address
DeviceAddress insideThermometer;

/*
 * Setup function. Here we do the basics
 */
void setup(void)
{
  // start serial port
  Serial.begin(115200);
  delay (3000);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // locate devices on the bus
  Serial.print("Locating devices...");
  sensors.begin();
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: ");
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

  // Assign address manually. The addresses below will need to be changed
  // to valid device addresses on your bus. Device address can be retrieved
  //by using either 
  //oneWire.search(DeviceAddress) ;
  //or individually via
  // sensors.getAddress(deviceAddress, index)
  // Note that you will need to use your specific address here
  insideThermometer = { 0x28, 0xE6, 0xD0, 0xBB, 0x00, 0x00, 0x00, 0xDE };

  // Method 1:
  // Search for devices on the bus and assign based on an index. Ideally,
  // you would do this to initially discover addresses on the bus and then
  // use those addresses and manually assign them (see above) once you know
  // the devices on your bus (and assuming they don't change).
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");

  // method 2: search()
  // search() looks for the next device. Returns 1 if a new address has been
  // returned. A zero might mean that the bus is shorted, there are no devices,
  // or you have already retrieved all of them. It might be a good idea to
  // check the CRC to make sure you didn't get garbage. The order is
  // deterministic. You will always get the same devices in the same order
  //
  // Must be called before search()
  //oneWire.reset_search();
  // assigns the first address found to insideThermometer
  //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
  sensors.setResolution(insideThermometer, 9);

  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC);
  Serial.println();
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  // method 1 - slower
  //Serial.print("Temp C: ");
  //Serial.print(sensors.getTempC(deviceAddress));
  //Serial.print(" Temp F: ");
  //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit

  // method 2 - faster
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == DEVICE_DISCONNECTED_C)
  {
    Serial.println("Error: Could not read temperature data");
    return;
  }
  Serial.print("Temp C: ");
  Serial.print(tempC);
  Serial.print(" Temp F: ");
  Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
}
/*
 * Main function. It will request the tempC from the sensors and display on Serial.
 */
void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  delay(1500);

  // It responds almost immediately. Let's print out the data
  printTemperature(insideThermometer); // Use a simple function to print out the data
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}
```

You forgot to include the verbose error log in code tags.

The DallasTemperature library is for Maxim temperature sensors:

## 📌 Supported Devices

- DS18B20
- DS18S20 (⚠️ Known issues with this series)
- DS1822
- DS1820
- MAX31820
- MAX31850

Is your thermocouple sensor compatible with any of those?

That sample is wrong, try another.

Try DS18B20_RT/examples at master · RobTillaart/DS18B20_RT · GitHub

oneWireScanner.ino

oneWireSearch.ino

What do they produce?, pleas post (as text)

You cannot copy an array that way. Easier just to set the address in the declaration


// arrays to hold device address
DeviceAddress insideThermometer = { 0x28, 0xE6, 0xD0, 0xBB, 0x00, 0x00, 0x00, 0xDE };

But I doubt it will correct the problem if the sensor was not found automatically in the example sketch.

Thank you for this correction of the library… with this change it compiles but but as you say it still does not work.

Thank you for your response.

Thermocouple is:

DS18B20 Temperature Sensor Sonde with 3m cable. So, if I have understood, should work and I secured and address (which may be wrong, of course) using oneWireSearch.

Any other thoughts?

Regards

Hi

Many thanks. Three cheers for you and three cheers for Rob Dillard. It works.

18:45:33.298 ->

18:45:33.298 -> /Users/mikedale/Documents/Arduino/DS18B20_RT-master/examples/DS18B20_simple/DS18B20_simple.ino

18:45:33.330 -> DS18B20_LIB_VERSION: 0.2.5

18:45:33.330 ->

18:45:33.362 -> Temp: 19.75

18:45:33.524 -> Temp: 19.75

18:45:33.557 -> Temp: 19.75

Kind Regards

Mike

It's not a thermocouple.
And it's @robtillaart

@tigger

Dillard is not too bad as it means “brave people” in old French IIRC

And it is called?

Apologies.. Dyslexia rules… it’s a miracle tha I can get any coding to work :slight_smile:

oneWireSearch produces

10:23:35.805 -> ��^<�<��//

10:23:37.472 -> // Start oneWireSearch.ino

10:23:37.472 -> //

10:23:37.472 ->

10:23:37.472 -> uint8_t pin2[][8] = {

10:23:37.472 -> {

10:23:37.472 -> 0x28, 0xE6, 0xD0, 0xBB, 0x00, 0x00, 0x00, 0xDE }, // CRC OK

10:23:37.505 -> };

10:23:37.505 -> // nr devices found: 1

10:23:37.505 ->

10:23:37.505 -> //

10:23:37.505 -> // End oneWireSearch.ino

10:23:37.538 -> //

Ln 58, Col 45

Arduino Uno

on /dev/cu.usbmodem14701

oneWireScanner produces

10:26:57.851 -> o�!�1�"]{����Y�0     �������Y=�Ӏ�v=.
10:26:59.513 -> /Users/mikedale/Downloads/DS18B20_RT-master/examples/oneWireScanner/oneWireScanner.ino
10:26:59.513 -> 
10:26:59.513 -> 
10:26:59.513 -> scanning pin:   2
10:26:59.545 -> 0x28, 0xE6, 0xD0, 0xBB, 0x00, 0x00, 0x00, 0xDE       CRC OK         DS1822
10:26:59.545 -> nr devices found: 1
10:26:59.545 -> nr devices found: 0

Looks good, (thanks for running)

It generates a snippet of code with the addresses of the found devices which can be used in your project (with any DallasTemperature library).

I'm not trying to nit-pick, but it is important to describe things correctly.
Thermocouples are generally used to measure very high temperatures as in ovens and furnaces.
The DS18B20 device is a silicon bandgap element combined with associated electronics that operates with Dallas Semiconductors (Maxim, Analog Devices) 1-Wire communications bus.
It most certainly isn't a thermocouple which works completely differently.
The name 1-Wire is a misnomer as it can be up to three wires, depending how you use it.
It's not so straightforward to use as I2C or SPI, but libraries are available.
Your search looks as though it works and the line starting 0x28 is the data package that the library decodes. CRC is Cyclic Redundancy Check and confirms that the data package is correct.
I don't know why it says one device found, then no device found.
As I said, 1-Wire does work, but sometimes needs some help.
More knowledgeable users than me will use it without a library and use a technique called bit-banging.
The DS18B20 is an old device but widely used. I have several for room temperature, and two for hot water and central heating. The whole house is wired for 1-Wire.
Do you have a reason to choose the DS18B20?
There are sensors available that don't need libraries like LM35, LM335, TMP36.
The LM devices just have 3 pins, Vcc, GND, Data. Data is an analogue voltage in millivolts which the Arduino reads at an Analog Input pin.

Thanks very much.

That is helpful. I am often called a pedant; so I appreciate your precision.

My choice of sensor was a reflection of my ignorance, like my coding skills! LM device sounds much better idea

The oneWireScanner sketch searches all pins of the Arduino and reports how many oneWire devices it finds per pin (including addresses).

I wrote it to diagnose (daily) a project at startup that had four DS18B20’s, one device per pin. Although oneWire is a bus that allows multiple DS-devices, this choice allowed me to uniquely diagnose which sensor(s) failed. Then the failing one could be replaced without adjusting one-wire addresses in the code.