I am using an Arduino DUE with a temperature sensor DS18B20.
I want to change the resolution of the sensor and I aspect to obtain more "precise" results with the resolution = 12 and a rought estimation with resolution = 9.
However I when I print the temperatures (obtained with different resolutions) I get same temperature (see attachment the image)!! How is possible that??
From the serial monitor I get:
34.31 Resolution: 9
34.31 Resolution: 10
34.31 Resolution: 11
34.31 Resolution: 12
-----------------------------
34.25 Resolution: 9
34.25 Resolution: 10
34.25 Resolution: 11
34.25 Resolution: 12
-----------------------------
34.19 Resolution: 9
34.19 Resolution: 10
34.19 Resolution: 11
34.19 Resolution: 12
Here is the code I am using:
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is connected to GPIO4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
DeviceAddress sensor1 = { 0x28, 0xCA, 0xBA, 0x55, 0x5, 0x0, 0x0, 0xD0 };
void setup(void){
Serial.begin(115200);
sensors.begin();
}
void loop(void){
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("");
Serial.println("-----------------------------");
sensors.setResolution(sensor1, 9);
Serial.print(sensors.getTempC(sensor1));
Serial.print(" Resolution: ");
Serial.print(sensors.getResolution(sensor1));
Serial.println();
sensors.setResolution(sensor1, 10);
Serial.print(sensors.getTempC(sensor1));
Serial.print(" Resolution: ");
Serial.print(sensors.getResolution(sensor1));
Serial.println();
sensors.setResolution(sensor1, 11);
Serial.print(sensors.getTempC(sensor1));
Serial.print(" Resolution: ");
Serial.print(sensors.getResolution(sensor1));
Serial.println();
sensors.setResolution(sensor1, 12);
Serial.print(sensors.getTempC(sensor1));
Serial.print(" Resolution: ");
Serial.print(sensors.getResolution(sensor1));
Serial.println();
}