-
Notifications
You must be signed in to change notification settings - Fork 5
Class: ADCPi
This class contains methods for use with the ADC Pi, ADC Pi Plus and ADC Pi Zero from https://www.abelectronics.co.uk/p/56/ADC-Pi-Plus-Raspberry-Pi-Analogue-to-Digital-converter
https://www.abelectronics.co.uk/p/69/ADC-Pi-Zero-Raspberry-Pi-Analogue-to-Digital-converter
Connect()
Connect to the I2C device
Parameters: none
Returns: null
IsConnected()
Check if the device is connected
Parameters: none
Returns: boolean
Dispose()
Dispose of the active I2C device
Parameters: none
Returns: null
ReadVoltage(byte channel)
Read the voltage from the selected channel
Parameters: channel as int - 1 to 8
Returns: number as double between 0 and 5.0
ReadRaw(byte channel)
Read the raw int value from the selected channel
Parameters: channel as int - 1 to 8
Returns: raw integer value from ADC buffer
SetPGA(byte gain)
Set the gain of the PDA on the chip
Parameters: gain as int - 1, 2, 4, 8
Returns: null
SetBitRate(byte rate)
Set the sample bit rate of the adc
Parameters: rate as int - 12, 14, 16, 18
Returns: null
12 = 12 bit (240SPS max)
14 = 14 bit (60SPS max)
16 = 16 bit (15SPS max)
18 = 18 bit (3.75SPS max)
SetConversionMode(bool mode)
Set the conversion mode for the adc
Parameters: mode as boolean - false = One-shot conversion, true = Continuous conversion
Returns: null
To use the ADC Pi library in your code you must first import the library dll:
using ABElectronics_Win10IOT_Libraries;
Next you must initialise the adc class:
ABElectronics_Win10IOT_Libraries.ADCPi adc = new ADCPi(0x68, 0x69);
The arguments are the two I2C addresses of the ADC chips. The values shown are the default addresses of the ADC board.
Next we need to connect to the device and wait for the connection before setting the bit rate and gain. The sample rate can be 12, 14, 16 or 18
adc.Connect();
while (!adc.IsConnected)
{
}
adc.SetBitRate(18);
adc.SetPGA(1);
You can now read the voltage from channel 1 with:
double readvalue = 0;
readvalue = adc.ReadVoltage(1);