Skip to main content

Analog In

Unlike digital input pins, which only read high or low, analog pins read a range of voltages between 0 V and the chip's reference voltage (3.3 V on Endpoint). Each pin connects internally to an analog-to-digital converter (ADC) that samples the voltage and returns a digital value.

The resolution of the ADC determines the smallest voltage change that registers. A 12-bit ADC has 4096 steps, so one step is roughly 0.8 mV at a 3.3 V reference, and smaller changes are indistinguishable.

Endpoint uses the standard System.Device.Analog API through the AdcController class. Open the pin with a board-level Adc.Pin constant and read voltage or raw samples.

using GHIElectronics.Endpoint.Core;
using GHIElectronics.Endpoint.Devices.Adc;

using var adc = new AdcController();
using var input = adc.OpenPin(EPDomino24.Adc.Pin.PC3); // mikroBUS #1 ADC

while (true) {
Console.WriteLine($"{input.ReadVoltage().Volts:0.000} V (raw {input.ReadRaw()})");
Thread.Sleep(1000);
}

ReadVoltage() returns a UnitsNet.ElectricPotential; ReadRaw() returns the integer sample straight from the ADC. The reference voltage is AdcController.VoltageReference.