Remarks

As5013
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Hid.As5013

Code Example

As5013 joystick;

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

    joystick = new As5013(Device.CreateI2cBus());

    joystick.Updated += As5013_Updated;

    return Task.CompletedTask;
}

public override Task Run()
{
    joystick.StartUpdating(TimeSpan.FromMilliseconds(100));

    return Task.CompletedTask;
}

private void As5013_Updated(object sender, IChangeResult<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition> e)
{
    Resolver.Log.Info($"{e.New.Horizontal}, {e.New.Vertical}");
}

Sample project(s) available on GitHub

Wiring Example

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

As5013 Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3
Characteristic Locus
Inheritance System.Object ObservableBase<AnalogJoystickPosition> SamplingSensorBase<AnalogJoystickPosition> > As5013
Implements ISamplingSensor<AnalogJoystickPosition> IAnalogJoystick
Inherited Members SamplingSensorBase<AnalogJoystickPosition>.samplingLock SamplingSensorBase<AnalogJoystickPosition>.Updated SamplingSensorBase<AnalogJoystickPosition>.SamplingTokenSource SamplingSensorBase<AnalogJoystickPosition>.Conditions SamplingSensorBase<AnalogJoystickPosition>.IsSampling SamplingSensorBase<AnalogJoystickPosition>.UpdateInterval SamplingSensorBase<AnalogJoystickPosition>.RaiseEventsAndNotify(IChangeResult<>) SamplingSensorBase<AnalogJoystickPosition>.Read() ObservableBase<AnalogJoystickPosition>.observers ObservableBase<AnalogJoystickPosition>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<AnalogJoystickPosition>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<AnalogJoystickPosition>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Hid
Assembly As5013.dll

Syntax

public class As5013 : SamplingSensorBase<AnalogJoystickPosition>, ISamplingSensor<AnalogJoystickPosition>, IAnalogJoystick

Constructors

As5013(II2cBus, Byte, IDigitalInterruptPort)

Create a new As5013 object

Declaration
public As5013(II2cBus i2cBus, byte address = null, IDigitalInterruptPort interruptPort = null)

Parameters

Type Name Description
II2cBus i2cBus

the I2C bus

System.Byte address

the device I2C address

IDigitalInterruptPort interruptPort

port connected to the interrupt pin

Properties

DefaultSpeed

Default I2C bus speed

Declaration
public I2cBusSpeed DefaultSpeed { get; }

Property Value

Type Description
I2cBusSpeed

DigitalPosition

The digital joystick position

Declaration
public DigitalJoystickPosition? DigitalPosition { get; }

Property Value

Type Description
System.Nullable<DigitalJoystickPosition>

IsHorizontalInverted

Is the horizontal analog value inverted

Declaration
public bool IsHorizontalInverted { get; set; }

Property Value

Type Description
System.Boolean

IsVerticalHorizonalSwapped

Swap horizonal and vertical

Declaration
public bool IsVerticalHorizonalSwapped { get; set; }

Property Value

Type Description
System.Boolean

IsVerticalInverted

Is the vertical analog value inverted

Declaration
public bool IsVerticalInverted { get; set; }

Property Value

Type Description
System.Boolean

Position

The joystick position

Declaration
public AnalogJoystickPosition? Position { get; }

Property Value

Type Description
System.Nullable<AnalogJoystickPosition>

Methods

DisableInterrupt()

Disable the interrupt pin

Declaration
public void DisableInterrupt()

EnableInterrupt()

enable the interrupt pin

Declaration
public void EnableInterrupt()

InvertSpinning()

Invert the channel voltage function

Declaration
public void InvertSpinning()

ReadSensor()

Convenience method to get the current position

Declaration
protected override Task<AnalogJoystickPosition> ReadSensor()

Returns

Type Description
Task<AnalogJoystickPosition>

Overrides

Meadow.Foundation.SamplingSensorBase<AnalogJoystickPosition>.ReadSensor()

SetDefaultConfiguration()

Set the default configuration

Declaration
public void SetDefaultConfiguration()

SetLowPowerMode(Byte)

Set the device into low power mode

Declaration
public void SetLowPowerMode(byte timing)

Parameters

Type Name Description
System.Byte timing

timing between reads

SetScalingFactor(Byte)

Set the data scaling factor from the hall sensor (see datasheet)

Declaration
public void SetScalingFactor(byte scalingFactor)

Parameters

Type Name Description
System.Byte scalingFactor

SoftReset()

Soft reset the IC

Declaration
public void SoftReset()

StartUpdating(Nullable<TimeSpan>)

Starts continuously sampling the sensor

This method also starts raising Changed events and IObservable subscribers getting notified. Use the readIntervalDuration parameter to specify how often events and notifications are raised/sent.

Declaration
public override void StartUpdating(TimeSpan? updateInterval)

Parameters

Type Name Description
System.Nullable<TimeSpan> updateInterval

A TimeSpan that specifies how long to wait between readings. This value influences how often *Updated events are raised and IObservable consumers are notified.

StopUpdating()

Stops sampling the joystick position

Declaration
public override void StopUpdating()

Overrides

Meadow.Foundation.SamplingSensorBase<AnalogJoystickPosition>.StopUpdating()

Events

Interrupt

Event if interrupt port is provided for interrupt pin

Declaration
public event EventHandler Interrupt

Event Type

Type Description
EventHandler