primer commit probando arduino, va el .ino de sensor de temperatura y humedad
This commit is contained in:
162
libraries/DallasTemperature/examples/Alarm/Alarm.pde
Normal file
162
libraries/DallasTemperature/examples/Alarm/Alarm.pde
Normal file
@ -0,0 +1,162 @@
|
||||
#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 (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
// arrays to hold device addresses
|
||||
DeviceAddress insideThermometer, outsideThermometer;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
// start serial port
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
||||
|
||||
// Start up the library
|
||||
sensors.begin();
|
||||
|
||||
// locate devices on the bus
|
||||
Serial.print("Found ");
|
||||
Serial.print(sensors.getDeviceCount(), DEC);
|
||||
Serial.println(" devices.");
|
||||
|
||||
// search for devices on the bus and assign based on an index.
|
||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
|
||||
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
|
||||
|
||||
// show the addresses we found on the bus
|
||||
Serial.print("Device 0 Address: ");
|
||||
printAddress(insideThermometer);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Device 0 Alarms: ");
|
||||
printAlarms(insideThermometer);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Device 1 Address: ");
|
||||
printAddress(outsideThermometer);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Device 1 Alarms: ");
|
||||
printAlarms(outsideThermometer);
|
||||
Serial.println();
|
||||
|
||||
Serial.println("Setting alarm temps...");
|
||||
|
||||
// alarm when temp is higher than 30C
|
||||
sensors.setHighAlarmTemp(insideThermometer, 30);
|
||||
|
||||
// alarm when temp is lower than -10C
|
||||
sensors.setLowAlarmTemp(insideThermometer, -10);
|
||||
|
||||
// alarm when temp is higher than 31C
|
||||
sensors.setHighAlarmTemp(outsideThermometer, 31);
|
||||
|
||||
// alarn when temp is lower than 27C
|
||||
sensors.setLowAlarmTemp(outsideThermometer, 27);
|
||||
|
||||
Serial.print("New Device 0 Alarms: ");
|
||||
printAlarms(insideThermometer);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("New Device 1 Alarms: ");
|
||||
printAlarms(outsideThermometer);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// function to print a device address
|
||||
void printAddress(DeviceAddress deviceAddress)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
if (deviceAddress[i] < 16) Serial.print("0");
|
||||
Serial.print(deviceAddress[i], HEX);
|
||||
}
|
||||
}
|
||||
|
||||
// function to print the temperature for a device
|
||||
void printTemperature(DeviceAddress deviceAddress)
|
||||
{
|
||||
float tempC = sensors.getTempC(deviceAddress);
|
||||
Serial.print("Temp C: ");
|
||||
Serial.print(tempC);
|
||||
Serial.print(" Temp F: ");
|
||||
Serial.print(DallasTemperature::toFahrenheit(tempC));
|
||||
}
|
||||
|
||||
void printAlarms(uint8_t deviceAddress[])
|
||||
{
|
||||
char temp;
|
||||
temp = sensors.getHighAlarmTemp(deviceAddress);
|
||||
Serial.print("High Alarm: ");
|
||||
Serial.print(temp, DEC);
|
||||
Serial.print("C/");
|
||||
Serial.print(DallasTemperature::toFahrenheit(temp));
|
||||
Serial.print("F | Low Alarm: ");
|
||||
temp = sensors.getLowAlarmTemp(deviceAddress);
|
||||
Serial.print(temp, DEC);
|
||||
Serial.print("C/");
|
||||
Serial.print(DallasTemperature::toFahrenheit(temp));
|
||||
Serial.print("F");
|
||||
}
|
||||
|
||||
// main function to print information about a device
|
||||
void printData(DeviceAddress deviceAddress)
|
||||
{
|
||||
Serial.print("Device Address: ");
|
||||
printAddress(deviceAddress);
|
||||
Serial.print(" ");
|
||||
printTemperature(deviceAddress);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void checkAlarm(DeviceAddress deviceAddress)
|
||||
{
|
||||
if (sensors.hasAlarm(deviceAddress))
|
||||
{
|
||||
Serial.print("ALARM: ");
|
||||
printData(deviceAddress);
|
||||
}
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
Serial.print("Requesting temperatures...");
|
||||
sensors.requestTemperatures();
|
||||
Serial.println("DONE");
|
||||
|
||||
// Method 1:
|
||||
// check each address individually for an alarm condition
|
||||
checkAlarm(insideThermometer);
|
||||
checkAlarm(outsideThermometer);
|
||||
/*
|
||||
// Alternate method:
|
||||
// Search the bus and iterate through addresses of devices with alarms
|
||||
|
||||
// space for the alarm device's address
|
||||
DeviceAddress alarmAddr;
|
||||
|
||||
Serial.println("Searching for alarms...");
|
||||
|
||||
// resetAlarmSearch() must be called before calling alarmSearch()
|
||||
sensors.resetAlarmSearch();
|
||||
|
||||
// alarmSearch() returns 0 when there are no devices with alarms
|
||||
while (sensors.alarmSearch(alarmAddr))
|
||||
{
|
||||
Serial.print("ALARM: ");
|
||||
printData(alarmAddr);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,144 @@
|
||||
#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 (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
// arrays to hold device addresses
|
||||
DeviceAddress insideThermometer, outsideThermometer;
|
||||
|
||||
// function that will be called when an alarm condition exists during DallasTemperatures::processAlarms();
|
||||
void newAlarmHandler(uint8_t* deviceAddress)
|
||||
{
|
||||
Serial.println("Alarm Handler Start");
|
||||
printAlarmInfo(deviceAddress);
|
||||
printTemp(deviceAddress);
|
||||
Serial.println();
|
||||
Serial.println("Alarm Handler Finish");
|
||||
}
|
||||
|
||||
void printCurrentTemp(DeviceAddress deviceAddress)
|
||||
{
|
||||
printAddress(deviceAddress);
|
||||
printTemp(deviceAddress);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printAddress(DeviceAddress deviceAddress)
|
||||
{
|
||||
Serial.print("Address: ");
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
if (deviceAddress[i] < 16) Serial.print("0");
|
||||
Serial.print(deviceAddress[i], HEX);
|
||||
}
|
||||
Serial.print(" ");
|
||||
}
|
||||
|
||||
void printTemp(DeviceAddress deviceAddress)
|
||||
{
|
||||
float tempC = sensors.getTempC(deviceAddress);
|
||||
if (tempC != DEVICE_DISCONNECTED)
|
||||
{
|
||||
Serial.print("Current Temp C: ");
|
||||
Serial.print(tempC);
|
||||
}
|
||||
else Serial.print("DEVICE DISCONNECTED");
|
||||
Serial.print(" ");
|
||||
}
|
||||
|
||||
void printAlarmInfo(DeviceAddress deviceAddress)
|
||||
{
|
||||
char temp;
|
||||
printAddress(deviceAddress);
|
||||
temp = sensors.getHighAlarmTemp(deviceAddress);
|
||||
Serial.print("High Alarm: ");
|
||||
Serial.print(temp, DEC);
|
||||
Serial.print("C");
|
||||
Serial.print(" Low Alarm: ");
|
||||
temp = sensors.getLowAlarmTemp(deviceAddress);
|
||||
Serial.print(temp, DEC);
|
||||
Serial.print("C");
|
||||
Serial.print(" ");
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
// start serial port
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
||||
|
||||
// Start up the library
|
||||
sensors.begin();
|
||||
|
||||
// locate devices on the bus
|
||||
Serial.print("Found ");
|
||||
Serial.print(sensors.getDeviceCount(), DEC);
|
||||
Serial.println(" devices.");
|
||||
|
||||
// search for devices on the bus and assign based on an index
|
||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
|
||||
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
|
||||
|
||||
Serial.print("Device insideThermometer ");
|
||||
printAlarmInfo(insideThermometer);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Device outsideThermometer ");
|
||||
printAlarmInfo(outsideThermometer);
|
||||
Serial.println();
|
||||
|
||||
// set alarm ranges
|
||||
Serial.println("Setting alarm temps...");
|
||||
sensors.setHighAlarmTemp(insideThermometer, 26);
|
||||
sensors.setLowAlarmTemp(insideThermometer, 22);
|
||||
sensors.setHighAlarmTemp(outsideThermometer, 25);
|
||||
sensors.setLowAlarmTemp(outsideThermometer, 21);
|
||||
|
||||
Serial.print("New insideThermometer ");
|
||||
printAlarmInfo(insideThermometer);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("New outsideThermometer ");
|
||||
printAlarmInfo(outsideThermometer);
|
||||
Serial.println();
|
||||
|
||||
// attach alarm handler
|
||||
sensors.setAlarmHandler(&newAlarmHandler);
|
||||
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// ask the devices to measure the temperature
|
||||
sensors.requestTemperatures();
|
||||
|
||||
// if an alarm condition exists as a result of the most recent
|
||||
// requestTemperatures() request, it exists until the next time
|
||||
// requestTemperatures() is called AND there isn't an alarm condition
|
||||
// on the device
|
||||
if (sensors.hasAlarm())
|
||||
{
|
||||
Serial.println("Oh noes! There is at least one alarm on the bus.");
|
||||
}
|
||||
|
||||
// call alarm handler function defined by sensors.setAlarmHandler
|
||||
// for each device reporting an alarm
|
||||
sensors.processAlarms();
|
||||
|
||||
if (!sensors.hasAlarm())
|
||||
{
|
||||
// just print out the current temperature
|
||||
printCurrentTemp(insideThermometer);
|
||||
printCurrentTemp(outsideThermometer);
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
int oneWirePins[]={3,7};//OneWire DS18x20 temperature sensors on these wires
|
||||
const int oneWirePinsCount=sizeof(oneWirePins)/sizeof(int);
|
||||
|
||||
OneWire ds18x20[oneWirePinsCount];
|
||||
DallasTemperature sensor[oneWirePinsCount];
|
||||
|
||||
|
||||
void setup(void) {
|
||||
// start serial port
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature Multiple Bus Control Library Simple Demo");
|
||||
Serial.print("============Ready with ");
|
||||
Serial.print(oneWirePinsCount);
|
||||
Serial.println(" Sensors================");
|
||||
|
||||
// Start up the library on all defined bus-wires
|
||||
DeviceAddress deviceAddress;
|
||||
for (int i=0; i<oneWirePinsCount; i++) {;
|
||||
ds18x20[i].setPin(oneWirePins[i]);
|
||||
sensor[i].setOneWire(&ds18x20[i]);
|
||||
sensor[i].begin();
|
||||
if (sensor[i].getAddress(deviceAddress, 0)) sensor[i].setResolution(deviceAddress, 12);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
Serial.print("Requesting temperatures...");
|
||||
for (int i=0; i<oneWirePinsCount; i++) {
|
||||
sensor[i].requestTemperatures();
|
||||
}
|
||||
Serial.println("DONE");
|
||||
|
||||
delay(1000);
|
||||
for (int i=0; i<oneWirePinsCount; i++) {
|
||||
float temperature=sensor[i].getTempCByIndex(0);
|
||||
Serial.print("Temperature for the sensor ");
|
||||
Serial.print(i);
|
||||
Serial.print(" is ");
|
||||
Serial.println(temperature);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
144
libraries/DallasTemperature/examples/Multiple/Multiple.pde
Normal file
144
libraries/DallasTemperature/examples/Multiple/Multiple.pde
Normal file
@ -0,0 +1,144 @@
|
||||
// Include the libraries we need
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
// Data wire is plugged into port 2 on the Arduino
|
||||
#define ONE_WIRE_BUS 2
|
||||
#define TEMPERATURE_PRECISION 9
|
||||
|
||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
// arrays to hold device addresses
|
||||
DeviceAddress insideThermometer, outsideThermometer;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
// start serial port
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
||||
|
||||
// Start up the library
|
||||
sensors.begin();
|
||||
|
||||
// locate devices on the bus
|
||||
Serial.print("Locating devices...");
|
||||
Serial.print("Found ");
|
||||
Serial.print(sensors.getDeviceCount(), DEC);
|
||||
Serial.println(" devices.");
|
||||
|
||||
// report parasite power requirements
|
||||
Serial.print("Parasite power is: ");
|
||||
if (sensors.isParasitePowerMode()) Serial.println("ON");
|
||||
else Serial.println("OFF");
|
||||
|
||||
// Assign address manually. The addresses below will beed to be changed
|
||||
// to valid device addresses on your bus. Device address can be retrieved
|
||||
// by using either oneWire.search(deviceAddress) or individually via
|
||||
// sensors.getAddress(deviceAddress, index)
|
||||
//insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
|
||||
//outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
|
||||
|
||||
// Search for devices on the bus and assign based on an index. Ideally,
|
||||
// you would do this to initially discover addresses on the bus and then
|
||||
// use those addresses and manually assign them (see above) once you know
|
||||
// the devices on your bus (and assuming they don't change).
|
||||
//
|
||||
// method 1: by index
|
||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
|
||||
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
|
||||
|
||||
// method 2: search()
|
||||
// search() looks for the next device. Returns 1 if a new address has been
|
||||
// returned. A zero might mean that the bus is shorted, there are no devices,
|
||||
// or you have already retrieved all of them. It might be a good idea to
|
||||
// check the CRC to make sure you didn't get garbage. The order is
|
||||
// deterministic. You will always get the same devices in the same order
|
||||
//
|
||||
// Must be called before search()
|
||||
//oneWire.reset_search();
|
||||
// assigns the first address found to insideThermometer
|
||||
//if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
|
||||
// assigns the seconds address found to outsideThermometer
|
||||
//if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer");
|
||||
|
||||
// show the addresses we found on the bus
|
||||
Serial.print("Device 0 Address: ");
|
||||
printAddress(insideThermometer);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Device 1 Address: ");
|
||||
printAddress(outsideThermometer);
|
||||
Serial.println();
|
||||
|
||||
// set the resolution to 9 bit per device
|
||||
sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
|
||||
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
|
||||
|
||||
Serial.print("Device 0 Resolution: ");
|
||||
Serial.print(sensors.getResolution(insideThermometer), DEC);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Device 1 Resolution: ");
|
||||
Serial.print(sensors.getResolution(outsideThermometer), DEC);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// function to print a device address
|
||||
void printAddress(DeviceAddress deviceAddress)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
// zero pad the address if necessary
|
||||
if (deviceAddress[i] < 16) Serial.print("0");
|
||||
Serial.print(deviceAddress[i], HEX);
|
||||
}
|
||||
}
|
||||
|
||||
// function to print the temperature for a device
|
||||
void printTemperature(DeviceAddress deviceAddress)
|
||||
{
|
||||
float tempC = sensors.getTempC(deviceAddress);
|
||||
Serial.print("Temp C: ");
|
||||
Serial.print(tempC);
|
||||
Serial.print(" Temp F: ");
|
||||
Serial.print(DallasTemperature::toFahrenheit(tempC));
|
||||
}
|
||||
|
||||
// function to print a device's resolution
|
||||
void printResolution(DeviceAddress deviceAddress)
|
||||
{
|
||||
Serial.print("Resolution: ");
|
||||
Serial.print(sensors.getResolution(deviceAddress));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// main function to print information about a device
|
||||
void printData(DeviceAddress deviceAddress)
|
||||
{
|
||||
Serial.print("Device Address: ");
|
||||
printAddress(deviceAddress);
|
||||
Serial.print(" ");
|
||||
printTemperature(deviceAddress);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main function, calls the temperatures in a loop.
|
||||
*/
|
||||
void loop(void)
|
||||
{
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
Serial.print("Requesting temperatures...");
|
||||
sensors.requestTemperatures();
|
||||
Serial.println("DONE");
|
||||
|
||||
// print the device information
|
||||
printData(insideThermometer);
|
||||
printData(outsideThermometer);
|
||||
}
|
||||
|
41
libraries/DallasTemperature/examples/Simple/Simple.pde
Normal file
41
libraries/DallasTemperature/examples/Simple/Simple.pde
Normal file
@ -0,0 +1,41 @@
|
||||
// Include the libraries we need
|
||||
#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 (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
/*
|
||||
* The setup function. We only start the sensors here
|
||||
*/
|
||||
void setup(void)
|
||||
{
|
||||
// start serial port
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
||||
|
||||
// Start up the library
|
||||
sensors.begin();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main function, get and show the temperature
|
||||
*/
|
||||
void loop(void)
|
||||
{
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
Serial.print("Requesting temperatures...");
|
||||
sensors.requestTemperatures(); // Send the command to get temperatures
|
||||
Serial.println("DONE");
|
||||
// After we got the temperatures, we can print them here.
|
||||
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
|
||||
Serial.print("Temperature for the device 1 (index 0) is: ");
|
||||
Serial.println(sensors.getTempCByIndex(0));
|
||||
}
|
116
libraries/DallasTemperature/examples/Single/Single.pde
Normal file
116
libraries/DallasTemperature/examples/Single/Single.pde
Normal file
@ -0,0 +1,116 @@
|
||||
// Include the libraries we need
|
||||
#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 (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
// arrays to hold device address
|
||||
DeviceAddress insideThermometer;
|
||||
|
||||
/*
|
||||
* Setup function. Here we do the basics
|
||||
*/
|
||||
void setup(void)
|
||||
{
|
||||
// start serial port
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
||||
|
||||
// locate devices on the bus
|
||||
Serial.print("Locating devices...");
|
||||
sensors.begin();
|
||||
Serial.print("Found ");
|
||||
Serial.print(sensors.getDeviceCount(), DEC);
|
||||
Serial.println(" devices.");
|
||||
|
||||
// report parasite power requirements
|
||||
Serial.print("Parasite power is: ");
|
||||
if (sensors.isParasitePowerMode()) Serial.println("ON");
|
||||
else Serial.println("OFF");
|
||||
|
||||
// Assign address manually. The addresses below will beed to be changed
|
||||
// to valid device addresses on your bus. Device address can be retrieved
|
||||
// by using either oneWire.search(deviceAddress) or individually via
|
||||
// sensors.getAddress(deviceAddress, index)
|
||||
// Note that you will need to use your specific address here
|
||||
//insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
|
||||
|
||||
// Method 1:
|
||||
// Search for devices on the bus and assign based on an index. Ideally,
|
||||
// you would do this to initially discover addresses on the bus and then
|
||||
// use those addresses and manually assign them (see above) once you know
|
||||
// the devices on your bus (and assuming they don't change).
|
||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
|
||||
|
||||
// method 2: search()
|
||||
// search() looks for the next device. Returns 1 if a new address has been
|
||||
// returned. A zero might mean that the bus is shorted, there are no devices,
|
||||
// or you have already retrieved all of them. It might be a good idea to
|
||||
// check the CRC to make sure you didn't get garbage. The order is
|
||||
// deterministic. You will always get the same devices in the same order
|
||||
//
|
||||
// Must be called before search()
|
||||
//oneWire.reset_search();
|
||||
// assigns the first address found to insideThermometer
|
||||
//if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");
|
||||
|
||||
// show the addresses we found on the bus
|
||||
Serial.print("Device 0 Address: ");
|
||||
printAddress(insideThermometer);
|
||||
Serial.println();
|
||||
|
||||
// set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
|
||||
sensors.setResolution(insideThermometer, 9);
|
||||
|
||||
Serial.print("Device 0 Resolution: ");
|
||||
Serial.print(sensors.getResolution(insideThermometer), DEC);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// function to print the temperature for a device
|
||||
void printTemperature(DeviceAddress deviceAddress)
|
||||
{
|
||||
// method 1 - slower
|
||||
//Serial.print("Temp C: ");
|
||||
//Serial.print(sensors.getTempC(deviceAddress));
|
||||
//Serial.print(" Temp F: ");
|
||||
//Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit
|
||||
|
||||
// method 2 - faster
|
||||
float tempC = sensors.getTempC(deviceAddress);
|
||||
Serial.print("Temp C: ");
|
||||
Serial.print(tempC);
|
||||
Serial.print(" Temp F: ");
|
||||
Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
|
||||
}
|
||||
/*
|
||||
* Main function. It will request the tempC from the sensors and display on Serial.
|
||||
*/
|
||||
void loop(void)
|
||||
{
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
Serial.print("Requesting temperatures...");
|
||||
sensors.requestTemperatures(); // Send the command to get temperatures
|
||||
Serial.println("DONE");
|
||||
|
||||
// It responds almost immediately. Let's print out the data
|
||||
printTemperature(insideThermometer); // Use a simple function to print out the data
|
||||
}
|
||||
|
||||
// function to print a device address
|
||||
void printAddress(DeviceAddress deviceAddress)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
if (deviceAddress[i] < 16) Serial.print("0");
|
||||
Serial.print(deviceAddress[i], HEX);
|
||||
}
|
||||
}
|
124
libraries/DallasTemperature/examples/Tester/Tester.pde
Normal file
124
libraries/DallasTemperature/examples/Tester/Tester.pde
Normal file
@ -0,0 +1,124 @@
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
// Data wire is plugged into port 2 on the Arduino
|
||||
#define ONE_WIRE_BUS 2
|
||||
#define TEMPERATURE_PRECISION 9 // Lower resolution
|
||||
|
||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
int numberOfDevices; // Number of temperature devices found
|
||||
|
||||
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
// start serial port
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
||||
|
||||
// Start up the library
|
||||
sensors.begin();
|
||||
|
||||
// Grab a count of devices on the wire
|
||||
numberOfDevices = sensors.getDeviceCount();
|
||||
|
||||
// locate devices on the bus
|
||||
Serial.print("Locating devices...");
|
||||
|
||||
Serial.print("Found ");
|
||||
Serial.print(numberOfDevices, DEC);
|
||||
Serial.println(" devices.");
|
||||
|
||||
// report parasite power requirements
|
||||
Serial.print("Parasite power is: ");
|
||||
if (sensors.isParasitePowerMode()) Serial.println("ON");
|
||||
else Serial.println("OFF");
|
||||
|
||||
// Loop through each device, print out address
|
||||
for(int i=0;i<numberOfDevices; i++)
|
||||
{
|
||||
// Search the wire for address
|
||||
if(sensors.getAddress(tempDeviceAddress, i))
|
||||
{
|
||||
Serial.print("Found device ");
|
||||
Serial.print(i, DEC);
|
||||
Serial.print(" with address: ");
|
||||
printAddress(tempDeviceAddress);
|
||||
Serial.println();
|
||||
|
||||
Serial.print("Setting resolution to ");
|
||||
Serial.println(TEMPERATURE_PRECISION, DEC);
|
||||
|
||||
// set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
|
||||
sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
|
||||
|
||||
Serial.print("Resolution actually set to: ");
|
||||
Serial.print(sensors.getResolution(tempDeviceAddress), DEC);
|
||||
Serial.println();
|
||||
}else{
|
||||
Serial.print("Found ghost device at ");
|
||||
Serial.print(i, DEC);
|
||||
Serial.print(" but could not detect address. Check power and cabling");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// function to print the temperature for a device
|
||||
void printTemperature(DeviceAddress deviceAddress)
|
||||
{
|
||||
// method 1 - slower
|
||||
//Serial.print("Temp C: ");
|
||||
//Serial.print(sensors.getTempC(deviceAddress));
|
||||
//Serial.print(" Temp F: ");
|
||||
//Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit
|
||||
|
||||
// method 2 - faster
|
||||
float tempC = sensors.getTempC(deviceAddress);
|
||||
Serial.print("Temp C: ");
|
||||
Serial.print(tempC);
|
||||
Serial.print(" Temp F: ");
|
||||
Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
Serial.print("Requesting temperatures...");
|
||||
sensors.requestTemperatures(); // Send the command to get temperatures
|
||||
Serial.println("DONE");
|
||||
|
||||
|
||||
// Loop through each device, print out temperature data
|
||||
for(int i=0;i<numberOfDevices; i++)
|
||||
{
|
||||
// Search the wire for address
|
||||
if(sensors.getAddress(tempDeviceAddress, i))
|
||||
{
|
||||
// Output the device ID
|
||||
Serial.print("Temperature for device: ");
|
||||
Serial.println(i,DEC);
|
||||
|
||||
// It responds almost immediately. Let's print out the data
|
||||
printTemperature(tempDeviceAddress); // Use a simple function to print out the data
|
||||
}
|
||||
//else ghost device! Check your power requirements and cabling
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// function to print a device address
|
||||
void printAddress(DeviceAddress deviceAddress)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
if (deviceAddress[i] < 16) Serial.print("0");
|
||||
Serial.print(deviceAddress[i], HEX);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
//
|
||||
// FILE: TwoPin_DS18B20.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// PURPOSE: two pins for two sensors demo
|
||||
// DATE: 2014-06-13
|
||||
// URL: http://forum.arduino.cc/index.php?topic=216835.msg1764333#msg1764333
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
#define ONE_WIRE_BUS_1 2
|
||||
#define ONE_WIRE_BUS_2 4
|
||||
|
||||
OneWire oneWire_in(ONE_WIRE_BUS_1);
|
||||
OneWire oneWire_out(ONE_WIRE_BUS_2);
|
||||
|
||||
DallasTemperature sensor_inhouse(&oneWire_in);
|
||||
DallasTemperature sensor_outhouse(&oneWire_out);
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature Control Library Demo - TwoPin_DS18B20");
|
||||
|
||||
sensor_inhouse.begin();
|
||||
sensor_outhouse.begin();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
Serial.print("Requesting temperatures...");
|
||||
sensor_inhouse.requestTemperatures();
|
||||
sensor_outhouse.requestTemperatures();
|
||||
Serial.println(" done");
|
||||
|
||||
Serial.print("Inhouse: ");
|
||||
Serial.println(sensor_inhouse.getTempCByIndex(0));
|
||||
|
||||
Serial.print("Outhouse: ");
|
||||
Serial.println(sensor_outhouse.getTempCByIndex(0));
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
#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 (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
// start serial port
|
||||
Serial.begin(115200);
|
||||
Serial.println("Dallas Temperature Control Library - Async Demo");
|
||||
Serial.println("\nDemo shows the difference in length of the call\n\n");
|
||||
|
||||
// Start up the library
|
||||
sensors.begin();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// Request temperature conversion (traditional)
|
||||
Serial.println("Before blocking requestForConversion");
|
||||
unsigned long start = millis();
|
||||
|
||||
sensors.requestTemperatures();
|
||||
|
||||
unsigned long stop = millis();
|
||||
Serial.println("After blocking requestForConversion");
|
||||
Serial.print("Time used: ");
|
||||
Serial.println(stop - start);
|
||||
|
||||
// get temperature
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(sensors.getTempCByIndex(0));
|
||||
Serial.println("\n");
|
||||
|
||||
// Request temperature conversion - non-blocking / async
|
||||
Serial.println("Before NON-blocking/async requestForConversion");
|
||||
start = millis();
|
||||
sensors.setWaitForConversion(false); // makes it async
|
||||
sensors.requestTemperatures();
|
||||
sensors.setWaitForConversion(true);
|
||||
stop = millis();
|
||||
Serial.println("After NON-blocking/async requestForConversion");
|
||||
Serial.print("Time used: ");
|
||||
Serial.println(stop - start);
|
||||
|
||||
|
||||
// 9 bit resolution by default
|
||||
// Note the programmer is responsible for the right delay
|
||||
// we could do something usefull here instead of the delay
|
||||
int resolution = 9;
|
||||
delay(750/ (1 << (12-resolution)));
|
||||
|
||||
// get temperature
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(sensors.getTempCByIndex(0));
|
||||
Serial.println("\n\n\n\n");
|
||||
|
||||
delay(5000);
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
//
|
||||
// Sample of using Async reading of Dallas Temperature Sensors
|
||||
//
|
||||
#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 (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
DeviceAddress tempDeviceAddress;
|
||||
|
||||
int resolution = 12;
|
||||
unsigned long lastTempRequest = 0;
|
||||
int delayInMillis = 0;
|
||||
float temperature = 0.0;
|
||||
int idle = 0;
|
||||
//
|
||||
// SETUP
|
||||
//
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("Dallas Temperature Control Library - Async Demo");
|
||||
Serial.print("Library Version: ");
|
||||
Serial.println(DALLASTEMPLIBVERSION);
|
||||
Serial.println("\n");
|
||||
|
||||
sensors.begin();
|
||||
sensors.getAddress(tempDeviceAddress, 0);
|
||||
sensors.setResolution(tempDeviceAddress, resolution);
|
||||
|
||||
sensors.setWaitForConversion(false);
|
||||
sensors.requestTemperatures();
|
||||
delayInMillis = 750 / (1 << (12 - resolution));
|
||||
lastTempRequest = millis();
|
||||
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
|
||||
if (millis() - lastTempRequest >= delayInMillis) // waited long enough??
|
||||
{
|
||||
digitalWrite(13, LOW);
|
||||
Serial.print(" Temperature: ");
|
||||
temperature = sensors.getTempCByIndex(0);
|
||||
Serial.println(temperature, resolution - 8);
|
||||
Serial.print(" Resolution: ");
|
||||
Serial.println(resolution);
|
||||
Serial.print("Idle counter: ");
|
||||
Serial.println(idle);
|
||||
Serial.println();
|
||||
|
||||
idle = 0;
|
||||
|
||||
// immediately after fetching the temperature we request a new sample
|
||||
// in the async modus
|
||||
// for the demo we let the resolution change to show differences
|
||||
resolution++;
|
||||
if (resolution > 12) resolution = 9;
|
||||
|
||||
sensors.setResolution(tempDeviceAddress, resolution);
|
||||
sensors.requestTemperatures();
|
||||
delayInMillis = 750 / (1 << (12 - resolution));
|
||||
lastTempRequest = millis();
|
||||
}
|
||||
|
||||
digitalWrite(13, HIGH);
|
||||
// we can do usefull things here
|
||||
// for the demo we just count the idle time in millis
|
||||
delay(1);
|
||||
idle++;
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
//
|
||||
// FILE: oneWireSearch.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.02
|
||||
// PURPOSE: scan for 1-Wire devices + code snippet generator
|
||||
// DATE: 2015-june-30
|
||||
// URL: http://forum.arduino.cc/index.php?topic=333923
|
||||
//
|
||||
// inspired by http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// 0.1.00 initial version
|
||||
// 0.1.01 first published version
|
||||
// 0.1.02 small output changes
|
||||
|
||||
#include <OneWire.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("//\n// Start oneWireSearch.ino \n//");
|
||||
|
||||
for (uint8_t pin = 2; pin < 13; pin++)
|
||||
{
|
||||
findDevices(pin);
|
||||
}
|
||||
Serial.println("\n//\n// End oneWireSearch.ino \n//");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t findDevices(int pin)
|
||||
{
|
||||
OneWire ow(pin);
|
||||
|
||||
uint8_t address[8];
|
||||
uint8_t count = 0;
|
||||
|
||||
|
||||
if (ow.search(address))
|
||||
{
|
||||
Serial.print("\nuint8_t pin");
|
||||
Serial.print(pin, DEC);
|
||||
Serial.println("[][8] = {");
|
||||
{
|
||||
count++;
|
||||
Serial.println(" {");
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
Serial.print("0x");
|
||||
if (address[i] < 0x10) Serial.print("0");
|
||||
Serial.print(address[i], HEX);
|
||||
if (i < 7) Serial.print(", ");
|
||||
}
|
||||
Serial.println(" },");
|
||||
} while (ow.search(address));
|
||||
|
||||
Serial.println("};");
|
||||
Serial.print("// nr devices found: ");
|
||||
Serial.println(count);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
//
|
||||
// This sketch does not use the ALARM registers and uses those 2 bytes as a counter
|
||||
// these 2 bytes can be used for other purposes as well e.g. last temperature or
|
||||
// a specific ID.
|
||||
//
|
||||
|
||||
#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 (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
int count = 0;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
// start serial port
|
||||
Serial.begin(9600);
|
||||
Serial.println("Dallas Temperature IC Control Library Demo");
|
||||
|
||||
// Start up the library
|
||||
sensors.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
Serial.print("Requesting temperatures...");
|
||||
sensors.requestTemperatures(); // Send the command to get temperatures
|
||||
Serial.println("DONE");
|
||||
|
||||
Serial.print("Temperature for the device 1 (index 0) is: ");
|
||||
Serial.println(sensors.getTempCByIndex(0));
|
||||
|
||||
count++;
|
||||
sensors.setUserDataByIndex(0, count);
|
||||
int x = sensors.getUserDataByIndex(0);
|
||||
Serial.println(count);
|
||||
}
|
Reference in New Issue
Block a user