Hello all, I am using 10 ds18b20 Temperature sensors using with "DS2482-100" I2C board
so when I am getting the output like this:- "ROM = 28 46 04 1F 0D 00 00 74 96014B467FFF0A100A 25.3 2699 Dc", so Instead of address I want to name it "Sensor-1" any tutorial or help would be appreciated.
/*
Arduino library for controlling DS2482-100 and DS2482-800 1-wire masters.
Uses Wire library to communicate with DS2482 so be sure to call Wire.begin() before using the library.
Quick example modeled after Onewire example:
*/
#include <OneWire.h>
#include <Wire.h>
#include <DS2482.h>
#include <DallasTemperature.h>
DS2482 ds(0); //channels ds2482-800 is 0 to 7, DS2482-100 is just set 0
byte data[9]; //holding for onewire capture
byte addr[9]; //1wire wire address and CRC
long time_temp;
uint8_t sensor1[8] = { 0x28, 0x00, 0xF9, 0x1E, 0x0D, 0x00, 0x00, 0x76 };
uint8_t sensor3[8] = { 0x28, 0x61, 0x64, 0x12, 0x3F, 0xFD, 0x80, 0xC6 };
void setup()
{
Wire.begin();
ds.reset();
pinMode(13, OUTPUT);
// start serial port
Serial.begin(57600);
time_temp = millis();
}
void loop()
{
//do search
if ( !ds.wireSearch(addr))
{
if(addr == sensor1)
{
Serial.print("sensor1");
};
Serial.print("No more addresses.\n");
ds.wireResetSearch();
return;
}
Serial.print("ROM =");
for ( int i = 0; i < 8; i++) {
Serial.write(' ');
if (addr[i] < 16) Serial.print("0");
Serial.print(addr[i], HEX);
}
if (ds.crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
//test if device code DS18b20
if (addr[0] == 0x28) {
//read temperature data.
ds.wireReset();
ds.selectChannel(0);
ds.wireSelect(addr);
ds.configure(0x05); //set bus on strong pull-up after next write until next command
ds.wireWriteByte(0x44); //convert temperature on this device
delay(770); //wait for conversion 750ms Plus margin
ds.wireReset();
ds.selectChannel(0);
ds.wireSelect(addr);
ds.wireWriteByte(0xbe); // Read Scratchpad command
//display hex values of scratchpad
Serial.print(" ");
for ( int i = 0; i < 9; i++) { // we need 9 bytes to capture CRC
data[i] = ds.wireReadByte();
if (data[i] < 16)Serial.print("0");
Serial.print(data[i], HEX);
}
Serial.print(" ");
//convert to decimal temperature
int LowByte = data[0];
int HighByte = data[1];
int TReading = (HighByte << 8) + LowByte;
int SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
int Tc_100 = (double)TReading * 0.0625 * 10;
if (SignBit) // If its negative
{
Tc_100 = 0 - Tc_100;
}
//print temp for each device
Serial.print(Tc_100 / 10);
Serial.print(".");
Serial.print(Tc_100 % 10);
Serial.print(" ");
Serial.print(millis() - time_temp);
Serial.println(" Dc");
}
}