I have just installed DallasTemperature.h into my Arduino setup.
I cannot find a listing of functions available in the library akin to this one for OneWire.h.
Is there one? Where is it?
Thanks
I have just installed DallasTemperature.h into my Arduino setup.
I cannot find a listing of functions available in the library akin to this one for OneWire.h.
Is there one? Where is it?
Thanks
It looks like there is no documentation other than the example sketches. However, you can find a listing of the functions with a helpful comment explaining the purpose of each in the header file:
If you need more information you'll want to check the implementation in the .cpp file:
The source code is always the definitive reference, if not the most user friendly.
pert:
The source code is always the definitive reference, if not the most user friendly.
Amen. Thanks pert
Note the above links are the source code at the 3.7.6 release, which I assume you're using since I seem to remember you use Library Manager and that's the most recent version available via Library Manager. There has been significant work done on the library since that release:
and in fact there have been 3 additional library versions but they never bothered to do GitHub releases so they are not available via Library Manager:
So you should make sure to look at the source code at the version you're using. The best way to be sure is to look at the files on your computer instead of those on GitHub but it's easier for me to post a GitHub link.
Since you mentioned you're having problems in the other thread, you might try using the latest version of the library downloaded from GitHub if you're not already.
Thanks pert. I'll get on it in the morning.
Pert if you are so kind to provide links with code examples using the functions in the library ?
Thanks
mjcolom:
Pert if you are so kind to provide links with code examples using the functions in the library ?
You'll find plenty of them under the File > Examples > DallasTemperature menu after you install the library.
mjcolom:
Pert if you are so kind to provide links with code examples using the functions in the library ?
A: Let us perform this Tutorial-A using DS18B20 Digital Temperature Sensor and OneWire.h Library
1. Connect the DS18B20 sensor with UNO as per following diagram.
Figure-1: Connection diagram between UNO and DS18B20 sensor
Figure-3: Scratchpad Memory map and ROMCode?address of DS18B20 sensor
Functional Description of Fig-2, 3: Every DS18B20 chip has its own 64-bit (8-byte) ROMCode (Fig-2) which is composed of three fields viz., 8-bit Family Code (0 - 7), 48-bit Serial Number/Address (8 - 55), and 8-bit CRC Code (56 - 63). Lower 2-byte (byte0, byte1) of the 9-byte wide scratchpad memory (Fig-3) contains the temperature information, which are always updated following every temperature conversion command. The user program reads all the data bytes of the scratchpad memory and processes the lower two bytes (as per Fig-4) to extract temperature value in decimal format.
Figure-4: Temperature/Data relationship table of DS18B20
2. Upload the following sketch
//12-bit default resolution; external power supply
#include<OneWire.h> //provides ready made functions for DS18B20 sensor
#define OneWireBus 10 //sensor's output is with DPin-10
OneWire ds(OneWireBus); //create an object named ds of type OneWire
byte addr[8]; //array to hold 64-bit ROMCode/address of DS18B20
byte data[9]; //array to hold data coming from scratchpad memory of DS18B20
float celsius; //variable of type float
void setup()
{
Serial.begin(9600);
ds.reset(); //reset the DS18B20 sensor and bring 1-Wire into idle state
ds.search(addr); //collect 64-bit ROMcode/address of sensor and save in addr array
}
void loop()
{
ds.reset(); //reset the DS18B20 sensor and bring 1-Wire into idle state
ds.select(addr); //slect with DS18B0 with address contained in addr[]
ds.write(0x44); //conversion command
delay(1000); //conversion delay time
//---------------------------
ds.reset();
ds.select(addr); //selectimg the desired DS18B20
ds.write(0xBE); //Function command to read Scratchpad Memory of DS18B20(9-Byte)
ds.read_bytes(data, 9); //data comes from DS18B20's scratchpad and are saved into array data[9]
//---------------------------------
unsigned int rawTemp = (data[1] << 8) | data[0]; //---data[0] and data[1] contains temperature data : 12-bit resolution-----
celsius = (float)rawTemp / 16.0; //12-bit resolution
Serial.print(celsius, 2); //Serial Monitor shows temperature
Serial.println(" *C");
}
3. Reset the UNO.
4. Bring in the Serial Monitor at 9600 Bd.
5. Check that the Serial Monitor shows room temperature at 1-sec interval.
B: Let us perform this Tutorial-B using DS18B20 Digital Temperature Sensor and OneWire.h and DallasTemperature.h Libraries. The program codes are taken from the examples of the DallasTemperature.h Library.
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 10// Data wire is plugged into port 10 on the Arduino
OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with DS18B20
DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.
void setup(void)
{
Serial.begin(9600); // start serial port
sensors.begin();// Start up the library
}
void loop(void)
{
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.print(sensors.getTempCByIndex(0));
Serial.println(" *C");
delay(1000);
}
C: Tasks
(1) Add codes with Tutorial-A to print the 8-byte ROM-code (16-digit including leading zeros) on Serial Monitor.
(2) Add another DS18B20 sensor with Fig-1; modify codes of Tutorial-A to accommodate the 2nd sensor; show temperatures of both sensors on Serial Monitor.
(3) Add an I2C LCD Panel with Fig-1; add necessary codes with the sketch of Tutorial-A to contain the LCD; show the temperature value on the Top Line of the LCD beginning from position DP0 (Display Position-0).