Skip to main content

Meadow.Foundation.ICs.IOExpanders.Nxp74HC4051

Nxp74HC4051
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.ICs.IOExpanders.AnalogMux

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:

Nxp74HC4051Meadow Pin
GNDGND
VCC3V3
SCLD08 (SCL Pin)
SDAD07 (SDA Pin)