API for temperature and/or humidity device drivers
Object filename description:
sensor.type.model.spin
type is one of: temperature
, humidity
, temp_rh
, thermal-array
, thermocouple
model indicates the manufacturer's model number of the sensor
These are methods that are common to all of the above types of drivers
Method | Description | Param | Returns |
---|---|---|---|
startx() |
Start driver using explicitly defined settings | Notes 1-3 | cog id+1 |
stop() |
Stop the driver | n/a | n/a |
defaults() |
Set sensor factory default settings | n/a | n/a |
Notes:
-
For SPI-connected sensors:
startx(CS_PIN, SCK_PIN, MOSI_PIN, MISO_PIN): status
- The preprocessor symbol
MODEL_SPI
must be defined when building, to use. - For some devices, a
MODEL_SPI_BC
variant exists, which directs the driver to use a bytecode-based engine that while much slower, doesn't use another cog. - Replace
MODEL
with the sensor model #. Example:SHT3X_SPI
- For SPI-connected sensors: 4-wire SPI is used by default. If supported by the device,
3-wire SPI can be chosen by setting
MOSI_PIN
andMISO_PIN
to the same I/O pin. Thestartx()
method will check for this and set the device's 3-wire SPI mode register.
-
For I2C-connected sensors:
startx(SCL_PIN, SDA_PIN, I2C_FREQ, ADDR_BITS): status
- If no particular interface preprocessor symbol is defined when building, the driver will default to the PASM-based I2C engine.
- For some devices, a
MODEL_I2C_BC
variant exists, which directs the driver to use a bytecode-based engine that while much slower, doesn't use another cog. - Not all devices support alternate I2C addresses.
-
For OneWire-connected sensors:
startx(OW_PIN): status
-
For all variants:
startx()
returns the launched cog number+1 of com engine used on success. -
For all variants: There may be a
RST_PIN
parameter, for specifying an optional reset pin (device-dependent). The pin is only validated in thereset()
method, and is ignored if set outside the allowable range. -
startx()
returnsFALSE
(0) if the driver fails to start, for these possible reasons:- No more cogs available
- One or more specified I/O pins are outside allowed range
- Bus frequency is outside allowed range
- If supported by the device,
dev_id()
didn't return the expected value
-
defaults()
may simply callreset()
, if sensible, as opposed to calling several other driver methods, in order to reduce memory usage. -
Most (but not all) drivers also provide the following methods:
Method | Description | Param | Returns |
---|---|---|---|
dev_id() |
Read model-unique identification register | n/a | model/dev ID |
reset() |
Perform a hard or soft-reset of the device | n/a | n/a |
-
Drivers may have one or more
Preset_()
methods, that establish a set of pre-set settings. -
stop()
performs the following tasks:- Stop any extra cogs that were started (if applicable)
- Clear all global variable space used to 0
Method | Description |
---|---|
last_temp() |
Previous temperature sensor reading (scaled) |
temp_data() |
Current temperature (ADC word) |
temperature() |
Current temperature (scaled temp) |
temp_scale() |
Set scale of temperature data returned |
temp_word2deg() |
Convert temperature ADC word to degrees |
Previous temperature sensor reading
- Parameters: none
- Returns: temperature in hundredths of a degree in chosen scale (see note 1)
Current temperature sensor reading ADC word
- Parameters: none
- Returns: ADC word representing current temperature sensor reading (see note 2)
Current temperature sensor reading
- Parameters: none
- Returns: temperature in hundredths of a degree in chosen scale (see note 1)
Set scale of temperature data returned
- Parameters:
scale
: new temperature scale (C
(0),F
(1),K
(2)) - Returns: current scale, if
scale
is outside of the rangeC
,F
,K
Convert temperature ADC word to degrees
- Parameters:
temp_wd
: ADC word representing temperature (see note 2)
- Returns: temperature in hundredths of a degree in chosen scale (see note 1)
Notes:
-
Temperature measurements are scaled to hundredths of a degree, in the chosen scale (e.g. 2105 = 21.05 degrees). The scale is chosen using
temp_scale()
with the parameter C (0), F (1), or K (2). If not specified, the default is Celsius (0). -
ADC word size varies from device to device.
Method | Description |
---|---|
last_rh() |
Previous Relative Humidity (scaled RH) |
rh() |
Current relative humidity (scaled RH) |
rh_data() |
Current relative humidity (ADC word) |
rh_word2pct() |
Convert RH ADC word to percent |
Previous relative humidity
- Parameters: none
- Returns: previous relative humidity measurement, in hundredths of a percent
Current relative humidity
- Parameters: none
- Returns: current relative humidity measurement, in hundredths of a percent
Current relative humidity
- Parameters: none
- Returns: ADC word representing current relative humidity measurement
Convert RH ADC word to percent
- Parameters:
rh_wd
: ADC word representing relative humidity
- Returns:
- relative humidity, in hundredths of a percent
Notes:
- Relative humidity measurements are scaled to hundredths of a percent.
Method | Description |
---|---|
get_frame() |
Read frame from sensor |
Read frame from sensor
- Parameters:
ptr_img
: pointer to buffer to copy frame/image to
- Returns: none
NOTE: get_frame()
needs to be pointed to a buffer that is large enough to copy the thermal
image to (varies from device to device).
Method | Description |
---|---|
cj_temp() |
Cold junction temperature (scaled) |
cj_data() |
Cold junction temperature (ADC word) |
tc_data() |
Thermocouple data (ADC word) |
tc_type() |
Set type of thermocouple |
tc_word2temp() |
Convert thermocouple ADC word to degrees |
Cold junction temperature
- Parameters: none
- Returns: temperature in hundredths of a degree in chosen scale
Cold junction temperature ADC word
- Parameters: none
- Returns: ADC word representing cold junction temperature measurement
Thermocouple data ADC word
- Parameters: none
- Returns: ADC word representing thermocouple temperature measurement
Set type of thermocouple
- Parameters:
t
: thermocouple type (symbol such asTYPE_K
, etc; availability depends on driver) - Returns: currently set thermocouple type
Convert thermocouple ADC word to degrees
- Parameters:
tc_word
: ADC word representing thermocouple temperature
- Returns: temperature in hundredths of a degree in chosen scale (see note 1)
Notes:
-
Temperature measurements are scaled to hundredths of a degree, in the chosen scale (e.g. 2105 = 21.05 degrees). The scale is chosen using
temp_scale()
with the parameter C (0), F (1), or K (2). If not specified, the default is Celsius (0). -
ADC word size varies from device to device.
Build the SHT3X demo for P2, native code output, using the I2C engine:
flexspin -2 -L$HOME/p2-spin-standard-library/library -DSHT3X_I2C SHT3x-Demo.spin2
or flexspin -2 -L$HOME/p2-spin-standard-library/library SHT3x-Demo.spin2