# SW01 Module¶

This is a module for the SW01 ambient temperature, humidity and pressure sensor. The board is based off the BME280 manufactured by Bosch. The board uses I2C for communication.

Data Sheets:

## SW01 class¶

class SW01(drvname, addr=0x76, clk=100000)

Creates an intance of the SW01 class.

Parameters: drvname – I2C Bus used ‘( I2C0, ... )’ addr – Slave address, default 0x76 clk – Clock speed, default 100kHz

Sensor’s calibration data are automatically read on object creation and setup method is called with default parameters. Temperature, humidity and pressure values can be easily obtained from the sensor:

from xinabox.sw01 import sw01

...

SW01 = sw01.SW01(I2C0)

temp, hum, pres = bmp.get_values()

setup(mode = 3, os_t = 1, os_h = 1, os_p = 1, t_sb = 6, filter = 1)

This method sets the operating mode and the sampling parameters of the module.

Parameters:

mode: Control the operating mode. Sleep mode is entered by default after power on reset. In sleep mode, no measurement are performed and all registers are accessible. In normal mode the sensor cycles between an active measurement period and an inactive standby period. In forced mode a single measurement is perfomed in accordance to the selected measurement and filter options, after which the sensor enter in sleep mode.

mode Operating mode
0 Sleep Mode
1 or 2 Forced Mode
3 Normal Mode

Note

See pages 12-13 of the datasheet_ for more details on operating mode and allowed sensor mode transitions.

os_t: Oversampling setting for temperature sensor, see os_p for details on allowed values.

os_h: Oversampling setting for humidity sensor, see os_p for details on allowed values.

os_p: Oversampling setting for pressure sensor.

os_p Oversampling setting
0 Skipped (output set to 0)
1 oversampling 1x
2 oversampling 2x
3 oversampling 4x
4 oversampling 8x
5 oversampling 16x

t_sb: Control the inactive duration t_standby in normal mode.

t_sb t_standby [ms]
0 0.5
1 62.5
2 125
3 250
4 500
5 1000
6 10
7 20

filter: Control the time constant of the internal IIR filter. It reduces the bandwidth of the temperature and pressure output signals and increases the resolution of the pressure and temperature output data to 20 bit.

filter Filter coefficient
0 Filter off
1 2
2 4
3 8
4 16
getTempC()

Return the current temperature value in Celsius degree.

getTempF()

Return the current temperature value in Celsius degree.

getHumidity()

Return the current humidity value in %rH.

getPressure()

Return the current pressure value in Pascal.

get_values()

Return a 3-element tuple containing current temperature, humidity and pressure values.

soft_reset()

Reset the device using the complete power-on-reset procedure.

get_status()

Return a two element long tuple representing the status of the sensor. The first element is equal to 1 whenever a conversion is running; it is equal to 0 when the results have been transferred to the data register. The second and last element of the returned tuple is euqal to 1 when the non-volatile memory data (calibration parameters) are being copied to image registers; it is equal to 0 when the copying is done. The data are copied at power-on-reset and before every conversion.

get_chip_id()

Return the device chip id as a single byte integer.