-
Notifications
You must be signed in to change notification settings - Fork 1
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/69/adc-pi-raspberry-pi-analogue-to-digital-converter
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 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 byte - 1 to 8
Returns: raw integer value from ADC buffer
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
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);