Skip to content
Brian Dorey edited this page Jul 1, 2017 · 1 revision

ADCDACPi

This class contains methods for use with the ADC DAC Pi and ADC DAC Pi Zero from https://www.abelectronics.co.uk/p/74/ADC-DAC-Pi-Zero-Raspberry-Pi-ADC-and-DAC-expansion-board

Methods:

ReadADCVoltage(byte channel)

Read the voltage from the selected channel on the ADC
Parameters: channel - 1 or 2
Returns: number as float between 0 and 2.048

ReadADCRaw(byte channel)

Read the raw value from the selected channel on the ADC
Parameters: channel - 1 or 2
Returns: int

SetADCrefVoltage(double voltage) 

Set the reference voltage for the analogue to digital converter.
The ADC uses the raspberry pi 3.3V power as a voltage reference so using this method to set the reference to match the exact output voltage from the 3.3V regulator will increase the accuracy of the ADC readings.
Parameters: voltage - double between 0.0 and 7.0
Returns: null

SetDACVoltage(byte channel, double voltage)

Set the voltage for the selected channel on the DAC
Parameters: channel - 1 or 2, voltage can be between 0 and 2.047 volts
Returns: null

SetDACRaw(byte channel, int value)

Set the raw value from the selected channel on the DAC
Parameters: channel - 1 or 2,value int between 0 and 4095
Returns: null

Usage

To use the ADCDACPi library in your code you must first import the library dll:

using ABElectronics_Win10IOT_Libraries;

Next you must initialise the ADCDACPi class:

ABElectronics_Win10IOT_Libraries.ADCDACPi adcdac = new ABElectronics_Win10IOT_Libraries.ADCDACPi();

Next we need to connect to the device and wait for the connection

adcdac.Connect();

while (!adcdac.IsConnected)
{
}

Set the reference voltage.

adcdac.SetADCrefVoltage(3.3);

Read the voltage from channel 2

double value = adcdac.ReadADCVoltage(2);

Set the DAC voltage on channel 2 to 1.5 volts

adcdac.SetDACVoltage(2, 1.5);

Clone this wiki locally