Pages: [1] 2   Go Down
Author Topic: ds18b20 bad resolution set at 11bit  (Read 2233 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is my first arduino project it is a reef controller and it seems to have bad tempurture resolution to me and I wanted to know if this seems normal if my temp is 78.12 deg F the next step would be 78.42 each increment is about .3 degrees is this right I was hoping for better

here is the code I cropped most of my project so it would be easier to find a problem hopefully I didnt take anything out needed
Code:
#include <SimpleTimer.h>
#include <EEPROMAnything.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Button.h>


SimpleTimer timer;




#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);
DeviceAddress Sump;


 void setup(void)
{

  lcd.begin(20, 4);
  sensors.begin();
  (!sensors.getAddress(Sump, 0));
  sensors.setResolution(Sump, 11);
 
 }

void printTemperature(DeviceAddress deviceAddress)
{
  
  hightempsp = (lowtempsp + 00.10);
    sump = sensors.getTempF(deviceAddress);
   if ((sump < lowtempsp) && (sump > 45)) digitalWrite(heaterpin, HIGH);
   if (sump > hightempsp) digitalWrite(heaterpin, LOW);
   if (sump > tempmax) tempmax = sump;
   if (sump < tempmin) tempmin = sump;
  
}

void loop(void)
{
  

  sensors.requestTemperatures(); // Send the command to get temperatures
  printTemperature(Sump); // Use a simple function to print out the data
}
« Last Edit: May 09, 2013, 11:28:23 pm by Sanddune600 » Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 47
Posts: 2261
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is only one line in your code that has any relevance.

  sensors.setResolution(Sump, 11);

You can change this to 12. This smacks rather of the dog-chasing-car scenario.

I believe most people set the resolution to 10.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have tried 8 9 10 11 12 it gets better but I thought I would be getting better resolution than .3 increments is this normal for this sensor
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3677
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a DS18B20 recording temperatures in my house with 12 bit resolution. I see resolution down to 0.01 degrees F in the range I commonly get, i.e. I see 66.00, 66.01 ... 66.98, 66.99 etc in my data.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13664
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@: Sanddune600
Cannot compile your posted code.

furthermore,
- the line   (!sensors.getAddress(Sump, 0));  does nothing.

- The DS18B20 has 4 bits fractional part in 12 bit. == stepsize 0.0625 C == ~0.12  F
This stepsize of 0.12F makes the hysteresis control with a margin of 0.10 F really living on the edge as the last bit in every digital sensor can be considered (including the) noise. Think you should increase that to at least 0.5F.

Tip, press CTRL-T before saving and copying gives nicer layout.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(!sensors.getAddress(Sump, 0));  this line calls the address at device 0 and anytime call on the word Sump it is really seeing that address from there I tried taking it out of my code and it gives me a temp of -196.60 all the time just to be sure


sorry it doesn't compile I cropped my code to make it fit in the forum
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13664
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
(!sensors.getAddress(Sump, 0));  this line calls the address at device 0 and anytime call on the word Sump it is really seeing that address from there I tried taking it out of my code and it gives me a temp of -196.60 all the time just to be sure

OK, I had to make myself more explicit (hurry is seldom good), what I really meant is that the ! (negation) does not have any value.


Quote
sorry it doesn't compile I cropped my code to make it fit in the forum
I prefer cropping it to a minimal version that runs and still shows the bug. That makes it much easier to verify what is going on.
If I first need to fix the code to get it running I may(will) introduce new bugs of my own smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the problem doesnt seem to lie in the code I have tried several others codes as well this thing was running smooth on the prototype breadbaord transfered it to the project box and smiley-eek-blue smiley-eek-blue now I have tried multiple codes a different sensor a different arduino board pariste mode on and off tried different resistor I am at a loss I noticed that I forgot to mention that it was working till I transfered half of the project but the sensor stayed wired and intack on the breadboard I get consistant results with my reading but not what I was getting
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13664
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


And when you use 9,10,12 bit you get correct results?


Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

temp is right I just only get tempuraters that display 78.12 -->78.23 --> 78.34 and so on I never get anything in between those numbers just jumps in the reading same no matter what code I find the resolution changes it in the increments that I see at 9 bit my temps look like this 78.00 79.50 81.00 I keep thinking its a programming issue but it isnt I get the same results with multiple codes written by others
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1614
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote from: wildbill
I have a DS18B20 recording temperatures in my house with 12 bit resolution.
Are you also using the DallasTemperature library?
I used that about a year ago and got strange results and ever since I have been using the OneWire library maintained by Paul@PJRC and have had no problems with it.

Pete
Logged

Where are the Nick Gammons of yesteryear?

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


- The DS18B20 has 4 bits fractional part in 12 bit. == stepsize 0.0625 C == ~0.12  F
This stepsize of 0.12F makes the hysteresis control with a margin of 0.10 F really living on the edge as the last bit in every digital sensor can be considered (including the) noise. Think you should increase that to at least 0.5F.

temp is right I just only get tempuraters that display 78.12 -->78.23 --> 78.34 and so on I never get anything in between those numbers just jumps in the reading same no matter what code I find the resolution changes it in the increments that I see at 9 bit my temps look like this 78.00 79.50 81.00 I keep thinking its a programming issue but it isnt I get the same results with multiple codes written by others

Did you read what robtillaart wrote?  The sensor can only give that level of resolution maximally (.12F roughly).  12 bit mode only gives four places to the right of the decimal point.  This is .0625C resolution.  That's pretty much as good as it gets.

There is a sensor model that will give you a "remainder" count from the internal ADC.  This will allow you to calculate to a higher resolution.
Logged

Experience, it's what you get when you were expecting something else.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is a code that runs instead of printing it to lcd it is in serial so no need for extra hardware I am just confused because it was working better and now it has bad resolution

Quote

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


#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress Sump;

int heaterpin = 10, alkpin = 12, calpin = 13, ato = 11, alarmpin = 8; //digital outputs
int PH_READ_PIN = A0;                                                 //analog inputs


 float tempmax, tempmin;
 float sump, PH;
 int alkml, calml;
 float alksp, calsp;
 float lowtempsp, hightempsp, Mlowtempsp;
 byte menustate = 0, alarmstate = 0, alarmmenureset = 0,menureset = 0;
 int Ealksp = 0;
 int Ecalsp = 0;
 int Rcalsp;
 int Ralksp;
 int Elowtempsp = 2;
 int lowtempspstart;
 int Wlowtempsp;
 boolean alkcheck = false, calcheck = false;
 int CAL, ALK;
 const float pumpspeed = (float)60 / (float)1.1;
 boolean hitemp = false,lowtemp = false, hilevel = false, checkfloats = false, lowfloatfault = false, highfloatfault = false;
 void setup(void)
{
  Serial.begin(9600);

  sensors.begin();
  (!sensors.getAddress(Sump, 0));
  sensors.setResolution(Sump, 11);



  lowtempsp = lowtempspstart / (float)100;


  //timer.setInterval(360000000, hourpulse);      

  alkml = alksp * pumpspeed;
  calml = calsp * pumpspeed;
  tempmax = 78;
  tempmin = 78;
Serial.begin(9600);
 
 }

void alarms()
{
if (sump > 82) hitemp = true;
if (sump < 76) lowtemp = true;


if (alarmmenureset >= 2) alarmstate++, alarmmenureset = 0;
if (alarmstate >= 6) alarmstate = 0;
if (menustate == 0)
{

hitemp = false;
lowtemp = false;
hilevel = false;
checkfloats = false;
lowfloatfault = false;
highfloatfault = false;

}  
}




void printTemperature(DeviceAddress deviceAddress)
{
  
  hightempsp = (lowtempsp + 00.10);
    sump = sensors.getTempF(deviceAddress);
   if ((sump < lowtempsp) && (sump > 45)) digitalWrite(heaterpin, HIGH);
   if (sump > hightempsp) digitalWrite(heaterpin, LOW);
   if (sump > tempmax) tempmax = sump;
   if (sump < tempmin) tempmin = sump;
  
}


void loop(void)
{
  Serial.print(sump);
  Serial.println();
  alarms();

  //getPH();

  sensors.requestTemperatures(); // Send the command to get temperatures
  printTemperature(Sump); // Use a simple function to print out the data
}

« Last Edit: May 11, 2013, 03:09:17 pm by Sanddune600 » Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 47
Posts: 2261
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Here is a code that runs instead of printing it to lcd it is in serial so no need for extra hardware

It's too hard to sort out what's relevant in your code. There may also one library more than you really need, which may imply a problem. Below is probably the most basic code you can get that can use the Dallas one-wire bus. It is from Hacktronics. While resolution 10 is said to be good enough, I use 12. I find the DS18B20 pretty robust but, if this code won't deliver, it may be a hardware or power supply problem.

Code:

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

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
DeviceAddress Thermo = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
 
  sensors.setResolution(Thermo, 12);
}

void loop(void)
{
  delay(1000);
  sensors.requestTemperatures();
 
  Serial.print("Temperature is: ");
  printTemperature(Thermo);
  }

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
     Serial.println(tempC);
  }

Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I noticed that I forgot to mention that it was working till I transfered half of the project but the sensor stayed wired and intack on the breadboard I get consistant results with my reading but not what I was getting

So why do you think it might be the sketch?? From what you have said, it was working as you expected but then you 'moved half the project' - not sure exactly what you mean by this??

Have you changed the way the 18B20 is powered? Have you extended the distance between the Arduino and the 18B20?
Logged

Pages: [1] 2   Go Up
Jump to: