From 8bde85723dd12a9afd275638e4aefa26c7c863bf Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 1 Jun 2022 13:10:01 +0200 Subject: [PATCH] use 3rd party lib for ds18b20 --- CMakeLists.txt | 1 + src/CMakeLists.txt | 2 +- src/gbmanager.cpp | 14 ++++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a9a760..5fd97de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,4 +18,5 @@ project(gbmanager VERSION "1.0.0" LANGUAGES C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() +add_subdirectory(modules/pico-onewire) add_subdirectory(src) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d807c3f..96a5e1a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,7 @@ pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0) pico_generate_pio_header(${CMAKE_PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/ds18b20.pio) # Add the standard library to the build -target_link_libraries(${CMAKE_PROJECT_NAME} pico_stdlib) +target_link_libraries(${CMAKE_PROJECT_NAME} pico_stdlib pico_one_wire) # Add any user requested libraries target_link_libraries(${CMAKE_PROJECT_NAME} diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index eedbac8..5790264 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -4,6 +4,7 @@ #include "hardware/i2c.h" #include "pico/stdlib.h" +#include "../modules/pico-onewire/api/one_wire.h" #include "config.h" #include "ds18b20.h" @@ -31,7 +32,10 @@ int main() { myLCD.clear(); // Initialize the temp sensor - // DS18B20 ds = DS18B20(pio0, DS18B20_PIN); + One_wire oneWire(DS18B20_PIN); + oneWire.init(); + rom_address_t address{}; + oneWire.single_device_read_rom(address); // Initialize the relais Relais relais(RELAIS_PIN); @@ -51,9 +55,8 @@ int main() { sleep_ms(3000); while (true) { - // ds.convert(); - // temp_act = ds.getTemperature(); - temp_act = 23.5; + int duration = oneWire.convert_temperature(address, true, false); + temp_act = oneWire.temperature(address); if (isSystemOn && temp_act < temp_tgt - temp_diff) { isHeating = true; @@ -75,5 +78,8 @@ int main() { myLCD.setCursor(0, 0); myLCD.sendString(lcdText.str()); + if (duration > 0 && duration <= 1000) { + sleep_ms(1000 - duration); + } } } \ No newline at end of file