Skip to main content

Meadow.Foundation.Sensors.Hid.Mpr121

Mpr121
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Hid.Mpr121

Code Example

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

var sensor = new Mpr121(Device.CreateI2cBus(Meadow.Hardware.I2cBusSpeed.Standard), 90, 100);
sensor.ChannelStatusesChanged += Sensor_ChannelStatusesChanged;

return Task.CompletedTask;
}

private void Sensor_ChannelStatusesChanged(object sender, ChannelStatusChangedEventArgs e)
{
string pads = string.Empty;

for (int i = 0; i < e.ChannelStatus.Count; i++)
{
if (e.ChannelStatus[(Mpr121.Channels)i] == true)
{
pads += i + ", ";
}
}

var msg = string.IsNullOrEmpty(pads) ? "none" : (pads + "touched");
Resolver.Log.Info(msg);
}

Sample project(s) available on GitHub

Wiring Example

To wire a Mpr121 to your Meadow board, connect the following:

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

It should look like the following diagram:

Class Mpr121

Represents the MPR121 12-Key Capacitive Touch Sensor

Assembly: Mpr121.dll
View Source
Declaration
public class Mpr121 : II2cPeripheral

Implements:
Meadow.Hardware.II2cPeripheral

Properties

DefaultI2cAddress

The default I2C address for the peripheral

View Source
Declaration
public byte DefaultI2cAddress { get; }

RefreshPeriod

Gets or sets the period in milliseconds to refresh the channels statuses.

View Source
Declaration
public int RefreshPeriod { get; set; }

Fields

i2cComms

I2C Communication bus used to communicate with the peripheral

View Source
Declaration
protected readonly II2cCommunications i2cComms

Methods

ReadChannelStatus(Channels)

Reads the channel status of MPR121 controller.

View Source
Declaration
public bool ReadChannelStatus(Mpr121.Channels channel)
Returns

System.Boolean

Parameters
TypeNameDescription
Meadow.Foundation.Sensors.Hid.Mpr121.ChannelschannelThe channel to read status.

ReadChannelStatuses()

Reads the channel statuses of MPR121 controller.

View Source
Declaration
public IReadOnlyDictionary<Mpr121.Channels, bool> ReadChannelStatuses()
Returns

System.Collections.Generic.IReadOnlyDictionary<Meadow.Foundation.Sensors.Hid.Mpr121.Channels,System.Boolean>

Events

ChannelStatusesChanged

Notifies about a the channel statuses have been changed. Refresh period can be changed by setting PeriodRefresh property.

View Source
Declaration
public event EventHandler<ChannelStatusChangedEventArgs> ChannelStatusesChanged
Event Type

System.EventHandler<Meadow.Foundation.Sensors.Hid.ChannelStatusChangedEventArgs>

Implements

  • Meadow.Hardware.II2cPeripheral