Commit e4c4f82a authored by Erik Strand's avatar Erik Strand

Only print the data

parent ad547ed8
......@@ -167,24 +167,36 @@ void loop(void) {
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
float celsius;
const unsigned n_nodes = 5;
static float measurements[n_nodes]; // so we can store each temp reading before printing
if (!ds.search(addr)) {
put_line(&serial_port, serial_pin_out, "No more addresses.");
ds.reset_search();
PORTB |= led_pin;
delay(250);
//put_line(&serial_port, serial_pin_out, "No more addresses.");
for (unsigned i = 0; i < n_nodes; ++i) {
put_float(&serial_port, serial_pin_out, measurements[i]);
put_string(&serial_port, serial_pin_out, ", ");
}
put_char(&serial_port, serial_pin_out, '\n');
ds.reset_search();
for (unsigned i = 0; i < n_nodes; ++i) {
measurements[i] = 0;
}
delay(200);
PORTB &= ~led_pin;
return;
}
//Serial.print("ROM =");
/*
put_string(&serial_port, serial_pin_out, "ROM=");
for (i = 0; i < 8; i++) {
put_char(&serial_port, serial_pin_out, ' ');
put_hex(&serial_port, serial_pin_out, addr[i]);
}
put_char(&serial_port, serial_pin_out, '\n');
*/
if (OneWire::crc8(addr, 7) != addr[7]) {
put_line(&serial_port, serial_pin_out, "CRC is not valid!");
......@@ -194,20 +206,20 @@ void loop(void) {
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
put_line(&serial_port, serial_pin_out, " Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
//put_line(&serial_port, serial_pin_out, " Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
put_line(&serial_port, serial_pin_out, " Chip = DS18B20");
type_s = 0;
break;
//put_line(&serial_port, serial_pin_out, " Chip = DS18B20");
type_s = 0;
break;
case 0x22:
put_line(&serial_port, serial_pin_out, " Chip = DS1822");
type_s = 0;
break;
//put_line(&serial_port, serial_pin_out, " Chip = DS1822");
type_s = 0;
break;
default:
put_line(&serial_port, serial_pin_out, "Device is not a DS18x20 family device.");
return;
put_line(&serial_port, serial_pin_out, "Device is not a DS18x20 family device.");
return;
}
ds.reset();
......@@ -221,15 +233,15 @@ void loop(void) {
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
put_string(&serial_port, serial_pin_out, " Data = ");
put_hex(&serial_port, serial_pin_out, present);
put_char(&serial_port, serial_pin_out, ' ');
//put_string(&serial_port, serial_pin_out, " Data = ");
//put_hex(&serial_port, serial_pin_out, present);
//put_char(&serial_port, serial_pin_out, ' ');
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
put_hex(&serial_port, serial_pin_out, data[i]);
//put_hex(&serial_port, serial_pin_out, data[i]);
}
put_string(&serial_port, serial_pin_out, " CRC=");
put_hex(&serial_port, serial_pin_out, OneWire::crc8(data, 8));
//put_string(&serial_port, serial_pin_out, " CRC=");
//put_hex(&serial_port, serial_pin_out, OneWire::crc9(data, 8));
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
......@@ -251,10 +263,32 @@ void loop(void) {
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
//fahrenheit = celsius * 1.8 + 32.0;
switch (addr[1]) {
case 0x06:
measurements[0] = celsius;
break;
case 0x18:
measurements[1] = celsius;
break;
case 0x78:
measurements[2] = celsius;
break;
case 0x71:
measurements[3] = celsius;
break;
case 0x70:
measurements[4] = celsius;
break;
default:
put_line(&serial_port, serial_pin_out, "Error: unrecognized temperature node");
}
/*
put_string(&serial_port, serial_pin_out, " Temperature = ");
put_float(&serial_port, serial_pin_out, celsius);
put_string(&serial_port, serial_pin_out, " Celsius, ");
put_float(&serial_port, serial_pin_out, fahrenheit);
put_line(&serial_port, serial_pin_out, " Fahrenheit");
*/
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment