Pages: [1]   Go Down
Author Topic: DS 18S20+ Temperatur Umrechnungsfaktor?  (Read 404 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo,

ich versuche die Temperatur aus einem DS18S20+ auszulesen, bekomme aber eine etwas zu hohe Temperatur heraus (~26 statt 21 °C):

Code:
int temperatur(void) {
  byte i;
  byte present = 0;
  byte data[12];
  int Tc_100 = 0;
  int HighByte, LowByte, TReading, SignBit;
 
  byte addr[8]={16,98,181,116,2,8,0,84}; // Adresse meines Sensors
 
 

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      //Serial.print("CRC is not valid!\n");
      return -2000;
  }
 
  if ( addr[0] != 0x10) {
      //Serial.print("Device is not a DS18S20 family device.\n");
      return -2000;
  }

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

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
 
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
 
  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);         // Read Scratchpad
 
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  } 

 
 
  // Temeperatur bestimmen
  LowByte = data[0];
  HighByte = data[1];
 
 
  TReading = (HighByte << 8) + LowByte;
 
  SignBit = TReading & 0x8000;  // test most sig bit
 
  if (SignBit) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
 
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25
 
  return Tc_100;
 
}

Ist der Umrechnungsfaktor möglicherweise falsch?

Danke

Gruß

Mebus

Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 347
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

warum so kompliziert mit umrechnen?
Es gibt doch ganz einfache Befehle:

sensors.requestTemperatures();
  Temperatur[0] = sensors.getTempC(Sensor0); Temperatur[1] = sensors.getTempC(Sensor1);
  Temperatur[2] = sensors.getTempC(Sensor2); Temperatur[3] = sensors.getTempC(Sensor3);
  Temperatur[4] = sensors.getTempC(Sensor4); Temperatur[5] = sensors.getTempC(Sensor5);

und schon hat man 6 Temperaturen eingelesen in °C.
gruß
Bernward
Logged

Forum Moderator
BZ (I)
Offline Offline
Brattain Member
*****
Karma: 236
Posts: 20281
+39 349 2158303
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

warum so kompliziert mit umrechnen?
Es gibt doch ganz einfache Befehle:

sensors.requestTemperatures();
  Temperatur[0] = sensors.getTempC(Sensor0); Temperatur[1] = sensors.getTempC(Sensor1);
  Temperatur[2] = sensors.getTempC(Sensor2); Temperatur[3] = sensors.getTempC(Sensor3);
  Temperatur[4] = sensors.getTempC(Sensor4); Temperatur[5] = sensors.getTempC(Sensor5);

und schon hat man 6 Temperaturen eingelesen in °C.
gruß
Bernward

Dann müßtest Du noch sagen, welche Bibliothek zu verwenden ist?
Grüße Uwe
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 347
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ja stimmt,

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

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So geht's auch: siehe Anhang.



* 1wire.png (61.01 KB, 883x217 - viewed 29 times.)
Logged

Pages: [1]   Go Up
Jump to: