use 3rd party lib for ds18b20
This commit is contained in:
parent
9f261ddac7
commit
8bde85723d
3 changed files with 12 additions and 5 deletions
|
@ -18,4 +18,5 @@ project(gbmanager VERSION "1.0.0" LANGUAGES C CXX ASM)
|
||||||
# Initialise the Raspberry Pi Pico SDK
|
# Initialise the Raspberry Pi Pico SDK
|
||||||
pico_sdk_init()
|
pico_sdk_init()
|
||||||
|
|
||||||
|
add_subdirectory(modules/pico-onewire)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
|
@ -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)
|
pico_generate_pio_header(${CMAKE_PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/ds18b20.pio)
|
||||||
|
|
||||||
# Add the standard library to the build
|
# 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
|
# Add any user requested libraries
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "hardware/i2c.h"
|
#include "hardware/i2c.h"
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
#include "../modules/pico-onewire/api/one_wire.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ds18b20.h"
|
#include "ds18b20.h"
|
||||||
|
@ -31,7 +32,10 @@ int main() {
|
||||||
myLCD.clear();
|
myLCD.clear();
|
||||||
|
|
||||||
// Initialize the temp sensor
|
// 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
|
// Initialize the relais
|
||||||
Relais relais(RELAIS_PIN);
|
Relais relais(RELAIS_PIN);
|
||||||
|
@ -51,9 +55,8 @@ int main() {
|
||||||
sleep_ms(3000);
|
sleep_ms(3000);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// ds.convert();
|
int duration = oneWire.convert_temperature(address, true, false);
|
||||||
// temp_act = ds.getTemperature();
|
temp_act = oneWire.temperature(address);
|
||||||
temp_act = 23.5;
|
|
||||||
|
|
||||||
if (isSystemOn && temp_act < temp_tgt - temp_diff) {
|
if (isSystemOn && temp_act < temp_tgt - temp_diff) {
|
||||||
isHeating = true;
|
isHeating = true;
|
||||||
|
@ -75,5 +78,8 @@ int main() {
|
||||||
|
|
||||||
myLCD.setCursor(0, 0);
|
myLCD.setCursor(0, 0);
|
||||||
myLCD.sendString(lcdText.str());
|
myLCD.sendString(lcdText.str());
|
||||||
|
if (duration > 0 && duration <= 1000) {
|
||||||
|
sleep_ms(1000 - duration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue