Skip to content

Commit

Permalink
Merge pull request #13 from Sensirion/add-read-measurement
Browse files Browse the repository at this point in the history
Add read measurement
  • Loading branch information
LeonieFierz authored Feb 3, 2025
2 parents ff925f3 + 6e683ff commit ea788fd
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 12 deletions.
48 changes: 43 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


## [1.0.1] - 2025-2-1

- add convenience method to read out measurements again

## [1.0.0] - 2025-1-30

### Added

- All commands according to data sheet
## [0.1.0] - 2021-2-1


### Changed

Note that there are breaking changes:
- You need to call scd4x_init(SCD41_I2C_ADDR_62); before sending any command t
- all methods that have been named xxxTicks are now named xxxRaw
- getDataReadyFlag has been renamed to getDataReadyStatus
- data type for parameter count in HAL implementation has been changed from uint16_t to uint8_t
- scd4x_set_ambient_pressure takes now a uint32_t in Pa and scd4x_set_ambient_pressure_raw takes a uint16_t in hPa
- scd4x_get_ambient_pressure returns now a uint32_t in Pa and scd4x_get_ambient_pressure_raw returns a uint16_t in hPa
- 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
- signature of scd4x_get_serial_number has changed
- removed read_measurement convenience method - see bugfix 1.0.1 where it is added again


## [0.2.1] - 2021-04-30

### Changed

* Increase timing for single shot from 1350ms to 5000ms
* Increase timing for self test from 5500ms to 10000ms


## [0.2.0] - 2021-03-01

### Added
- Convenience interfaces taking care of unit conversion to and from ticks.

### Fixed
- wake-up interface handles missing ACK from sensor on wake up.


## [0.1.0] - 2021-01-28

Initial release

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

[Unreleased]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/1.0.0...HEAD
[1.0.0]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/0.1.0...1.0.0
[0.1.0]: https://github.com/Sensirion/embedded-i2c-scd4x/releases/tag/0.1.0
[1.0.0]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/0.2.1...1.0.0
[0.2.1]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/0.2.0...0.2.1
[0.2.0]: https://github.com/Sensirion/embedded-i2c-scd4x/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/Sensirion/embedded-i2c-scd4x/releases/tag/0.1.0
14 changes: 7 additions & 7 deletions example-usage/scd4x_i2c_example_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ int main(void) {
//
bool data_ready = false;
uint16_t co2_concentration = 0;
uint16_t temperature = 0;
uint16_t relative_humidity = 0;
int32_t temperature = 0;
int32_t relative_humidity = 0;
uint16_t repetition = 0;
for (repetition = 0; repetition < 50; repetition++) {
//
Expand All @@ -124,17 +124,17 @@ int main(void) {
continue;
}
}
error = scd4x_read_measurement_raw(&co2_concentration, &temperature,
&relative_humidity);
error = scd4x_read_measurement(&co2_concentration, &temperature,
&relative_humidity);
if (error != NO_ERROR) {
printf("error executing read_measurement_raw(): %i\n", error);
printf("error executing read_measurement(): %i\n", error);
continue;
}
//
// Print results in physical units.
printf("CO2 concentration [ppm]: %u\n", co2_concentration);
printf("Temperature ticks: %u\n", temperature);
printf("Humidity ticks: %u\n", relative_humidity);
printf("Temperature [m°C] : %i\n", temperature);
printf("Humidity [mRH]: %i\n", relative_humidity);
}

return NO_ERROR;
Expand Down
14 changes: 14 additions & 0 deletions scd4x_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ int16_t scd4x_read_measurement_raw(uint16_t* co2_concentration,
return local_error;
}

int16_t scd4x_read_measurement(uint16_t* co2, int32_t* temperature_m_deg_c,
int32_t* humidity_m_percent_rh) {
int16_t error;
uint16_t temperature;
uint16_t humidity;
error = scd4x_read_measurement_raw(co2, &temperature, &humidity);
if (error) {
return error;
}
*temperature_m_deg_c = ((21875 * (int32_t)temperature) >> 13) - 45000;
*humidity_m_percent_rh = ((12500 * (int32_t)humidity) >> 13);
return NO_ERROR;
}

int16_t scd4x_stop_periodic_measurement() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
Expand Down
15 changes: 15 additions & 0 deletions scd4x_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ int16_t scd4x_read_measurement_raw(uint16_t* co2_concentration,
uint16_t* temperature,
uint16_t* relative_humidity);

/**
* @brief Read sensor output and convert to pyhsical unit.
*
* See @ref scd4x_read_measurement_raw() for more details.
*
* @param[out] co2 CO₂ concentration in ppm
* @param[out] temperature_m_deg_c Temperature in milli degrees celsius (°C *
* 1000)
* @param[out] humidity_m_percent_rh Relative humidity in milli percent RH
* (%RH * 1000)
* @return 0 on success, an error code otherwise
*/
int16_t scd4x_read_measurement(uint16_t* co2, int32_t* temperature_m_deg_c,
int32_t* humidity_m_percent_rh);

/**
* @brief Stop periodic measurement to change the sensor configuration or to
* save power.
Expand Down

0 comments on commit ea788fd

Please sign in to comment.