Remarks

Mcp3208
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet 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

Characteristic Locus
Inheritance object Mcp3xxx > Mcp3208
Implements IAnalogInputController IPinController ISpiPeripheral IDisposable
Inherited Members Mcp3xxx.IsDisposed Mcp3xxx.SpiComms Mcp3xxx.ChannelCount Mcp3xxx.DefaultSpiBusSpeed Mcp3xxx.SpiBusSpeed Mcp3xxx.DefaultSpiBusMode Mcp3xxx.SpiBusMode Mcp3xxx.AdcResolutionInBits Mcp3xxx.CreateAnalogInputPort(IPin, int) Mcp3xxx.CreateAnalogInputPort(IPin, int, TimeSpan, Voltage) Mcp3xxx.CreateAnalogInputPort(IPin, int, TimeSpan, Voltage, Mcp3xxx.InputType) Mcp3xxx.CreateAnalogInputArray(params IPin[]) Mcp3xxx.IsInputTypeSupported(Mcp3xxx.InputType) Mcp3xxx.ValidateChannel(int, int) Mcp3xxx.ValidateChannelPairing(int, int) Mcp3xxx.ReadSingleEnded(int) Mcp3xxx.ReadPseudoDifferential(int, int) Mcp3xxx.ReadDifferential(int, int) Mcp3xxx.ReadInternal(int, Mcp3xxx.InputType, int) Mcp3xxx.ReadInternalRaw(int, int, int) Mcp3xxx.Dispose() Mcp3xxx.Dispose(bool) object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.ICs.IOExpanders
Assembly Mcp3xxx.dll

Syntax

public class Mcp3208 : Mcp3xxx, IAnalogInputController, IPinController, ISpiPeripheral, IDisposable

Constructors

Mcp3208(ISpiBus, IDigitalOutputPort)

Constructs Mcp3208 instance

Declaration
public Mcp3208(ISpiBus spiBus, IDigitalOutputPort chipSelectPort)

Parameters

Type Name Description
ISpiBus spiBus

The SPI bus

IDigitalOutputPort chipSelectPort

Chip select port

Remarks

Mcp3208
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet 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

Properties

Pins

The pins

Declaration
public Mcp3208.PinDefinitions Pins { get; }

Property Value

Type Description
Mcp3208.PinDefinitions

Remarks

Mcp3208
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet 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