... it's sht30 not scd30

This commit is contained in:
Artemis Tosini 2022-10-05 00:45:40 +00:00
parent a3b29e47c7
commit f43defd194
Signed by: artemist
GPG key ID: EE5227935FE3FF18
3 changed files with 23 additions and 23 deletions

View file

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

View file

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

View file

@ -4,7 +4,7 @@
#include "hardware/i2c.h" #include "hardware/i2c.h"
#include "pico/stdlib.h" #include "pico/stdlib.h"
struct scd30_result { struct sht30_result {
float temp_c; float temp_c;
float relative_humidity; 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]]; return crc8_table[lsb ^ crc8_table[msb ^ 0xff]];
} }
static void scd30_reset_all() { static void sht30_reset_all() {
// Generall call recet // Generall call recet
uint8_t cmd[] = {0x06}; uint8_t cmd[] = {0x06};
i2c_write_blocking(i2c, 0x00, cmd, sizeof(cmd), false); i2c_write_blocking(i2c, 0x00, cmd, sizeof(cmd), false);
@ -45,7 +45,7 @@ static void scd30_reset_all() {
sleep_ms(2); sleep_ms(2);
} }
static uint16_t scd30_get_firmware_version() { static uint16_t sht30_get_firmware_version() {
uint8_t cmd[] = {0xd1, 0x00}; uint8_t cmd[] = {0xd1, 0x00};
i2c_write_blocking(i2c, addr, cmd, sizeof(cmd), true); i2c_write_blocking(i2c, addr, cmd, sizeof(cmd), true);
uint8_t resp[3]; uint8_t resp[3];
@ -55,13 +55,13 @@ static uint16_t scd30_get_firmware_version() {
return (uint16_t)resp[0] << 8 | resp[1]; return (uint16_t)resp[0] << 8 | resp[1];
} }
static void scd30_start_capture() { static void sht30_start_capture() {
// High repeatability, 1 sample per second // High repeatability, 1 sample per second
uint8_t cmd[] = {0x21, 0x30}; uint8_t cmd[] = {0x21, 0x30};
i2c_write_blocking(i2c, addr, cmd, sizeof(cmd), false); 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}; uint8_t cmd[] = {0xe0, 0x00};
i2c_write_blocking(i2c, addr, cmd, sizeof(cmd), true); i2c_write_blocking(i2c, addr, cmd, sizeof(cmd), true);
uint8_t resp[6]; uint8_t resp[6];
@ -78,7 +78,7 @@ static struct scd30_result scd30_fetch_data() {
else else
relative_humidity = NAN; relative_humidity = NAN;
struct scd30_result result = {.temp_c = temp_c, struct sht30_result result = {.temp_c = temp_c,
.relative_humidity = relative_humidity}; .relative_humidity = relative_humidity};
return result; return result;
} }
@ -94,13 +94,13 @@ int main() {
sleep_ms(2000); sleep_ms(2000);
scd30_reset_all(); sht30_reset_all();
scd30_start_capture(); sht30_start_capture();
while (true) { while (true) {
sleep_ms(1000); 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, printf("{\"temperature\": %f, \"humidity\": %f}\n", result.temp_c,
result.relative_humidity); result.relative_humidity);
} }