Skip to main content

Class Mcp3xxx

Provide an interface to connect to a MCP3xxx analog to digital converter (ADC)

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

Derived:
Meadow.Foundation.ICs.IOExpanders.Mcp3001, Meadow.Foundation.ICs.IOExpanders.Mcp3002, Meadow.Foundation.ICs.IOExpanders.Mcp3004, Meadow.Foundation.ICs.IOExpanders.Mcp3008, Meadow.Foundation.ICs.IOExpanders.Mcp3201, Meadow.Foundation.ICs.IOExpanders.Mcp3202, Meadow.Foundation.ICs.IOExpanders.Mcp3204, Meadow.Foundation.ICs.IOExpanders.Mcp3208

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

Properties

IsDisposed

Is the object disposed

View Source
public bool IsDisposed { get; }

SpiComms

Gets the underlying ISpiCommunications instance

View Source
protected ISpiCommunications SpiComms { get; }

ChannelCount

the number of input channels on the ADC

View Source
protected int ChannelCount { get; set; }

DefaultSpiBusSpeed

The default SPI bus speed for the device

View Source
public Frequency DefaultSpiBusSpeed { get; }

SpiBusSpeed

The SPI bus speed for the device

View Source
public Frequency SpiBusSpeed { get; set; }

DefaultSpiBusMode

The default SPI bus mode for the device

View Source
public SpiClockConfiguration.Mode DefaultSpiBusMode { get; }

SpiBusMode

The SPI bus mode for the device

View Source
public SpiClockConfiguration.Mode SpiBusMode { get; set; }

AdcResolutionInBits

The resolution of the analog-to-digital converter in the Mcp3xxx This is model-specific and not configurable

View Source
public int AdcResolutionInBits { get; protected set; }

Methods

CreateAnalogInputPort(IPin, int)

Create an analog input port for a pin

View Source
protected IAnalogInputPort CreateAnalogInputPort(IPin pin, int sampleCount = 64)
Returns

Meadow.Hardware.IAnalogInputPort: An instance of Meadow.Hardware.IAnalogInputPort that represents the analog input on the specified pin

Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe pin to use for the analog input port
System.Int32sampleCountThe number of samples to take when measuring the pin's voltage

CreateAnalogInputPort(IPin, int, TimeSpan, Voltage)

Creates a new instance of an IAnalogInputPort for the specified pin

View Source
public IAnalogInputPort CreateAnalogInputPort(IPin pin, int sampleCount, TimeSpan sampleInterval, Voltage voltageReference)
Returns

Meadow.Hardware.IAnalogInputPort: A new instance of an IAnalogInputPort

Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe IPin object that this port is created from
System.Int32sampleCountThe number of samples to take
System.TimeSpansampleIntervalThe interval delay between samples
Meadow.Units.VoltagevoltageReferenceThe Voltage reference for ADC readings

CreateAnalogInputPort(IPin, int, TimeSpan, Voltage, InputType)

Creates a new instance of an IAnalogInputPort for the specified pin

View Source
public IAnalogInputPort CreateAnalogInputPort(IPin pin, int sampleCount, TimeSpan sampleInterval, Voltage voltageReference, Mcp3xxx.InputType inputType)
Returns

Meadow.Hardware.IAnalogInputPort: A new instance of an IAnalogInputPort

Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe IPin object that this port is created from
System.Int32sampleCountThe number of samples to take
System.TimeSpansampleIntervalThe interval delay between samples
Meadow.Units.VoltagevoltageReferenceThe Voltage reference for ADC readings
Meadow.Foundation.ICs.IOExpanders.Mcp3xxx.InputTypeinputTypeThe pin channel input type

CreateAnalogInputArray(params IPin[])

Creates an IAnalogInputArray instance from the specified set of pins

View Source
public IAnalogInputArray CreateAnalogInputArray(params IPin[] pins)
Returns

Meadow.Hardware.IAnalogInputArray

Parameters
TypeNameDescription
Meadow.Hardware.IPin[]pinsThe pins to use for the IAnalogInputArray

IsInputTypeSupported(InputType)

Is the input type supported on this MCP3xxx version

View Source
public virtual bool IsInputTypeSupported(Mcp3xxx.InputType inputType)
Returns

System.Boolean: True if supported, false if not supported

Parameters
TypeNameDescription
Meadow.Foundation.ICs.IOExpanders.Mcp3xxx.InputTypeinputTypeThe input type

ValidateChannel(int, int)

Checks if channel is in range

View Source
protected void ValidateChannel(int channel, int channelCount)
Parameters
TypeNameDescription
System.Int32channelThe channel
System.Int32channelCountThe number of channels on the device

ValidateChannelPairing(int, int)

Checks if the channel is in range of the available input channels and that both channels are part of a valid pairing

View Source
protected void ValidateChannelPairing(int valueChannel, int referenceChannel)
Parameters
TypeNameDescription
System.Int32valueChannelThe 1st (value) channel in the pairing
System.Int32referenceChannelThe 2nd (reference) channel in the pairing

ReadSingleEnded(int)

Reads a value from the device for a single ended input

View Source
protected virtual int ReadSingleEnded(int channel)
Returns

System.Int32: The raw voltage

Parameters
TypeNameDescription
System.Int32channelChannel which represents the input signal

ReadPseudoDifferential(int, int)

Reads a value from the device using pseudo-differential inputs

View Source
protected virtual int ReadPseudoDifferential(int valueChannel, int referenceChannel)
Returns

System.Int32: The raw relative voltage

Parameters
TypeNameDescription
System.Int32valueChannelChannel which represents the signal
System.Int32referenceChannelChannel which represents ground

ReadDifferential(int, int)

Reads a value from the device using differential inputs

View Source
protected virtual int ReadDifferential(int valueChannel, int referenceChannel)
Returns

System.Int32: The raw relative voltage

Parameters
TypeNameDescription
System.Int32valueChannelChannel which represents the positive signal
System.Int32referenceChannelChannel which represents the negative signal

ReadInternal(int, InputType, int)

Reads a value from the device

View Source
protected virtual int ReadInternal(int channel, Mcp3xxx.InputType inputType, int adcResolutionBits)
Returns

System.Int32: A value corresponding to relative voltage level on specified device channel

Parameters
TypeNameDescription
System.Int32channelChannel to read - for differential inputs this represents a channel pair (valid values: 0 - channelcount - 1 or 0 - channelcount / 2 - 1 with differential inputs)
Meadow.Foundation.ICs.IOExpanders.Mcp3xxx.InputTypeinputTypeThe type of input channel to read
System.Int32adcResolutionBitsThe number of bits in the returned value

ReadInternalRaw(int, int, int)

Reads a value from the device

View Source
protected int ReadInternalRaw(int adcRequest, int adcResolutionInBits, int delayBits)
Returns

System.Int32: A value corresponding to a voltage level on the input pin described by the request

Parameters
TypeNameDescription
System.Int32adcRequestA bit pattern to be sent to the ADC
System.Int32adcResolutionInBitsThe number of bits in the returned value
System.Int32delayBitsThe number of bits to be delayed between the request and the response being read

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source
public void Dispose()

Dispose(bool)

Dispose of the object

View Source
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs disposing

Implements

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