I need to write a function that can read 3 sensors (ds18b20) without knowing their address... i.e. we just know what socket (pins) they are to be plugged but I cant rely on the device address since they can be changed...
I tried looking up how the i2c bus assigns the index number so I could just refer to index number but didnt find any info...
anyway, I thought I could turn ON/OFF the power pin of the sensor thus only that sensor will report in to the bus... Dont know if Im screwing up something so thought I would ask.. Maybe a better way thus avoiding the use of so many resources?
Here is how the function will be called out, (all data wires to the same bus)
#define ONE_WIRE_BUS 7
#define vss_sensor_1 8
#define vss_sensor_2 10
#define vss_sensor_3 12
#define vcc_sensor_1 9
#define vcc_sensor_2 11
#define vcc_sensor_3 13
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float temp_1, temp_2, temp_3;
void temp_check() {
digitalWrite(vss_sensor_1, LOW);
digitalWrite(vcc_sensor_1, HIGH);
delay(250); // allow the sensor time to initialize
sensors.begin();
sensors.requestTemperatures();
temp_1 = sensors.getTempCByIndex(0);
digitalWrite(vss_sensor_1, LOW);
digitalWrite(vcc_sensor_1, LOW);
digitalWrite(vss_sensor_2, LOW);
digitalWrite(vcc_sensor_2, HIGH);
delay(250); // allow the sensor time to initialize
sensors.begin();
sensors.requestTemperatures();
temp_2 = sensors.getTempCByIndex(0);
digitalWrite(vss_sensor_2, LOW);
digitalWrite(vcc_sensor_2, LOW);
digitalWrite(vss_sensor_3, LOW);
digitalWrite(vcc_sensor_3, HIGH);
delay(250); // allow the sensor time to initialize
sensors.begin();
sensors.requestTemperatures();
temp_3 = sensors.getTempCByIndex(0);
digitalWrite(vss_sensor_3, LOW);
digitalWrite(vcc_sensor_3, LOW);
}
I havent tested it yet but it compiles...