use 3rd party lib for ds18b20

This commit is contained in:
Martin Brodbeck 2022-06-01 13:10:01 +02:00
parent 9f261ddac7
commit 8bde85723d
3 changed files with 12 additions and 5 deletions

View file

@ -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)

View file

@ -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}

View file

@ -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);
}
}
}