L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
scd41.h
Go to the documentation of this file.
1/*
2 * hvac.h
3 *
4 * Created on: 29. 12. 2025
5 * Author: Milan
6 *
7 * reading from sensors SCD41
8 *
9 * sensor HVAC Click, SCD41 - CO2, temperature, humidity SCD41Datasheet.pdf
10 * https://www.mikroe.com/hvac-click
11 * https://download.mikroe.com/documents/datasheets/SCD41%20Datasheet.pdf
12 * Sensor is electrically quite demanding, therefore it is necessary to control environment reading via Start/Stop
13 *
14 *
15 * geminy:
16 * https://gemini.google.com/share/a96b452eacf9
17 *
18 *
19 */
20
21#ifndef INC_SCD41_H_
22#define INC_SCD41_H_
23
24#include "mysensors_def.h"
25
26#ifdef SENSOR_SCD41
27
28#include "stm32wlxx_hal.h"
29
30#pragma pack(1)
31/**
32 * @brief Measurement data produced by the SCD41 CO2 / temperature / humidity sensor.
33 * Populated by scd41_Read(); check IsDataValid before using the values.
34 */
35typedef struct
36{
37 float Co2; /**< CO2 concentration in ppm */
38 float Temperature; /**< Temperature in degrees Celsius */
39 float Humidity; /**< Relative humidity in percent (0–100 %) */
40 int8_t IsDataValid; /**< 1 – values are valid; 0 – last read failed or data not yet available */
41} scd41_t;
42#pragma pack()
43
44/** @brief Live measurement data from the SCD41 sensor; updated by scd41_Read(). */
45extern scd41_t _scd41Data;
46/** @brief Snapshot copy of the last completed measurement; used for LoRaWAN transmission. */
48
49/**
50 * @brief - check if CO2 sensor is present
51 * @param tryInit - in case sensor is not yet initialized, 1 - attempt to initialize again, 0 - no
52 * @retval 1 - is present, 0 - is not
53 */
54int8_t scd41_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit);
55
56/**
57 * @brief initialization of sensor sdc41
58 * @retval HAL_OK - sensor is present, HAL_ERROR - error
59 */
60HAL_StatusTypeDef scd41_Init(I2C_HandleTypeDef *hi2c);
61
62/**
63 * @brief start reading - turn on sensor, reading mode can be:
64 * SCD41_CMD_START_PERIODIC - every 5s - this is probably most accurate
65 * SCD41_CMD_START_LOW_POWER_PERIODIC - every 30s
66 */
67HAL_StatusTypeDef scd41_On(I2C_HandleTypeDef *hi2c);
68
69/**
70 * @brief stop reading
71 */
72HAL_StatusTypeDef scd41_Off(I2C_HandleTypeDef *hi2c);
73
74/**
75 * @brief check if data is available
76 * @retval HAL_OK - data is available, can be read, HAL_BUSY - data not yet available, HAL_ERROR - error
77 */
78HAL_StatusTypeDef scd41_IsDataReady(I2C_HandleTypeDef *hi2c);
79
80/**
81 * @brief read value from sensor
82 * @retval HAL_OK - have data, HAL_BUSY - data not yet available, HAL_ERROR - error
83 */
84HAL_StatusTypeDef scd41_Read(I2C_HandleTypeDef *hi2c);
85
86/**
87 * @brief log data to buffer
88 */
89void scd41_LogData(char* buf);
90
91#endif
92
93#endif /* INC_SCD41_H_ */
HAL_StatusTypeDef scd41_IsDataReady(I2C_HandleTypeDef *hi2c)
check if data is available
Definition scd41.c:143
HAL_StatusTypeDef scd41_Off(I2C_HandleTypeDef *hi2c)
stop reading
Definition scd41.c:94
void scd41_LogData(char *buf)
log data to buffer
Definition scd41.c:228
HAL_StatusTypeDef scd41_Init(I2C_HandleTypeDef *hi2c)
initialization of sensor sdc41
Definition scd41.c:99
scd41_t _scd41Data
Live measurement data from the SCD41 sensor; updated by scd41_Read().
Definition scd41.c:39
HAL_StatusTypeDef scd41_Read(I2C_HandleTypeDef *hi2c)
read value from sensor
Definition scd41.c:190
HAL_StatusTypeDef scd41_On(I2C_HandleTypeDef *hi2c)
start reading - turn on sensor, reading mode can be: SCD41_CMD_START_PERIODIC - every 5s - this is pr...
Definition scd41.c:77
int8_t scd41_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if CO2 sensor is present
Definition scd41.c:70
scd41_t _bck_scd41Data
Snapshot copy of the last completed measurement; used for LoRaWAN transmission.
Definition scd41.c:40
Measurement data produced by the SCD41 CO2 / temperature / humidity sensor. Populated by scd41_Read()...
Definition scd41.h:36
float Humidity
Definition scd41.h:39
int8_t IsDataValid
Definition scd41.h:40
float Co2
Definition scd41.h:37
float Temperature
Definition scd41.h:38