Remarks
Nxp74HC4051 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Nxp74HC4051 mux;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
mux = new Nxp74HC4051(
Device.CreateAnalogInputPort(Device.Pins.A00), // input
Device.CreateDigitalOutputPort(Device.Pins.D00), // s0
Device.CreateDigitalOutputPort(Device.Pins.D01), // s1
Device.CreateDigitalOutputPort(Device.Pins.D02), // s2
Device.CreateDigitalOutputPort(Device.Pins.D03) // enable
);
return base.Initialize();
}
public override Task Run()
{
Task.Run(ReadRoundRobin);
return base.Run();
}
public async Task ReadRoundRobin()
{
while (true)
{
for (var channel = 0; channel < 8; channel++)
{
mux.SetInputChannel(channel);
var read = await mux.Signal.Read();
Resolver.Log.Info($"ADC Channel {channel} = {read.Volts:0.0}V");
await Task.Delay(1000);
}
}
}
Sample project(s) available on GitHub
Wiring Example
To wire a Nxp74HC4051 to your Meadow board, connect the following:
Nxp74HC4051 | Meadow Pin |
---|---|
GND | GND |
VCC | 3V3 |
SCL | D08 (SCL Pin) |
SDA | D07 (SDA Pin) |
Characteristic | Locus |
---|---|
Inheritance | object AnalogMuxBase > Nxp74HC4051 |
Implements | IAnalogInputMultiplexer |
Inherited Members | AnalogMuxBase.SyncRoot AnalogMuxBase.EnablePort AnalogMuxBase.Signal AnalogMuxBase.Enable() AnalogMuxBase.Disable() 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 | AnalogMux.dll |
Syntax
public class Nxp74HC4051 : AnalogMuxBase, IAnalogInputMultiplexer
Constructors
Nxp74HC4051(IAnalogInputPort, IDigitalOutputPort, IDigitalOutputPort?, IDigitalOutputPort?, IDigitalOutputPort?)
Creates a new Nxp74HC4051 object using the default parameters
Declaration
public Nxp74HC4051(IAnalogInputPort z, IDigitalOutputPort s0, IDigitalOutputPort? s1 = null, IDigitalOutputPort? s2 = null, IDigitalOutputPort? enable = null)
Parameters
Type | Name | Description |
---|---|---|
IAnalogInputPort | z | |
IDigitalOutputPort | s0 | |
IDigitalOutputPort | s1 | |
IDigitalOutputPort | s2 | |
IDigitalOutputPort | enable |
Remarks
Nxp74HC4051 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Nxp74HC4051 mux;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
mux = new Nxp74HC4051(
Device.CreateAnalogInputPort(Device.Pins.A00), // input
Device.CreateDigitalOutputPort(Device.Pins.D00), // s0
Device.CreateDigitalOutputPort(Device.Pins.D01), // s1
Device.CreateDigitalOutputPort(Device.Pins.D02), // s2
Device.CreateDigitalOutputPort(Device.Pins.D03) // enable
);
return base.Initialize();
}
public override Task Run()
{
Task.Run(ReadRoundRobin);
return base.Run();
}
public async Task ReadRoundRobin()
{
while (true)
{
for (var channel = 0; channel < 8; channel++)
{
mux.SetInputChannel(channel);
var read = await mux.Signal.Read();
Resolver.Log.Info($"ADC Channel {channel} = {read.Volts:0.0}V");
await Task.Delay(1000);
}
}
}
Sample project(s) available on GitHub
Wiring Example
To wire a Nxp74HC4051 to your Meadow board, connect the following:
Nxp74HC4051 | Meadow Pin |
---|---|
GND | GND |
VCC | 3V3 |
SCL | D08 (SCL Pin) |
SDA | D07 (SDA Pin) |
Properties
S0
The port connected to the mux's S0 selection pin
Declaration
public IDigitalOutputPort S0 { get; }
Property Value
Type | Description |
---|---|
IDigitalOutputPort |
Remarks
Nxp74HC4051 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Nxp74HC4051 mux;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
mux = new Nxp74HC4051(
Device.CreateAnalogInputPort(Device.Pins.A00), // input
Device.CreateDigitalOutputPort(Device.Pins.D00), // s0
Device.CreateDigitalOutputPort(Device.Pins.D01), // s1
Device.CreateDigitalOutputPort(Device.Pins.D02), // s2
Device.CreateDigitalOutputPort(Device.Pins.D03) // enable
);
return base.Initialize();
}
public override Task Run()
{
Task.Run(ReadRoundRobin);
return base.Run();
}
public async Task ReadRoundRobin()
{
while (true)
{
for (var channel = 0; channel < 8; channel++)
{
mux.SetInputChannel(channel);
var read = await mux.Signal.Read();
Resolver.Log.Info($"ADC Channel {channel} = {read.Volts:0.0}V");
await Task.Delay(1000);
}
}
}
Sample project(s) available on GitHub
Wiring Example
To wire a Nxp74HC4051 to your Meadow board, connect the following:
Nxp74HC4051 | Meadow Pin |
---|---|
GND | GND |
VCC | 3V3 |
SCL | D08 (SCL Pin) |
SDA | D07 (SDA Pin) |
S1
The port connected to the mux's S1 selection pin
Declaration
public IDigitalOutputPort? S1 { get; }
Property Value
Type | Description |
---|---|
IDigitalOutputPort |
Remarks
Nxp74HC4051 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Nxp74HC4051 mux;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
mux = new Nxp74HC4051(
Device.CreateAnalogInputPort(Device.Pins.A00), // input
Device.CreateDigitalOutputPort(Device.Pins.D00), // s0
Device.CreateDigitalOutputPort(Device.Pins.D01), // s1
Device.CreateDigitalOutputPort(Device.Pins.D02), // s2
Device.CreateDigitalOutputPort(Device.Pins.D03) // enable
);
return base.Initialize();
}
public override Task Run()
{
Task.Run(ReadRoundRobin);
return base.Run();
}
public async Task ReadRoundRobin()
{
while (true)
{
for (var channel = 0; channel < 8; channel++)
{
mux.SetInputChannel(channel);
var read = await mux.Signal.Read();
Resolver.Log.Info($"ADC Channel {channel} = {read.Volts:0.0}V");
await Task.Delay(1000);
}
}
}
Sample project(s) available on GitHub
Wiring Example
To wire a Nxp74HC4051 to your Meadow board, connect the following:
Nxp74HC4051 | Meadow Pin |
---|---|
GND | GND |
VCC | 3V3 |
SCL | D08 (SCL Pin) |
SDA | D07 (SDA Pin) |
S2
The port connected to the mux's S2 selection pin
Declaration
public IDigitalOutputPort? S2 { get; }
Property Value
Type | Description |
---|---|
IDigitalOutputPort |
Remarks
Nxp74HC4051 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Nxp74HC4051 mux;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
mux = new Nxp74HC4051(
Device.CreateAnalogInputPort(Device.Pins.A00), // input
Device.CreateDigitalOutputPort(Device.Pins.D00), // s0
Device.CreateDigitalOutputPort(Device.Pins.D01), // s1
Device.CreateDigitalOutputPort(Device.Pins.D02), // s2
Device.CreateDigitalOutputPort(Device.Pins.D03) // enable
);
return base.Initialize();
}
public override Task Run()
{
Task.Run(ReadRoundRobin);
return base.Run();
}
public async Task ReadRoundRobin()
{
while (true)
{
for (var channel = 0; channel < 8; channel++)
{
mux.SetInputChannel(channel);
var read = await mux.Signal.Read();
Resolver.Log.Info($"ADC Channel {channel} = {read.Volts:0.0}V");
await Task.Delay(1000);
}
}
}
Sample project(s) available on GitHub
Wiring Example
To wire a Nxp74HC4051 to your Meadow board, connect the following:
Nxp74HC4051 | Meadow Pin |
---|---|
GND | GND |
VCC | 3V3 |
SCL | D08 (SCL Pin) |
SDA | D07 (SDA Pin) |
Methods
SetInputChannel(int)
Sets the channel input (Y pin) that will be routed to the mux output (Z pin)
Declaration
public override void SetInputChannel(int channel)
Parameters
Type | Name | Description |
---|---|---|
int | channel |
Overrides
Remarks
Nxp74HC4051 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Nxp74HC4051 mux;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
mux = new Nxp74HC4051(
Device.CreateAnalogInputPort(Device.Pins.A00), // input
Device.CreateDigitalOutputPort(Device.Pins.D00), // s0
Device.CreateDigitalOutputPort(Device.Pins.D01), // s1
Device.CreateDigitalOutputPort(Device.Pins.D02), // s2
Device.CreateDigitalOutputPort(Device.Pins.D03) // enable
);
return base.Initialize();
}
public override Task Run()
{
Task.Run(ReadRoundRobin);
return base.Run();
}
public async Task ReadRoundRobin()
{
while (true)
{
for (var channel = 0; channel < 8; channel++)
{
mux.SetInputChannel(channel);
var read = await mux.Signal.Read();
Resolver.Log.Info($"ADC Channel {channel} = {read.Volts:0.0}V");
await Task.Delay(1000);
}
}
}
Sample project(s) available on GitHub
Wiring Example
To wire a Nxp74HC4051 to your Meadow board, connect the following:
Nxp74HC4051 | Meadow Pin |
---|---|
GND | GND |
VCC | 3V3 |
SCL | D08 (SCL Pin) |
SDA | D07 (SDA Pin) |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |