Skip to main content

Meadow.Foundation.ICs.IOExpanders.Mcp3208

Mcp3208
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.ICs.ADCs.Mcp3xxx

Code Example

Mcp3208 mcp;

IAnalogInputPort port;

public override Task Initialize()
{
Resolver.Log.Info("Initialize");

IDigitalOutputPort chipSelectPort = Device.CreateDigitalOutputPort(Device.Pins.D01);

mcp = new Mcp3208(Device.CreateSpiBus(), chipSelectPort);

port = mcp.CreateAnalogInputPort(mcp.Pins.CH0, 32, TimeSpan.FromSeconds(1), new Voltage(3.3, Voltage.UnitType.Volts), Mcp3xxx.InputType.SingleEnded);

port.Updated += (s, result) =>
{
Resolver.Log.Info($"Analog event, new voltage: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
};

var observer = IAnalogInputPort.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Analog observer triggered; new: {result.New.Volts:n2}V, old: {result.Old?.Volts:n2}V");
},
filter: result =>
{
if (result.Old is { } oldValue)
{
return (result.New - oldValue).Abs().Volts > 0.1;
}
else { return false; }
}
);
port.Subscribe(observer);

return base.Initialize();
}

public override Task Run()
{
Resolver.Log.Info("Run");

port.StartUpdating();

return Task.CompletedTask;
}

Sample project(s) available on GitHub

Class Mcp3208

MCP3008 Analog to Digital Converter (ADC)

Assembly: Mcp3xxx.dll
View Source
Declaration
public class Mcp3208 : Mcp3xxx, IAnalogInputController, IPinController, ISpiPeripheral, IDisposable

Inheritance: System.Object -> Meadow.Foundation.ICs.IOExpanders.Mcp3xxx

Implements:
Meadow.Hardware.IAnalogInputController, Meadow.Hardware.IPinController, Meadow.Hardware.ISpiPeripheral, System.IDisposable

Properties

Pins

The pins

View Source
Declaration
public Mcp3208.PinDefinitions Pins { get; }

Implements

  • Meadow.Hardware.IAnalogInputController
  • Meadow.Hardware.IPinController
  • Meadow.Hardware.ISpiPeripheral
  • System.IDisposable