I have read once, a long time ago, it must be possible to read the ID from a DS1820
i need it, to fix more than 1 DS1820 one wire digital thermometer
Can someone help me to find out, how to get the ID from the DS1820
I have read once, a long time ago, it must be possible to read the ID from a DS1820
i need it, to fix more than 1 DS1820 one wire digital thermometer
Can someone help me to find out, how to get the ID from the DS1820
Install DallasTemperature.h library and try with this:
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// variable to hold device addresses
DeviceAddress Thermometer;
int deviceCount = 0;
void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.println("Locating devices...");
Serial.print("Found ");
deviceCount = sensors.getDeviceCount();
Serial.print(deviceCount, DEC);
Serial.println(" devices.");
Serial.println("");
Serial.println("Printing addresses...");
for (int i = 0; i < deviceCount; i++)
{
Serial.print("Sensor ");
Serial.print(i+1);
Serial.print(" : ");
sensors.getAddress(Thermometer, i);
printAddress(Thermometer);
}
}
void loop(void)
{}
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
Serial.print("0x");
if (deviceAddress[i] < 0x10) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
if (i < 7) Serial.print(", ");
}
Serial.println("");
}
I assume:
DS18B20
Sketch to read and Display 64-bit ROM Code (ID) of DS18B20 Sensor:
#include<OneWire.h>
OneWire ds(7); //DPin-7 of UNO with data line of DS18B20
byte addrs[8]; //to hold 64-bit ROM Codes of DS
void setup()
{
Serial.begin(9600);
ds.reset(); //sensor reset
ds.search(addrs); //collect 64-bit ROM code from sensor (DS1)
for(int i = 0; i < 8; i++)
{
byte y = addrs[i];
if(y < 0x10)
{
Serial.print('0'); //print leading zero
}
Serial.print(y, HEX);
Serial.print(' '); //insert space
}
}
void loop(){}
Tester.ino
Not needed if you read the sensors by index.
sensors.requestTemperatures();
float temp1 = sensors.getTempCByIndex(0);
float temp2 = sensors.getTempCByIndex(1);
Leo..
I wish I understood which sensor goes where......
Simple, run the code and then warm only one up, it will become obvious. Have fun!
Yes
Or, just do one temperature sensor at a time, write down this value to use at a later time.
This sketch looks for 1-wire devices and
// prints their addresses (serial number) to
// the UART, in a format that is useful in Arduino sketches
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
#include <OneWire.h>
OneWire ds(3); // Connect your 1-wire device to pin 3
void setup(void) {
Serial.begin(9600);
discoverOneWireDevices();
}
void discoverOneWireDevices(void) {
byte i;
byte present = 0;
byte data[12];
byte addr[8];
Serial.print("Looking for 1-Wire devices...\n\r");
while(ds.search(addr)) {
Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");
for( i = 0; i < 8; i++) {
Serial.print("0x");
if (addr[i] < 16) {
Serial.print('0');
}
Serial.print(addr[i], HEX);
if (i < 7) {
Serial.print(", ");
}
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}
}
Serial.print("\n\r\n\rThat's it.\r\n");
ds.reset_search();
return;
}
void loop(void) {
// nothing to see here
}
In proper code with specified addresses.
Thank you all for these info
I have a program that displays the address of the sensor. I get the address of sensors one at a time and write the address on a tag that I put on the sensor cable.
When using multiple sensors I use get by address and use the addresses on the tags to know which sensor it is.
Another neat option is to write the addresses on heat shrink tubing. This also enables you to group sensors by colour.
is it also possible the get the degrees character on a LCD?
Try char(0xDF)
The DS18B20 has 2 alarm fields (2 bytes)
If you do not use them for alarms you can set your own 16 bit identifier in it .
Might be an option.
thank you, but i dont get it in my serial monitor, is that correct?
Yes only on LCD
but is it possible, to get it there too?
It's an unprintable character so I don't think it is possible.
Maybe someone else knows how.