ds18b20 round to __ .00 ???

Please help
I found thisk sketch on web and work nice with my UNO R3 (1.0.6 ) and W5100.

I can’t found a possibility to set the resolution (10,11,12 byte) ? I try to change everything but the result always finish with .00 . WHY :angry:

/*
Fermenter Web Server
 * Ethernet shield attached to pins 10, 11, 12, 13
 Created June 26, 2013
 by atoughram
 */
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,5,37);
EthernetServer server(80);
OneWire ds(2);

//Set up some variables
byte i, ii; //array pointers
byte dev[8] [8]; //device array
byte devpr; //Number of devices present

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());

  //Find all of the Onewire devices connected to pin 9
  for (ii = 0; ii < 8; ii++) { //Up to eight devices
    if (!ds.search(dev[ii])){ //if no devices found
      Serial.println("No more devices found! ");
      devpr = ii;
      Serial.print("Number of devices found equal ");
      Serial.println(devpr);
      ds.reset_search();
      delay(250);
      return;
    }}}

void loop() {
  byte present = 0;
  byte data [8] [12];// 8  12
  int16_t raw [8];//8
  float celsius [8] ;//8

  //Print out the device serial numbers
  for( ii = 0; ii < devpr; ii++) { 
    Serial.print("ROM =");
    for( i = 0; i < 8; i++) {
      Serial.write(' ');
      Serial.print(dev[ii][i], HEX);
    }
    Serial.println(""); 
  }
  //Let get some data!
  for( ii = 0; ii < devpr; ii++) { //Select which device
    ds.reset();
    ds.select(dev[ii]);
    ds.write(0x44, 1); //(bilo je 1 sad je 10) start conversion, with parasite power on at the end
    delay(1000); // data 750ms is enough, maybe not
    present = ds.reset();
    ds.select(dev[ii]); 
    ds.write(0xBE); // Read Scratchpad
    for ( i = 0; i < 9; i++) { // we need 9 bytes
      data[ii][i] = ds.read();
    }
  }
  //Conversion time...
  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor. 
  for( ii = 0; ii < devpr; ii++) {
    raw [ii]= (data[ii][1] << 8) | data[ii][0]; // bilo je 0
    raw [ii]= (raw [ii] & 0xFFF0) + 12 - data[ii][6];
    celsius [ii] = (float)raw [ii] / 16.0;
    Serial.print(" Temperature = ");
    Serial.print(celsius [ii]);
    Serial.print(" Celsius, ");
  }
  // listen for incoming clients on the Ethernet
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close"); // the connection will be closed after completion of the response
          client.println("Refresh: 5"); // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html><title>PELETKOTLOVNICA</title>");
          client.println("<font face = arial>");
          client.println("<body BGCOLOR='#FF5930'>");
          client.println("<h3 style='text-align: center;'>TEMPERATURE U KOTLOVNICI</h3>");
          client.println("<body>");
          client.println("<tr>");
          client.print("<hr><font size=+2 center color=#000014>temp. kotla  <b>");
          client.print(celsius [0]);
          client.println("&degC</b></font></hr>");
          client.print("<hr><font size=+2 center color=#000014>temp. bojlera  <b>");
          client.print(celsius [1]);
          client.println("&degC</b></font></td></hr>");
          client.println("<hr></hr>");
          /* client.print("<tr><td><font size=+10 color=#3399cc>Sensor 3 <b>"); //Commented out - comment in whichever sensors your going to use. 
           client.print( [2]); //If celsius is preferred, change variable fahrenheit to celcius
           client.println("&degC</b></font></td>"); //If celsius is preferred, change f at beginning of line to c
           client.print("<td><font size=+10 color=#3399cc>Sensor 4 <b>");
           client.print(celsius [3]);
           client.println("&degC</b></font></td></tr>");
           client.print("<tr><td><font size=+10 color=#3399cc>Sensor 5 <b>");
           client.print(celsius [4]);
           client.println("&degC</b></font></td>");
           client.print("<td><font size=+10 color=#3399cc>Sensor 6 <b>");
           client.print(celsius [5]);
           client.println("&degC</b></font></td></tr>");
           client.print("<tr><td><font size=+10 color=#3399cc>Sensor 7 <b>");
           client.print(celsius [6]);
           client.println("&degC</b></font></td>");
           client.print("<td><font size=+10 color=#3399cc>Sensor 8 <b>");
           client.print(celsius [7]);
           client.println("&degC</b></font></td></tr>"); */
          client.println("</body>");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

tnx ;D

You are using code intended for a DS18S20
Replace this line:

    raw [ii]= (raw [ii] & 0xFFF0) + 12 - data[ii][6];

with this:

    byte cfg = (data[ii][4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00)      raw[ii] = raw[ii] & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw[ii] = raw[ii] & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw[ii] = raw[ii] & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time

To set the precision, in the setup() function change this line:

    }}}

with this:

//       bits
//        of
//     precision
// 0   -   9
// 1   -  10
// 2   -  11
// 3   -  12

  // For 9 bit precision
      int t_precision = 0;
      ds.select(dev[ii]);    
      ds.write(0x4E);
      // write zero into the alarm registers
      ds.write(0);
      ds.write(0);
      // and write t_precision into the configuration register
      // to select the precision of the temperature
      ds.write(t_precision << 5);
      // Write them to the EEPROM
      ds.write(0x48);
    }
  }
}

Pete

To truncate the result add , 0 to Serial.print(celsius [ii]); Like so: Serial.print(celsius [ii], 0); Changing the 0 to a value > 0 will set the places displayed after the decimal point.

:grin: Thanks, now works as I imagined. The code is very complicated for me as a beginner I would never solve it. Now I go on adding more inputs, so if I get stuck I know that there is a great forum which can help.

THANKS AGAIN