MicroPython AS6212 Library

as6212

MicroPython Library for the ASM AS6212 Temperature Sensor

  • Author(s): Jose D. Montoya

class micropython_as6212.as6212.AS6212(i2c, address: int = 0x48)[source]

Driver for the AS6212 Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the AS6212 is connected to.

address : int

The I2C device address. Defaults to 0x48

Quickstart: Importing and using the device

Here is an example of using the AS6212 class. First you will need to import the libraries to use the sensor

from machine import Pin, I2C
from micropython_as6212 import as6212

Once this is done you can define your machine.I2C object and define your sensor object

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
as6 = as6212.AS6212(i2c)

Now you have access to the attributes

temp = as6.temperature
property alert : bool

Sensor alert The alert bit can be used to easily compare the current temperature reading to the thresholds that can be set with the temperature_low_limit and temperature_high_limit.

property conversion_rate : str

Sensor conversion_rate The conversion rate bits define the number of executed temperature conversions per time unit. Additional readouts of the temperature register between conversions are possible but not recommended because the value is changed only after a conversion is finished

Mode

Value

as6212.RATE_0_25

0b00

as6212.RATE_1

0b01

as6212.RATE_4

0b10

as6212.RATE_8

0b11

property interrupt_mode : str

Sensor interrupt_mode The interrupt mode bit defines whether the device operates in the temperature comparator mode or the interrupt mode. This defines the operation of the ALERT output as described in the polarity section bit.

The comparator mode is characterized that if the temperature value exceeds the THIGH value, the alert output is changed (e.g. from high to low if the polarity bit is set to 0 and vice versa). The alert output stays in that condition until the measured temperature drops below the defined TLOW value.

The interrupt mode is characterized that it changes the alert output as soon as the measured temperature crosses the THIGH or TLOW value threshold.

The alert bit has the same setting as the alert output if the device is set to comparator mode.

Mode

Value

as6212.COMPARATOR

0b0

as6212.INTERRUPT

0b1

property operation_mode : str

Sensor operation_mode When the sleep mode is activated, this will shut the device down immediately and reduces the power consumption to a minimum value

Mode

Value

as6212.CONTINUOUS

0b0

as6212.SLEEP

0b1

property temperature : float

Temperature in Celsius

property temperature_high_limit : float

Temperature high limit in Celsius

property temperature_low_limit : float

Temperature low limit in Celsius