Skip to content

Releases

2.1.0

Choose a tag to compare

@UncleRus UncleRus released this 13 Nov 00:19
bf408ff

The driver had several problems in the arithmetic around the sensor and in the way the work is serialized. All of them are fixed, and the reset command is available again.

Fixed

The humidity was converted to zero at 100 %

(uint16_t)(humidity / 100.0 * 65536) gave 0 at 100 %RH, so the sensor received the driest possible air when the air was the most humid. The multiplier is 65535 in table 10 of the SGP40 v1.2 and SGP41 v1.0 datasheets (#4).

The values outside the documented range (0..100 % and -45..130 °C) were silently replaced with the closest limit, so a measurement computed from an impossible input looked valid. They are reported as ESP_ERR_INVALID_ARG now (#4).

The commands were built with unaligned 16-bit accesses

The 3-byte Sensirion frames put every other word on an odd address. *(uint16_t *)p broke the alignment requirement and the strict aliasing rules: the Xtensa cores tolerate the access, the RISC-V ones raise an exception (#5).

The gas index was updated outside the device mutex

.eil.yml promises thread_safe: yes, but sgp4x_measure_raw() released the mutex before GasIndexAlgorithm_process() touched the filter state in the descriptor, so two tasks corrupted it (#6).

ESP_FAIL was used for the unsupported operations

A conditioning on the SGP40 and an unknown type in the descriptor reported ESP_FAIL, the same code as a genuinely failed operation. They report ESP_ERR_NOT_SUPPORTED now (#7).

sgp4x_init_desc() accepted an unknown device type

SGP4x_TYPE_SGP40 is 0, so a zero-initialized descriptor silently became an SGP40 (#8).

New

  • sgp4x_soft_reset() is back (#9). It was lost in 2.0.0, although both datasheets document 0x0006 as the way back to the idle mode after an interrupted conditioning or a heater off. The command is sent to the device address, so the other devices on the bus are not reset.

Documentation

The header lists the real return codes of every function — ESP_ERR_INVALID_ARG, ESP_ERR_NOT_SUPPORTED, ESP_ERR_TIMEOUT, ESP_ERR_INVALID_CRC and ESP_FAIL for a failed self-test — and the two constraints: the conditioning must not last longer than 10 seconds, and sgp4x_measure_index() keeps the algorithm state in the descriptor, so the sampling interval has to be constant (#10).

Verification

  • Both examples build on ESP-IDF 6.1 without warnings, astyle --project reports no changes.
  • The byte order and the CRC were checked against table 10 of the datasheets: 0x8000 → 80 00 A2, 0x6666 → 66 66 93, 0x0000 → 00 00 81, 0xFFFF → FF FF AC.
  • The unaligned access was reproduced on the host under -fsanitize=undefined before the fix and is gone after it.
  • 100.0 %RH gives 0xFFFF, -45 °C gives 0x0000, 130 °C gives 0xFFFF.

Full changelog: 2.0.0...2.1.0

Version 2.0.0

Choose a tag to compare

@UncleRus UncleRus released this 12 Nov 23:05
7651307

The component now drives both the SGP40 and the SGP41 through a single API.
The SGP41 is the same sensor with an added NOx channel, and it requires the
conditioning command before the first measurement: sgp4x_start_conditioning()
runs it and returns the raw VOC value for every cycle, so the sensor can be
watched while it warms up. After that, sgp4x_measure_index() returns the VOC
index and, on the SGP41, the NOx index, both computed by Sensirion's Gas Index
Algorithm, which replaces the older VOC algorithm.

The new sgp41 example shows the whole sequence: the humidity and the
temperature are taken from an AHT sensor during the conditioning, the sensor
warms up for ten seconds and the loop then prints both indices with the air
quality verdict. The header of the vendor algorithm is documented on the
component page as well.

Breaking changes

  • sgp40.h is now sgp4x.h, and the prefix of every function, type and
    constant is sgp4x_: sgp40_t became sgp4x_t, SGP40_ADDR became
    SGP4X_ADDR.
  • sgp4x_init_desc() takes the device type, so a single call describes either
    chip: sgp4x_init_desc(&dev, SGP4x_TYPE_SGP40, port, sda, scl).
  • sgp40_measure_raw() became sgp4x_measure_raw(), which fills the raw VOC
    value and, on the SGP41, the raw NOx value.
  • sgp40_measure_voc() became sgp4x_measure_index().
  • sgp40_soft_reset() is gone: the initialization reads the serial number and
    the featureset, and the datasheet's reset command is no longer needed.

Thanks to @botastic for the SGP41 support and for the unified driver.

Full changelog: 1.0.8...2.0.0

Release 1.0.8

Choose a tag to compare

@UncleRus UncleRus released this 11 Nov 06:48
6f4b209

Dropped the explicit target list from .eil.yml and idf_component.yml.
The component now declares support for every target that ESP-IDF provides;
the build matrix takes targets from ESP-IDF itself, so a new chip no longer
requires a change in this repository.

Part of esp-idf-lib/core#69.

Full changelog: 1.0.7...1.0.8

Release 1.0.7

Choose a tag to compare

@trombik trombik released this 31 Jul 12:05

Release 1.0.7

Release 1.0.6

Choose a tag to compare

@trombik trombik released this 31 Jul 07:34

Release 1.0.6

Release 1.0.3

Choose a tag to compare

@trombik trombik released this 26 Jul 02:30

Release 1.0.3

Release 1.0.2

Choose a tag to compare

@trombik trombik released this 26 Jul 01:34

Release 1.0.2

Release 1.0.1

Choose a tag to compare

@trombik trombik released this 26 Jul 00:52

Release 1.0.1

Release 1.0.0

Choose a tag to compare

@trombik trombik released this 25 Jul 09:24

Release 1.0.0