Skip to content

Commit ea788fd

Browse files
authored
Merge pull request #13 from Sensirion/add-read-measurement
Add read measurement
2 parents ff925f3 + 6e683ff commit ea788fd

File tree

4 files changed

+79
-12
lines changed

4 files changed

+79
-12
lines changed

CHANGELOG.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
9+
## [1.0.1] - 2025-2-1
10+
11+
- add convenience method to read out measurements again
12+
813
## [1.0.0] - 2025-1-30
914

1015
### Added
1116

1217
- All commands according to data sheet
13-
## [0.1.0] - 2021-2-1
18+
19+
20+
### Changed
21+
22+
Note that there are breaking changes:
23+
- You need to call scd4x_init(SCD41_I2C_ADDR_62); before sending any command t
24+
- all methods that have been named xxxTicks are now named xxxRaw
25+
- getDataReadyFlag has been renamed to getDataReadyStatus
26+
- data type for parameter count in HAL implementation has been changed from uint16_t to uint8_t
27+
- scd4x_set_ambient_pressure takes now a uint32_t in Pa and scd4x_set_ambient_pressure_raw takes a uint16_t in hPa
28+
- scd4x_get_ambient_pressure returns now a uint32_t in Pa and scd4x_get_ambient_pressure_raw returns a uint16_t in hPa
29+
- scd4x_get_automatic_self_calibration/scd4x_set_automatic_self_calibration has been renamed to scd4x_get_automatic_self_calibration_enabled/scd4x_set_automatic_self_calibration_enabled
30+
- signature of scd4x_get_serial_number has changed
31+
- removed read_measurement convenience method - see bugfix 1.0.1 where it is added again
32+
33+
34+
## [0.2.1] - 2021-04-30
35+
36+
### Changed
37+
38+
* Increase timing for single shot from 1350ms to 5000ms
39+
* Increase timing for self test from 5500ms to 10000ms
40+
41+
42+
## [0.2.0] - 2021-03-01
1443

1544
### Added
45+
- Convenience interfaces taking care of unit conversion to and from ticks.
46+
47+
### Fixed
48+
- wake-up interface handles missing ACK from sensor on wake up.
49+
50+
51+
## [0.1.0] - 2021-01-28
52+
53+
Initial release
1654

17-
- Initial version
18-
- Check latest 0.x.x version for changelog prior to version 1.0.0
1955

2056
[Unreleased]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/1.0.0...HEAD
21-
[1.0.0]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/0.1.0...1.0.0
22-
[0.1.0]: https://github.com/Sensirion/embedded-i2c-scd4x/releases/tag/0.1.0
57+
[1.0.0]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/0.2.1...1.0.0
58+
[0.2.1]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/0.2.0...0.2.1
59+
[0.2.0]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/0.1.0...0.2.0
60+
[0.1.0]: https://github.com/Sensirion/embedded-i2c-scd4x/releases/tag/0.1.0

example-usage/scd4x_i2c_example_usage.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ int main(void) {
9999
//
100100
bool data_ready = false;
101101
uint16_t co2_concentration = 0;
102-
uint16_t temperature = 0;
103-
uint16_t relative_humidity = 0;
102+
int32_t temperature = 0;
103+
int32_t relative_humidity = 0;
104104
uint16_t repetition = 0;
105105
for (repetition = 0; repetition < 50; repetition++) {
106106
//
@@ -124,17 +124,17 @@ int main(void) {
124124
continue;
125125
}
126126
}
127-
error = scd4x_read_measurement_raw(&co2_concentration, &temperature,
128-
&relative_humidity);
127+
error = scd4x_read_measurement(&co2_concentration, &temperature,
128+
&relative_humidity);
129129
if (error != NO_ERROR) {
130-
printf("error executing read_measurement_raw(): %i\n", error);
130+
printf("error executing read_measurement(): %i\n", error);
131131
continue;
132132
}
133133
//
134134
// Print results in physical units.
135135
printf("CO2 concentration [ppm]: %u\n", co2_concentration);
136-
printf("Temperature ticks: %u\n", temperature);
137-
printf("Humidity ticks: %u\n", relative_humidity);
136+
printf("Temperature [m°C] : %i\n", temperature);
137+
printf("Humidity [mRH]: %i\n", relative_humidity);
138138
}
139139

140140
return NO_ERROR;

scd4x_i2c.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ int16_t scd4x_read_measurement_raw(uint16_t* co2_concentration,
159159
return local_error;
160160
}
161161

162+
int16_t scd4x_read_measurement(uint16_t* co2, int32_t* temperature_m_deg_c,
163+
int32_t* humidity_m_percent_rh) {
164+
int16_t error;
165+
uint16_t temperature;
166+
uint16_t humidity;
167+
error = scd4x_read_measurement_raw(co2, &temperature, &humidity);
168+
if (error) {
169+
return error;
170+
}
171+
*temperature_m_deg_c = ((21875 * (int32_t)temperature) >> 13) - 45000;
172+
*humidity_m_percent_rh = ((12500 * (int32_t)humidity) >> 13);
173+
return NO_ERROR;
174+
}
175+
162176
int16_t scd4x_stop_periodic_measurement() {
163177
int16_t local_error = NO_ERROR;
164178
uint8_t* buffer_ptr = communication_buffer;

scd4x_i2c.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ int16_t scd4x_read_measurement_raw(uint16_t* co2_concentration,
195195
uint16_t* temperature,
196196
uint16_t* relative_humidity);
197197

198+
/**
199+
* @brief Read sensor output and convert to pyhsical unit.
200+
*
201+
* See @ref scd4x_read_measurement_raw() for more details.
202+
*
203+
* @param[out] co2 CO₂ concentration in ppm
204+
* @param[out] temperature_m_deg_c Temperature in milli degrees celsius (°C *
205+
* 1000)
206+
* @param[out] humidity_m_percent_rh Relative humidity in milli percent RH
207+
* (%RH * 1000)
208+
* @return 0 on success, an error code otherwise
209+
*/
210+
int16_t scd4x_read_measurement(uint16_t* co2, int32_t* temperature_m_deg_c,
211+
int32_t* humidity_m_percent_rh);
212+
198213
/**
199214
* @brief Stop periodic measurement to change the sensor configuration or to
200215
* save power.

0 commit comments

Comments
 (0)