#include <OneWire.h>
/* DS2438 Sensor chip i/o */
OneWire ds(10); // on pin 10
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
byte i;
// byte present = 0;
byte data[12];
byte addr[8] = {0x26, 0x3A, 0xD5, 0x7, 0x1, 0x0, 0x0, 0xE2};
/* //These if-loops finds all the individual serial codes and then we just used one (the one above)
if ( !ds.search(addr)) {
Serial.print("No more addresses.\n");
ds.reset_search();
delay(250);
return;
}
Serial.print("R=");
for( i = 0; i < 8; i++) {
Serial.print(addr[i], HEX);
Serial.print(" ");
}
//CRC
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}
To check if the chip is in whatever the DSx familiy because they all have the same first byte in their unique serial codes
its unecessary
if ( addr[0] != 0x10) {
Serial.print("Device is not a DS18S20 family device.\n");
return;
}*/
/configure chip to read VAD and not VDD
ds.reset();
ds.reset(); //two resets for good luck
ds.select(addr);
ds.write(0x00);
ds.write(0x07);
ds.reset();
ds.reset();
ds.select(addr);
ds.write(0x48); //copy scratchpad
ds.write(0x00);
delay(1500);
ds.reset();
ds.reset();
ds.select(addr);
ds.write(0xBE);
ds.write(0xFF);
ds.write(0xFF);
ds.reset();
Configuration complete
ds.reset();
ds.reset();
ds.select(addr);
ds.write(0x44); // start temperature conversion
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
ds.reset();
ds.reset();
//present = ds.reset();
ds.select(addr);
ds.write(0xB4); //Convert voltage
delay(1000);
//current readings are updated automatically
ds.reset();
ds.reset();
ds.select(addr);
ds.write(0xB8); //recall
ds.write(0x00);
ds.reset();
ds.reset();
ds.select(addr);
ds.write(0xBE); //Read Scratchpad
ds.write(0x00);
Serial.print("P=");
//Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes, last one for CRC
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print( OneWire::crc8( data, 8), HEX);
Serial.println();
}