ens160.driver

ENS160 I2C driver

class Driver:

ENS160 Sensor class.

Driver(communication: ens160.icommunication.ICommunication)

Constructor for the class which takes an ens160.ICommunication object to provide the communications.

This project provides two retry_i2c.SMBusRetryingI2C and ens160.mock.MockENS160. The first can be used to communicate with a real ENS160 via an I2C link.

The ENS160 can be configured to use I2C addresses 0x52 or 0x53.

PART_ID = 352

The PART_ID as of the ENS160.

def set_operating_mode(self, mode: ens160.op_modes.OpModes):

Sets the ENS160 operation mode. Returns True on success.

Note that get_part_id and get_fw_version will only work in OpModes.IDLE.

def get_operating_mode(self) -> ens160.op_modes.OpModes:

Returns one of the ENS160_OP_MODE values.

def get_part_id(self) -> int:

Gets the part id.

Expecting 0x0160. Note that this only works in OpModes.IDLE.

def clear_gp_read_flag(self):

Clears the General Purpose Read bit of the device status.

def get_fw_version(self) -> str:

Returns a string of firmware version in Major.Minor.Release format.

For example: 5.4.6.

def set_temp_compensation_kelvin(self, t_in_kelvin: float):

Sets the compensation temperature. The sensor will adjust the measurement outputs based on these values.

Note: set temperature and humidity compensation values before reading data, otherwise you get zeros.

def set_temp_compensation_celcius(self, t_in_celcius: float):

Sets the compensation temperature. The sensor will adjust the measurement outputs based on these values.

Note: set temperature and humidity compensation values before reading data, otherwise you get zeros.

def set_temp_compensation_fahrenheit(self, t_in_fahrenheit: float):

Sets the compensation temperature. The sensor will adjust the measurement outputs based on these values.

Note: set temperature and humidity compensation values before reading data, otherwise you get zeros.

def set_rh_compensation(self, relative_humidity: float):

Sets the compensation humidity. The sensor will adjust the measurement outputs based on these values.

Note: set temperature and humidity compensation values before reading data, otherwise you get zeros.

def get_device_status(self) -> ens160.status.Status:

Get the device status.

def get_aqi(self) -> int:

Get the Air Quality index.

Possible value are 1,2,3,4 or 5. With 1 being great and 5 being worst.

def get_tvoc(self) -> int:

Get the Total Volatile Organic compounds in the air in ppb. Lower is better air quality.

def get_eco2(self) -> int:

Get the eCO2 levels in the air in ppm.

Range Unit Quality Description
0 - 600 ppm Excellent Target
600 - 800 ppm Good Average
800 - 1000 ppm Fair Optional Ventilation
1000 - 1500 ppm Poor Contaminated indoor air, ventilation recommend.
1500 + ppm Bad Heavily contaminated indoor air, ventilation required.
def reset(self):

Reset the unit.

Sets the operating mode to OpModes.RESET and then waits for OpModes.DEEP_SLEEP.

def init(self):

Reset and set operating mode to IDLE.