application: add DS18B20 temperature sensor
This commit is contained in:
parent
2976f59622
commit
05ad975fe7
|
@ -33,6 +33,7 @@
|
|||
#include "terminal.h" // handle the terminal interface
|
||||
#include "menu.h" // menu utilities
|
||||
#include "sensor_sr04.h" // range measurement utilities
|
||||
#include "sensor_ds18b20.h" // 1-Wire temperature sensor utilities
|
||||
|
||||
/** watchdog period in ms */
|
||||
#define WATCHDOG_PERIOD 10000
|
||||
|
@ -433,6 +434,17 @@ void main(void)
|
|||
sensor_sr04_setup(); // setup peripheral
|
||||
puts("OK\n");
|
||||
|
||||
puts("setup DS18B20 temperature sensor: ");
|
||||
sensor_ds18b20_setup(); // setup peripheral
|
||||
const bool sensor_ds18b20_present = (1 == sensor_ds18b20_number() && sensor_ds18b20_only()); // ensure there is only one ds18b20 sensor on the bus (so we don't have to use its ROM code)
|
||||
if (sensor_ds18b20_present) {
|
||||
sensor_ds18b20_precision(0, 12); // use highest resolution. it requires 750 ms to do the conversion, but we only check once a second
|
||||
sensor_ds18b20_convert(0); // start the conversion
|
||||
puts("OK\n");
|
||||
} else {
|
||||
puts("KO\n");
|
||||
}
|
||||
|
||||
// setup terminal
|
||||
terminal_prefix = ""; // set default prefix
|
||||
terminal_process = &process_command; // set central function to process commands
|
||||
|
@ -465,6 +477,11 @@ void main(void)
|
|||
action = true; // action will be performed
|
||||
led_toggle(); // toggle LED to indicate if main function is stuck
|
||||
sensor_sr04_trigger(); // start measurement
|
||||
const float heater_temp = sensor_ds18b20_temperature(0); // get temperature
|
||||
if (85.0 != heater_temp) { // the conversion has not been completed
|
||||
sensor_ds18b20_convert(0); // start next conversion
|
||||
printf("heater temperature: %.01f °C\n", heater_temp);
|
||||
}
|
||||
}
|
||||
if (sensor_sr04_distance) { // distance measurement is available
|
||||
printf("%u\n", sensor_sr04_distance); // start measurement
|
||||
|
|
Loading…
Reference in New Issue