private static async Task Main(string[] args) { Console.WriteLine("Hello Mcp3428 Sample!"); var options = new I2cConnectionSettings(1, Mcp3428.I2CAddressFromPins(PinState.Low, PinState.Low)); using (var dev = I2cDevice.Create(options)) { using (var adc = new Mcp3428(dev, AdcMode.OneShot, resolution: AdcResolution.Bit16, pgaGain: AdcGain.X1)) { var watch = new Stopwatch(); watch.Start(); while (true) { for (int i = 0; i < 4; i++) { var last = watch.ElapsedMilliseconds; var value = adc.ReadChannel(i); foreach (var b in adc.LastBytes.ToArray()) { Console.Write($"{b:X} "); } Console.WriteLine(); Console.WriteLine($"ADC Channel[{adc.LastChannel + 1}] read in {watch.ElapsedMilliseconds - last} ms, value: {value} V"); await Task.Delay(500); } Console.WriteLine($"mode {adc.Mode}, gain {adc.InputGain}, res {adc.Resolution}"); await Task.Delay(1000); } } } }
public void Dispose() { if (!disposed) { return; } sensor.Dispose(); sensor = null; disposed = true; }
public AdcExpansionBoard(int I2CId = Pinout.I2cBus.I2C2, ushort i2cAddress = 0x68) { // Adress Options 0x68, 0x6A, 0x6C or 0x6E I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(I2CId, i2cAddress)); sensor = new Mcp3428(i2cDevice, AdcMode.OneShot, AdcResolution.Bit16, AdcGain.X1); PT100TemperatureCoefficient = 1.250f; //not sure why this is better... 0c correct 30c 0.5c off... //PT100TemperatureCoefficient = 0.385f;// 0.00385 Ohms/Ohm/ºC //Default Vishay NTCALUG01A103F specs //B25/85-value 3435 to 4190 K NTC_A = 0.0011415995549162692f; NTC_B = 0.000232134233116422f; NTC_C = 9.520031026040015e-8f; }