DS1822 Programming (Assigning name for each sensor)


hello!

i found code hacktronics.com

code: [select]

//  this arduino sketch reads ds18b20 "1-wire" digital
//  temperature sensors.
//  copyright (c) 2010 mark mccomb, hacktronics llc
//  license: http://www.opensource.org/licenses/mit-license.php (go crazy)
//  tutorial:
//  http://www.hacktronics.com/tutorials/arduino-1-wire-tutorial.html

#include <onewire.h>
#include <dallastemperature.h>

// data wire plugged pin 3 on arduino
#define one_wire_bus 3

// setup onewire instance communicate onewire devices
onewire onewire(one_wire_bus);

// pass our onewire reference dallas temperature.
dallastemperature sensors(&onewire);

// assign addresses of 1-wire temp sensors.
// see tutorial on how obtain these addresses:
// http://www.hacktronics.com/tutorials/arduino-1-wire-address-finder.html

deviceaddress insidethermometer = { 0x28, 0x94, 0xe2, 0xdf, 0x02, 0x00, 0x00, 0xfe };
deviceaddress outsidethermometer = { 0x28, 0x6b, 0xdf, 0xdf, 0x02, 0x00, 0x00, 0xc0 };
deviceaddress doghousethermometer = { 0x28, 0x59, 0xbe, 0xdf, 0x02, 0x00, 0x00, 0x9f };

void setup(void)
{
 // start serial port
 serial.begin(9600);
 // start library
 sensors.begin();
 // set resolution 10 bit (good enough?)
 sensors.setresolution(insidethermometer, 10);
 sensors.setresolution(outsidethermometer, 10);
 sensors.setresolution(doghousethermometer, 10);
}

void printtemperature(deviceaddress deviceaddress)
{
 float tempc = sensors.gettempc(deviceaddress);
 if (tempc == -127.00) {
   serial.print("error getting temperature");
 } else {
   serial.print("c: ");
   serial.print(tempc);
   serial.print(" f: ");
   serial.print(dallastemperature::tofahrenheit(tempc));
 }
}

void loop(void)
{
 delay(2000);
 serial.print("getting temperatures...\n\r");
 sensors.requesttemperatures();
 
 serial.print("inside temperature is: ");
 printtemperature(insidethermometer);
 serial.print("\n\r");
 serial.print("outside temperature is: ");
 printtemperature(outsidethermometer);
 serial.print("\n\r");
 serial.print("dog house temperature is: ");
 printtemperature(doghousethermometer);
 serial.print("\n\r\n\r");
}


could teach me on how modify code use loop printing deviceaddress name , temperature reading?

quote
can modify code use loop printing deviceaddress name , temperature reading?

of course can.


Arduino Forum > Using Arduino > Programming Questions > DS1822 Programming (Assigning name for each sensor)


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support