// No hay que usar la librería OneWire de Arduino, sino la que tengo en OneWireNoResistor-1.0
// Modifiqué el DS18x20_NoPullupTester_Juan para que simplemente tire datos de los sensores conectados en modo parásito.
// Los datos vienen separados por coma entre los sensores y, al terminar, finaliza la linea y espera X segundos.
#include <OneWire.h>
#include <DallasTemperature.h>
// This is an updated version of the Tester program that comes with the DallasTemp library
// It will drive a DS18x20 tempurature sensor plugged directly to the Arduino header pins 8,9, and 10.
// The flat side of the sensor should face into the center of the board.
// More info and a video here...
// http://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/#more-1892
// Data wire is plugged into port 9 on the Arduino
#define ONE_WIRE_BUS 9
constexpr int delay_ms = 1000;
// 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(9600);
// Establecemos al resolución del sensor con índice 0
sensors.setResolution(9);
}
void loop(void) {
int numberOfDevices; // Number of temperature devices found
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
// For testing purposes, reset the bus every loop so we can see if any devices appear or fall off
sensors.begin();
// Grab a count of devices on the wire
numberOfDevices = sensors.getDeviceCount();
sensors.requestTemperatures(); // Send the command to get temperatures
// 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)) {
float tempC = sensors.getTempC(tempDeviceAddress);
Serial.print(tempC, 4);
Serial.print(",");
}
}
Serial.println("");
delay(delay_ms);
}