resolution of DS18B20

I am trying to change the resolution of a DS18B20 to 9 using the DallasTemperature library but it doesnt work. Allways remains in 12. Is this a bug in the library?

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

#define ONE_WIRE_BUS 2

//OneWire ds(2);
OneWire oneWire(ONE_WIRE_BUS);


DallasTemperature sensors(&oneWire);


DeviceAddress insideThermometer;
byte value;
int a=0;
int b=0;
byte dire[8];
//byte data[9];
/*
 * Setup function. Here we do the basics
 */
void setup(void)
{
   Serial.begin(9600);
   sensors.begin();
  delay(50);
    //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
   if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
   printAddress(insideThermometer);
 
   sensors.setResolution(insideThermometer,9);
  
   Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();
}

void printTemperature(DeviceAddress deviceAddress)
{
  
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print(b);
    Serial.print("   ");
  Serial.print("Temp C: ");
  Serial.println(int(tempC));
  //Serial.println(sensors.getResolution(insideThermometer), DEC);
  
}

void loop(void)
{ 
 
 // Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  //Serial.println("DONE");
  printTemperature(insideThermometer); // Use a simple function to print out the data
delay(10);
b++;
}

void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    
    Serial.println(deviceAddress[i], DEC);
    
    
  }
}
void recAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
    {
    if (deviceAddress[i] < 16) Serial.print("0");
    EEPROM.write(1011+i,deviceAddress[i]);
    }
  EEPROM.write(1010,1);
  Serial.print(" EEPROM grabada");
}


void checkAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
    {
    if (deviceAddress[i] < 16) Serial.print("0");
    if(EEPROM.read(1011+i)==deviceAddress[i]){
      a++;
   }
 }
 Serial.println(" Checkeado ");
}

The resolution setting command is kosher but you do not seem to be setting the address, so that might have something to do with it. I also believe your loop is too quick, which probably doesn't help.

DeviceAddress insideThermometer = { 0x28,.........etc.

Thank you Nick. I just take the example of the library. And I have only one DS18B20. There is only one address. Everything works fine except the resolution setting. I also tried with a delay after setting.

Your code works for me using the Dallas Temperature library V3.7.7.
I tested it on a Teensy 2 (similar to a Nano) with 7 DS18B20 on the bus. Your code correctly selected the first one on the bus and set it to resolution 9. I used your code to change the resolution to 12 - it worked. And then back to 9 - it worked.

Which Arduino are you using and which version of the Dallas library?

Pete

Pete. I´m using the version 3.8 of Dallas Temperature and an Arduino Uno with only one DS18B20.

And is it wired to 3.3V or 5V?

And do you have a 4.7k pullup resistor on the data line?

Pete

It´s wired to 5v and has a 4k7 pullup resistor. All the others functions work fine. I can read the temps, the address, etc. The only thing I can´t do is to set the resolution. Thanks in advance.