Sensors¶
Reference¶
Reference for following capitalized words in this page:
SENSOR- sensor name being used (as a prefix to functions), e.g. hdc1080 or adc which then translates to hdc1080_open(..) or adc_read(..)
DEVstruct i2c_device *in case of sensor connected to I2C busstruct spi_device *in case of sensor connected to SPI bus- other device structs depending on bus and so on
MASTERstruct i2c_master *in case of sensor connected to I2C busstruct spi_master *in case of sensor connected to SPI bus- other master structs depending on bus and so on
Generic Functions¶
-
int8_t
SENSOR_open(DEV, MASTER, int32_t ref, int32_t cfg)¶ Parameters: - DEV – See Reference
- MASTER – See Reference
- ref (int32_t) –
Reference information to driver
- I2C: Optional address if device supports more than one, set to zero to use default
- SPI: Slave select pin
- cfg (int32_t) –
Driver specific configuration option
- T&H sensors: Device specific measurement resolution or similar setting
- 0: use default
- -1: skip configuration and use what ever the chip is using currently
Returns: - 0 on success
- -1 if device not found
- -2 on other errors, e.g. configuration failed
ADC¶
Analog to digital converters.
Functions¶
-
int8_t
SENSOR_vref(DEV, float vref)¶ Parameters: - DEV – See Reference
- vref (float) – Reference voltage to use when reading
Returns: - 0 on success
- -1 if device not found
- -2 on other errors
Set reference voltage used by ADC. Default is 1.0 volts.
See
SENSOR_read().
-
int8_t
SENSOR_zero(DEV, float zero)¶ Parameters: - DEV – See Reference
- zero (float) – Zero offset to apply when reading
Returns: 0
Set zero offset. Default is zero which means no effect.
See
SENSOR_read().
-
int8_t
SENSOR_multiplier(DEV, float multiplier)¶ Parameters: - DEV – See Reference
- multiplier (float) – Multiplier to apply when reading
Returns: 0
Default is 1.0.
See
SENSOR_read().
-
int8_t
SENSOR_read(DEV, int32_t *raw, float *value)¶ Parameters: - DEV – See Reference
- *raw (int32_t) –
Save raw reading here if not NULL.
Note that differential ADC readings can be negative.
*rawis a 32 bit signed integer which means that example a 16 bit differential ADC reading is returned between -32768..32767 as a 32 bit signed integer, not 16 bits of raw data saved in 32 bit signed integer. - *value (float) – Save converted value here after applying formula shown in description. Can be NULL.
Returns: - 0 on success
- -1 if device not found
- -2 on other errors
Read ADC value. Formula applied to raw value for converting it to
*value:\((RAW\_VALUE / MAX\_VALUE * vref - zero) * multiplier\)
Temperature and Humidity¶
Temperature and humidity sensors are combined together under same API.
Note
Even sensors that provide only one use the same API.
Functions¶
-
int8_t
SENSOR_heater(DEV, bool on)¶ Parameters: - DEV – See Reference
- on (bool) – Heater on or off
Returns: - 0 on success
- -1 if device not found
- -2 on other errors
- -3 if device has no heater
Enable internal heater if device has such. Usually heater will only apply heat when a measurement is requested so in order to actually heat the device sensor should be read continuously.
-
int8_t
SENSOR_read(DEV, float *t, float *h) Parameters: - DEV – See Reference
- *t (float) –
Save temperature here if not NULL
- Set to -274 if device does not support temperature reading
- Set to -275.0 on other errors, e.g. reading failed
- *h (float) –
Save humidity here if not NULL
- Set to -1 if device does not support humidity reading
- Set to -2 on other errors, e.g. reading failed
Returns: - 0 on success
- -1 if device not found
- -2 on other errors
Read device temperature and humidity values.