ADC

This module allows reading analogue data from hardware pins.

The hardware pins can be read from or written to, therefore they are called bidirectional IO pins. This module provides the reading part.

adc.open(configuration, callback)

  • configuration {Object}
    • device {string} Mandatory configuration on Linux.
    • pin {number} Mandatory configuration on NuttX and TizenRT.
  • callback {Function}
    • err: {Error|null}
    • adcpin {Object} An instance of AdcPin.
  • Returns: {Object} An instance of AdcPin.

Opens an ADC pin with the specified configuration asynchronously.

Example

  1. var adc = require('adc');
  2. var adc0 = adc.open({
  3. device: '/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw'
  4. }, function(err) {
  5. if (err) {
  6. throw err;
  7. }
  8. });

adc.openSync(configuration)

  • configuration {Object}
    • device {string} Mandatory configuration on Linux.
    • pin {number} Mandatory configuration on NuttX and TizenRT.
  • callback {Function}
    • err: {Error|null}
  • Returns: {Object} An instance of AdcPin.

Opens an ADC pin with the specified configuration synchronously.

Example

  1. var adc = require('adc');
  2. var adc0 = adc.openSync({
  3. device: '/sys/devices/12d10000.adc/iio:device0/in_voltage0_raw'
  4. });

Class: AdcPin

adcpin.read(callback)

  • callback {Function}
    • err: {Error|null}
    • {number} Analog value.

Reads the analog value from the pin asynchronously.

callback will be called having read the analog value.

Example

  1. adc0.read(function(err, value) {
  2. if (err) {
  3. throw err;
  4. }
  5. console.log('value:', value);
  6. });

adcpin.readSync()

  • Returns: {number} Analog value.

Reads the analog value from the pin synchronously.

Example

  1. var value = adc0.readSync();
  2. console.log('value:', value);

adcpin.close([callback])

  • callback {Function}
    • err: {Error|null}

Closes ADC pin asynchronously. This function must be called after the work of ADC finished.

callback will be called after ADC device is released.

Example

  1. adc0.close(function(err) {
  2. if (err) {
  3. throw err;
  4. }
  5. });

adcpin.closeSync()

Closes ADC pin synchronously. This function must be called after the work of ADC finished.

Example

  1. adc0.closeSync();
  2. console.log('adc pin is closed');