Buen dia les explico un poquito la mano…
Este codigo lo que hace es escuchar el pin 2 de la arduino, donde yo anteriormente setee que en el “one_wire_bus_PIN2” estan enchufados 2 sensores.
que son estos
DeviceAddress Sensor01 = { 0x28, 0xFF, 0x62, 0x96, 0x74, 0x04, 0x00, 0x78 };
DeviceAddress Sensor02 = { 0x28, 0xFF, 0x23, 0x4C, 0x78, 0x04, 0x00, 0xFD }
-----------------------------------------------------------------------------------------------------------------------Una vez que le aclaré al programa que en el bus pin 2 el sensor01 es xxxxx y el sensor01 es xxxx2. Hace toda una operacion matematica para tirarme los grados centigrados, con un if que si es mayor a 24 ºc me prenda un led situado en el pin 13. si no… que lo apague. (las lecturas son cada 3 segundos)
(este es el codigo)
#include <OneWire.h>
//Get DallasTemperature Library here: http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2
/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);
int led = 13;
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress Sensor01 = { 0x28, 0xFF, 0x62, 0x96, 0x74, 0x04, 0x00, 0x78 };
DeviceAddress Sensor02 = { 0x28, 0xFF, 0x23, 0x4C, 0x78, 0x04, 0x00, 0xFD };
void setup() /****** SETUP: RUNS ONCE ******/
{
pinMode(led, OUTPUT);
// start serial port to show results
Serial.begin(9600);
Serial.print("Cargando Libreria Read Temp SGIT ");
Serial.println(DALLASTEMPLIBVERSION);
// Initialize the Temperature measurement library
sensors.begin();
// set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
sensors.setResolution(Sensor01, 10);
sensors.setResolution(Sensor02, 10);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
delay(3000);
Serial.println();
Serial.print("Numero de sensores en el mismo canal = ");
Serial.println(sensors.getDeviceCount());
Serial.print("Obteniendo Temperaturas... ");
Serial.println();
// Command all devices on bus to read temperature
sensors.requestTemperatures();
Serial.print("Sensor01 Temperatura: ");
printTemperature(Sensor01);
Serial.println();
Serial.print("Sensor02 Temperatura: ");
printTemperature(Sensor02);
Serial.println();
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print("Error al obtener temperatura");
}
if (tempC > 20.00)
{
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.print("ALTA TEMPERATURA");
}
if (tempC < 20.00)
{
digitalWrite(led, LOW);
}
else
{
Serial.print("C: ");
Serial.print(tempC);
}
}
Si entendiste esto, vas a ver que.
Yo en un BUS puedo tener enchufados x cantidad de termometros, si declaro la MACADRESS (por asi decirlo) de cada sensor, entonces aplica el codigo anterior y me tira la temp.
Yo puedo tener un BUS en el pin2 y otro Bus en el pin 3.
por lo que tendria que declarar
“one_wire_bus_PIN2” (x sesores con identificacion x12cx3zaraza)
y luego
“one_wire_bus_PIN3” (x sensores con identificacion x123123xzarazados)
Aplico el codigo de temperatura y me muestra los datos.
Lo que pasa con el codigo anterior es que si se me jode un sensor tengo que al cambiarlo tambien cambiar la macadress del sensor en el codigo, sin embargo con este codigo uno puede hacer que el arduino te escanee el bus que dijiste y te tire las direcciones de todos los sensores enchufados en ese bus…
#include <OneWire.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SENSOR_1_PIN 2 // For BUS 1
#define SENSOR_2_PIN 3 // For BUS 2
/*-----( Declare objects )-----*/
OneWire Bus1(SENSOR_1_PIN); // Create a 1-wire object
OneWire Bus2(SENSOR_2_PIN); // Create another 1-wire object
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
Serial.println("Searching for DS18B20's on two different busses");
Serial.println();
Serial.println("Searching for DS18B20's on BUS ONE");
discoverBusOneWireDevices();
Serial.println();
Serial.println();
Serial.println("Searching for DS18B20's on BUS TWO");
discoverBusTwoWireDevices();
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
// Nothing happening here
}
/*-----( Declare User-written Functions )-----*/
void discoverBusOneWireDevices(void)
{
byte i;
byte present = 0;
byte data[12];
byte addr[8];
Serial.print("Looking for 1-Wire devices...\n\r");// "\n\r" is NewLine
while(Bus1.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\r");
return;
}
}
Serial.println();
Serial.print("Done");
Bus1.reset_search();
return;
}// END
//------------------------------------------------------------
void discoverBusTwoWireDevices(void)
{
byte i;
byte present = 0;
byte data[12];
byte addr[8];
Serial.print("Looking for 1-Wire devices...\n\r");// "\n\r" is NewLine
while(Bus2.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\r");
return;
}
}
Serial.println();
Serial.print("Done");
Bus2.reset_search();
return;
}//END
//*********( THE END )***********
(esto lo que hace es buscar en el pin que le declare todas las mac adrees de los sensores y despues me hace un serial print y me las muestra)
PREGUNTAAA
Yo lo que quiero hacer es usar este codigo y que el resultado del escaneo me lo tire como
BusPIN2
Sensor01 (x32232390i9zaraza)
sensor01 (x394834743)
Entonces luego los asigna automaticamente, con esto lo que yo me evito es tocar el codigo si se rompe un sensor… por que uniendo estos 2 tengo…
El escaner que busca los sensores segun el bus… y luego los declara para que se utilice en el codigo para sacar la temperatura.
Espero que se entienda
Saludos a todos
Necesito orientacion (no pretendo que me escriban el codigo)
saludos nuevamente.