Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

ADC Pi .Net Core Library

ADC Pi .Net Core Library code and demos

Created 29/07/2024 | Last Updated: 30/07/2024

.Net Core Library to use with the ADC Pi Raspberry Pi development boards.

Downloading and Installing the .Net Core Libraries

Download the zip archive containing the code demos and libaries from GitHub.

ADC Pi Methods

Connect() 

Open a connection with the ADC Pi.
Parameters: none
Returns: null

IsConnected() 

Shows if there is a connection with the ADC Pi.
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 a byte - 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 a byte - 1 to 8
Returns: raw integer value from ADC buffer

ADC Pi Parameters

byte PGA { get; set; }

Gets or sets the PGA (Programmable Gain Amplifier) gain. Set to 1, 2, 4 or 8
Parameters: gain as byte - 1, 2, 4, 8
Returns: byte - 1, 2, 4 or 8

byte BitRate { get; set; }

Gets or sets the sample resolution bit rate.
12 = 12 bit (240SPS max)
14 = 14 bit (60SPS max)
16 = 16 bit (15SPS max)
18 = 18 bit (3.75SPS max)
Returns: 12, 14, 16, 18

byte ConversionMode { get; set; }

Gets or sets the conversion mode for the ADC.
0 = One shot conversion mode, 1 = Continuous conversion mode
Returns: 0 or 1

ADC Pi Usage

To use the ADC Pi library in your code you must first import the library DLL:

using ABElectronicsUK;

Next, you must initialise the adc class:

ABElectronicsUK.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.BitRate = 18;
adc.PGA = 1;

You can now read the voltage from channel 1 with:

double readvalue = 0;

readvalue = adc.ReadVoltage(1);