0

I found a batch of DS1820 in my drawers; they worked 10 years ago on a DS9097U-09 onewire to RS232 converter. Note, not DS18B20

I use them in parasite power mode; pin 1 and 3 together to gnd.

But when I connect them to an Arduino scetch, they are identified, but read no temperature, only FF FF FF FF FF FF FF FF with correct CRC C9, so it's not data being garbled; it must be the polling of data which is not right.

Are the DS18(S)20 compatible with the standard Arduino lib?

I'm using this:

https://www.elec-cafe.com/temperature-sensor-on-the-web-with-esp8266-and-ds18b20/

shown with the irellevant parts removed below:

#include <OneWire.h>

OneWire  ds(D7);  // on pin 7 (a 4.7K resistor is necessary)


void loop() {

  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;

  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(1000);
    return;
  }

  Serial.print("ROM =");
  for ( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

 if (OneWire::crc8(addr, 7) != addr[7]) {
    Serial.println("CRC is not valid!");
    return;
  }
  Serial.println();

  // the first ROM byte indicates which chip
 switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
     type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  }

  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

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.println(" Celsius, ");
}

I get this (I have a string of 6 on a 10m at least 2-wire cable),

ROM = 10 28 6A C6 0 8 0 6
  Chip = DS18S20
  Data = 1 FF FF FF FF FF FF FF FF FF  CRC=C9
  Temperature = -0.50 Celsius, 
ROM = 10 CC 49 C6 0 8 0 45
  Chip = DS18S20
  Data = 1 FF FF FF FF FF FF FF FF FF  CRC=C9
  Temperature = -0.50 Celsius, 
...
No more addresses.

I get the same result if I only use one DS18(S)20.

Another sketch using DallasTemperature.h is not working either:

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

#define ONE_WIRE_BUS D7

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
....
void setup(void){
  DS18B20.begin();
}

float getTemperature() {
  float temp;
  do {
    DS18B20.requestTemperatures(); 
    temp = DS18B20.getTempCByIndex(0);
    delay(1000);
    Serial.println(".");
  } while (temp == 85.0 || temp == (-127.0));
  return temp;
}

.. just hangs in this while loop.

  • It's interesting that each library reports different (wrong) temp values. The DallasTemperature readme does say that "there appears to be an issue with the DS18S20 series" so you should probably abandon that. You can try the sketch here instead github.com/jerkey/DS18S20, only requires the OneWire lib. A github search for "DS18S20" will turn up other options. – TisteAndii Feb 24 '18 at 22:57
  • hangs in this while loop - hangs? or prints . every second? – Jaromanda X Feb 25 '18 at 1:46
  • Just loops. Never get anything but invalid values. – Lenne Feb 25 '18 at 8:09
  • @TisteAndii, Tried that ino, returns 4095.94C or 7404.69F :-( – Lenne Feb 25 '18 at 8:34
  • Have you compared the datasheets for the two devices to see what differences there are? – Majenko Feb 25 '18 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.