Digital Temperature Sensor Breakout - AS6212 (Qwiic) Hookup Guide

Pages
Contributors: QCPete, El Duderino
Favorited Favorite 0

Qwiic AS6212 Arduino Library

Note: This library assumes the latest version of the Arduino IDE is used. If this is your first time using Arduino, please review our tutorials on Installing the Arduino IDE and Installing an Arduino Library.

The SparkFun AS6212 Arduino Library helps users configure and pull temperature data from the AS6212. Install the library through the Arduino Library Installer by searching for "SparkFun AS6212". Users who prefer to manually install the library can find it on the GitHub Repository or can download a .ZIP of the repo by clicking the button below:

Library Functions

The list below outlines the functions included in the AS6212 Arduino Library along with short descriptions of what they do.

Class

Construct the AS6212 object in the global class. The examples use sensor as the AS6212 breakout object.

  • AS6212 sensor;

Device Setup and Settings

  • bool begin(uint8_t sensorAddress, TwoWire &wirePort); - Initialize the AS6212 Qwiic breakout at a specified address on a selected port. If left empty, default values are used for the address (0x48) and Wire port.
  • bool setDefaultSettings(); - Set the AS6212 CONFIG register to default/factory settings. This helps quickly return the sensor to default settings if anything in the CONFIG register has been changed as adjustments to the CONFIG register remain through power cycles.
  • uint8_t getAddress(); - Returns the device's I2C address.
  • bool getAlertStatus(); - Returns the status of the Alert bit.
  • void setConsecutiveFaults(int faults); - Sets the number of consecutive faults (temperature above THigh) to occur before the Alert pin state adjusts. Acceptable values are 1,2,3 and 4.
  • uint8_t getConsecutiveFaults(); - Returns the value set for setConsecutiveFaults();.
  • void setInterruptMode(bool mode); - Set the AS6212 Alert pin to operate in Interrupt mode.
  • bool getInterruptMode(); - Read whether the Alert pin is set to operate in Interrupt mode.
  • void setConversionCycleTime(uint8_t cycleTime = AS6212_CONVERSION_CYCLE_TIME_250MS); - Sets the time between temperature conversions in milliseconds. Acceptable entries are: 125MS, 250MS, 1000MS or 4000MS.
  • uint16_t getConversionCycleTime(); - Returns the value set for Conversion Cycle Time in milliseconds.
  • void setAlertPolarity(bool polarity); - Set the polarity of the Alert pin output to go either HIGH or LOW when triggered. Default is LOW/0.
  • bool getAlertPolarity(); - Returns the value set for the Alert polarity bit. 0 for active LOW or 1 for active HIGH.
  • void sleepModeOn(); - Put the AS6212 into Sleep Mode. The device must be in Sleep Mode for Single Shot measurements to be made.
  • void sleepModeOff(); - Clears the Sleep Mode bit in the config register and after reseting the SM bit to 0 the device returns to continuous conversion mode.
  • bool getSleepMode(); - Returns the Sleep Mode bit status as a boolean.
  • void triggerSingleShotConversion(); - Tell the AS6212 to perform a Single Shot temperature conversion.
  • bool getSingleShotStatus(); - Returns the Single Shot mode bit status as a boolean. 0 for no conversion ongoing/conversion finished. 1 for start Single Shot conversion/conversion ongoing.
  • void setConfig(uint16_t targetState); - Legacy function for users who wish to interact directly with the CONFIG register. Refer to section 6.2 in the AS6212 Datasheet for a detailed description of this regsiter and the adjustable bits in it.
  • uint16_t readConfig(); - Returns the settings in the CONFIG register as an unsigned integer.

Temperature Data

  • float readTempC(); - Returns the recorded temperature in degrees Celsius.
  • float getTLowC(); - Returns the temperature value set for setTLowC.
  • bool setTLowC(int16_t lowLimit); - Sets the temperature in °C for low temperature threshold. Used for the alert pin temperature limits.
  • float getTHighC(); - Returns the temperature value set for setTHighC.
  • bool setTHighC(int16_t highLimit); - Sets the temperature in °C for the high temperature threshold. Used for the alert pin temperature limits.
  • float readTempF(); - Returns the recorded temperature in degrees Fahrenheit.
  • float getTLowF(); - Returns the temperature value set for setTLowF.
  • bool setTLowF(int16_t lowLimit); - Sets the temperature in °F for low temperature threshold. Used for the alert pin temperature limits.
  • float getTHighF(); - Returns the temperature value set for setTHighF.
  • bool setTHighF(int16_t highLimit); - ets the temperature in °F for high temperature threshold. Used for the alert pin temperature limits.