#include #include #define DISPLAY_ADDRESS1 0x71 //This is the default address of the OpenSegment with both solder jumpers open // DS18S20 Temperature chip i/o OneWire ds(10); // on pin 10 void setup(void) { Wire.begin(); //Join the bus as master // initialize inputs/outputs // start serial port lookUpSensors(); //Send the reset command to the display - this forces the cursor to return to the beginning of the display Wire.beginTransmission(DISPLAY_ADDRESS1); Wire.write('v'); Wire.endTransmission(); } void lookUpSensors() { byte address[8]; int i=0; byte ok = 0, tmp = 0; while (ds.search(address)) { tmp = 0; //0x10 = DS18S20 if (address[0] == 0x10) { tmp = 1; } else { //0x28 = DS18B20 if (address[0] == 0x28) { tmp = 1; } } //display the address, if tmp is ok if (tmp == 1) { if (OneWire::crc8(address, 7) != address[7]) { // but it doesn't have a valid CRC! } else { ok = 1; } }//end if tmp }//end while } int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract; void loop(void) { byte i; byte present = 0; byte data[12]; byte addr[8]; byte dscount = 0; while (ds.search(addr)) { 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(); } 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 Whole = Tc_100 / 100; // separate off the whole and fractional portions Fract = Tc_100 % 100; // Output the value to the Display // First write delimiter and Sign for first or second DS. Wire.beginTransmission(DISPLAY_ADDRESS1); Wire.write(0x77); if (dscount ==0) { Wire.write(0x22); } else { Wire.write(0x02); } Wire.endTransmission(); // write Value to Display Wire.beginTransmission(DISPLAY_ADDRESS1); byte value = Whole / 10; Wire.write(value); value = Whole % 10; Wire.write(value); value = Fract / 10; Wire.write(value); value = Fract % 10; Wire.write(value); Wire.endTransmission(); dscount++; } }