Change Resolution of DS18B20

Hi,
maybe someone can help me with my question ??

Is it possible to change the resolution from 12 to 9 bit permanently - even after power off/on ??

If yes - how can that be done (step by step) with an arduino nano
Will i need additional Hardware ? How must i connect the sensor to the board ??

I am really new with that, sorry for asking that way ....

BR

Harry

I think the answer is no, and it's a pointless exercise anyway. What happens when the power goes off is of no interest. All you need do is call for 9 bit in the setup, and that ensures you will get want you want when the power is turned on.

Hi Nick,
thanks for replying. I did not know that..

BR

Harry

Actually, the answer is yes. You use the WRITE SCRATCHPAD command to write the high and low temperature alarms and the required precision to the scratchpad registers and then issue a COPY SCRATCHPAD command to write those three values to EEPROM. When powered up, the DS18B20 loads the data from these three EEPROM locations back into the scratchpad registers.
See the datasheet.

Pete

Hi Pete,
thanks for your help....
This is a complete new stuff for me and i dont understand all at the moment but i i am really not sure if that will work that way. It would be great if someone can write a comment for the code below....

BR

Harry

See the smileys in the code you posted? They occur because you didn't post your code in code tags.
Read How to post code properly.

Pete

I submit the code you are using is obsolete junk, and the sooner it is wiped out of cyberspace the better. It also goes some way to explain your original question. The only useful line in that code is

// The DallasTemperature library can do all this work for you!

and it is just a comment, not a command.

You might find this a lot more usable - and understandable. At least it doesn't waste your time messing about with sensors you will never see.

Arduino 1-Wire Tutorial.

Note that there are two programmes to use, one to sniff the address and the other to use the sensor.

BTW code like

OneWire  ds(9);  // on pin 10

does not signal clear intent!

Below is an example. The notable thing about it is that it is about 50 lines long

/* Basic 2xDS18B20 code for serial monitor, bluetooth, Excel or w.h.y.
Derived from Hacktronics. USE THEIR ADDRESS SNIFFER, test one sensor at 
a time, and substitute your numbers. 
Use Hacktronics connections diagram. 
http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
Stay away from using parasite power
-127C means bad connection
85 means you haven't gotten a read yet, probably just the 
wrong order of commands
*/

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

// Data wires are plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
  
byte Thermo1[8] = {0x28, 0x39, 0xFD, 0x50, 0x04, 0x00, 0x00, 0X69};
byte Thermo2[8] = {0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95};
float tempC,Temp1,Temp2;  

void setup(){
  Serial.begin(9600);
  sensors.begin();
  delay(500);//Wait for newly restarted system to stabilize
/* // No resolution command means default to 12 bit
  sensors.setResolution(Thermo1, 10); 
  sensors.setResolution(Thermo2, 10);
*/
}

void loop() {
 sensors.requestTemperatures();  // call readings from the addresses
  Temp1 = sensorValue(Thermo1);
  Temp2 = sensorValue(Thermo2);  

Serial.print("      Temp1 = ");
Serial.print(Temp1);
Serial.print("      Temp2 = "); 
Serial.println(Temp2);
delay(1000);
}

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

Hi,
thx for your comment. I already deleted the code and will try your proposal.

Lets see if I get the sensor programmed..As mentioned I only want to set a permanent 9 Bit resolution for the sensor - it will be used with other hard and software later that is not able to query the 9 bit resolution...
I will see if the setResolution will do this - but i have to wait for shipment of my arduino, i am afraid i ve just broken mine...

BR

Harry

backbone10:
I already deleted the code and will try your proposal.

That's a good idea. An even better idea would be for it to be removed from the internet altogether so that newbies are spared a lot of grief..

Lets see if I get the sensor programmed..As mentioned I only want to set a permanent 9 Bit resolution for the sensor - it will be used with other hard and software later that is not able to query the 9 bit resolution...
I will see if the setResolution will do this

This should not be a problem at all, and is the standard procedure for using DS18B20 with Arduino. I guess that other malarky is for people who don't have Arduinos and have nothing better to do, but nobody with an Arduino could possibly maintain it is a good idea. No command default gives 12 bit. I believe 9 bit is the lowest resolution. You just write it as you need it.

  sensors.setResolution(Thermo1, 9); 
  sensors.setResolution(Thermo2, 9);

I don't know what the results of that are but if your other stuff is 9 bit I guess you've got that all worked out!

Note that the code I listed is slightly different from the tutorial. I think it's a better way to go, but I can't remember why.