UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

ADC121C021 Class

Module: adc121c021

UPM module for the ADC121C021 12-bit analog-to-digital converter (ADC). By constantly providing a reference voltage, this sensor helps increase the accuracy of a value collected from an analog sensor.
adc121c021.jpg

Methods

ADC121C021

(
  • bus
  • address
  • vref
)
Number

ADC121C021 ADC constructor

Parameters:

  • bus Number

    I2C bus to use

  • address Number

    Address for this sensor; default is 0x55

  • vref Number

    Reference voltage for this sensor; default is 3.0v

Returns:

Number:

writeByte

(
  • reg
  • byte
)
Mraa_result_t

Writes a byte value into the register

Parameters:

  • reg Number

    Register location to write into

  • byte Number

    Byte to write

Returns:

Mraa_result_t:

0 (MRAA_SUCCESS) if successful; non-zero otherwise

writeWord

(
  • reg
  • word
)
Mraa_result_t

Writes a word value into the register

Parameters:

  • reg Number

    Register location to write into

  • word Number

    Word to write

Returns:

Mraa_result_t:

0 (MRAA_SUCCESS) if successful; non-zero otherwise

readByte

(
  • reg
)
Number

Reads the byte value from the register

Parameters:

  • reg Number

    Register location to read from

Returns:

Number:

Value in the specified register

readWord

(
  • reg
)
Number

Reads the word value from the register

Parameters:

  • reg Number

    Register location to read from

Returns:

Number:

Value in the specified register

value

() Number

Reads the current value of conversion

Returns:

Number:

Current value of conversion

valueToVolts

(
  • val
)
Number

Converts a supplied value to voltage based on the set vref

Parameters:

  • val Number

    Value of conversion (from value() )

Returns:

Number:

Value of conversion in volts

getAlertStatus

() Boolean

Reads the current status of the alert flag. If the flag is set, the low or high alert indicators are set as appropriate, and you can access these values with alertLowTriggered() or alertHighTriggered() .

Returns:

Boolean:

True if the alert flag is set

alertLowTriggered

() Boolean

Returns the current value of m_alertLow. You must call getAlertStatus() to update this value.

Returns:

Boolean:

Current status of the alert low flag

alertHighTriggered

() Boolean

Returns the current value of m_alertHigh. You must call getAlertStatus() to update this value.

Returns:

Boolean:

Current status of the alert high flag

clearAlertStatus

()

Clears the alert low and alert high flags. This also clears the last stored alert values.

enableAlertFlag

(
  • enable
)

Enables or disables the alert flag functionality. If enabled, when the measured value exceeds the low or high limits configured, the alert flag is set. Use getAlertStatus() to access these values.

Parameters:

  • enable Boolean

    If true, enables the alert flag; otherwise, disables the alert flag

enableAlertPin

(
  • enable
)

Enables or disables the alert pin functionality.

Parameters:

  • enable Boolean

    If true, enables the alert pin; otherwise, disables the alert pin

enableAlertHold

(
  • enable
)

Enables or disables the alert hold functionality. When the alert hold is enabled, the alert status remains until manually cleared via clearAlertStatus() . Otherwise, the alert self-clears when the value moves into the defined limits if alerts are enabled via enableAlertFlag() .

Parameters:

  • enable Boolean

    If true, enables the alert hold; otherwise, disables the alert hold

enableAlertPinPolarityHigh

(
  • enable
)

If the alert pin is enabled, defines the active polarity of the pin in an alert condition. Enabling this sets the pin to active high in an alert condition; otherwise, active low is used.

Parameters:

  • enable Boolean

    If true, the alert pin is active high; otherwise, active low

setAutomaticConversion

(
  • cycleTime
)

Enables or disables the automatic conversion mode. When enabled, the ADC samples and updates the conversion value independently. It is disabled by default, so conversion is only done by calling value() .

Parameters:

  • cycleTime ADC121C021_CYCLE_TIME_T

    Sets the cycle time for automatic conversion

setAlertLowLimit

(
  • limit
)
Mraa_result_t

Sets the alert low limit. If alerts are enabled and the measured conversion value is lower than the low limit, an alert is triggered.

Parameters:

  • limit Number

    Alert low limit

Returns:

Mraa_result_t:

0 (MRAA_SUCCESS) if successful; non-zero otherwise

setAlertHighLimit

(
  • limit
)
Mraa_result_t

Sets the alert high limit. If alerts are enabled and the measured conversion value is higher than the high limit, an alert is triggered.

Parameters:

  • limit Number

    Alert high limit

Returns:

Mraa_result_t:

0 (MRAA_SUCCESS) if successful; non-zero otherwise

setHysteresis

(
  • limit
)
Mraa_result_t

Sets the hysteresis value. If a high or low alert condition is triggered, the conversion result must move within the high or low limit by more than this value to clear the alert condition. If the alert hold is set, the alert doesn't self-clear regardless of this value.

Parameters:

  • limit Number

    Hysteresis limit

Returns:

Mraa_result_t:

0 (MRAA_SUCCESS) if successful; non-zero otherwise

getHighestConversion

() Number

Returns the highest conversion value recorded so far. This value is only updated by the converter when the automatic conversion mode is enabled.

Returns:

Number:

Highest conversion value

getLowestConversion

() Number

Returns the lowest conversion value recorded so far. This value is only updated by the converter when the automatic conversion mode is enabled.

Returns:

Number:

Lowest conversion value

clearHighestConversion

() Mraa_result_t

Clears the highest conversion value recorded so far.

Returns:

Mraa_result_t:

0 (MRAA_SUCCESS) if successful; non-zero otherwise

clearLowestConversion

() Mraa_result_t

Clears the lowest conversion value recorded so far.

Returns:

Mraa_result_t:

0 (MRAA_SUCCESS) if successful; non-zero otherwise

Properties

ADC121C021_CYCLE_NONE

Enum ADC121C021_CYCLE_TIME_T

ADC121C021_CYCLE_32

Enum ADC121C021_CYCLE_TIME_T

ADC121C021_CYCLE_64

Enum ADC121C021_CYCLE_TIME_T

ADC121C021_CYCLE_128

Enum ADC121C021_CYCLE_TIME_T

ADC121C021_CYCLE_256

Enum ADC121C021_CYCLE_TIME_T

ADC121C021_CYCLE_512

Enum ADC121C021_CYCLE_TIME_T

ADC121C021_CYCLE_1024

Enum ADC121C021_CYCLE_TIME_T

ADC121C021_CYCLE_2048

Enum ADC121C021_CYCLE_TIME_T