From f43defd1945d051acd758cc2991419ab7ba543c7 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Wed, 5 Oct 2022 00:45:40 +0000 Subject: [PATCH] ... it's sht30 not scd30 --- rp2040/scd30/CMakeLists.txt | 14 -------------- rp2040/sht30/CMakeLists.txt | 14 ++++++++++++++ rp2040/{scd30/scd30.c => sht30/sht30.c} | 18 +++++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 rp2040/scd30/CMakeLists.txt create mode 100644 rp2040/sht30/CMakeLists.txt rename rp2040/{scd30/scd30.c => sht30/sht30.c} (90%) diff --git a/rp2040/scd30/CMakeLists.txt b/rp2040/scd30/CMakeLists.txt deleted file mode 100644 index 487d9ed..0000000 --- a/rp2040/scd30/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake) -set(CMAKE_C_STANDARD 11) - -project(scd30) -pico_sdk_init() - -add_executable(scd30 - scd30.c - ) -target_link_libraries(scd30 pico_stdlib hardware_i2c) -pico_enable_stdio_usb(scd30 1) -pico_add_extra_outputs(scd30) diff --git a/rp2040/sht30/CMakeLists.txt b/rp2040/sht30/CMakeLists.txt new file mode 100644 index 0000000..06aac35 --- /dev/null +++ b/rp2040/sht30/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.12) + +include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake) +set(CMAKE_C_STANDARD 11) + +project(sht30) +pico_sdk_init() + +add_executable(sht30 + sht30.c + ) +target_link_libraries(sht30 pico_stdlib hardware_i2c) +pico_enable_stdio_usb(sht30 1) +pico_add_extra_outputs(sht30) diff --git a/rp2040/scd30/scd30.c b/rp2040/sht30/sht30.c similarity index 90% rename from rp2040/scd30/scd30.c rename to rp2040/sht30/sht30.c index 731b92a..101f8fe 100644 --- a/rp2040/scd30/scd30.c +++ b/rp2040/sht30/sht30.c @@ -4,7 +4,7 @@ #include "hardware/i2c.h" #include "pico/stdlib.h" -struct scd30_result { +struct sht30_result { float temp_c; float relative_humidity; }; @@ -37,7 +37,7 @@ static uint8_t crc8(uint8_t msb, uint8_t lsb) { return crc8_table[lsb ^ crc8_table[msb ^ 0xff]]; } -static void scd30_reset_all() { +static void sht30_reset_all() { // Generall call recet uint8_t cmd[] = {0x06}; i2c_write_blocking(i2c, 0x00, cmd, sizeof(cmd), false); @@ -45,7 +45,7 @@ static void scd30_reset_all() { sleep_ms(2); } -static uint16_t scd30_get_firmware_version() { +static uint16_t sht30_get_firmware_version() { uint8_t cmd[] = {0xd1, 0x00}; i2c_write_blocking(i2c, addr, cmd, sizeof(cmd), true); uint8_t resp[3]; @@ -55,13 +55,13 @@ static uint16_t scd30_get_firmware_version() { return (uint16_t)resp[0] << 8 | resp[1]; } -static void scd30_start_capture() { +static void sht30_start_capture() { // High repeatability, 1 sample per second uint8_t cmd[] = {0x21, 0x30}; i2c_write_blocking(i2c, addr, cmd, sizeof(cmd), false); }; -static struct scd30_result scd30_fetch_data() { +static struct sht30_result sht30_fetch_data() { uint8_t cmd[] = {0xe0, 0x00}; i2c_write_blocking(i2c, addr, cmd, sizeof(cmd), true); uint8_t resp[6]; @@ -78,7 +78,7 @@ static struct scd30_result scd30_fetch_data() { else relative_humidity = NAN; - struct scd30_result result = {.temp_c = temp_c, + struct sht30_result result = {.temp_c = temp_c, .relative_humidity = relative_humidity}; return result; } @@ -94,13 +94,13 @@ int main() { sleep_ms(2000); - scd30_reset_all(); + sht30_reset_all(); - scd30_start_capture(); + sht30_start_capture(); while (true) { sleep_ms(1000); - struct scd30_result result = scd30_fetch_data(); + struct sht30_result result = sht30_fetch_data(); printf("{\"temperature\": %f, \"humidity\": %f}\n", result.temp_c, result.relative_humidity); }