Skip to main content

Meadow.Foundation.Sensors.Hid.As5013

As5013
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet 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:

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

Class As5013

Represents an AS5013 Hall navigation sensor for analog joysticks

Assembly: As5013.dll
View Source
Declaration
public class As5013 : SamplingSensorBase<AnalogJoystickPosition>, IObservable<IChangeResult<AnalogJoystickPosition>>, ISamplingSensor<AnalogJoystickPosition>, ISensor<AnalogJoystickPosition>, ISensor, ISamplingSensor, IAnalogJoystick, II2cPeripheral

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>>, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>, Meadow.Peripherals.Sensors.ISensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Peripherals.Sensors.Hid.IAnalogJoystick, Meadow.Hardware.II2cPeripheral

Properties

DefaultSpeed

Default I2C bus speed

View Source
Declaration
public I2cBusSpeed DefaultSpeed { get; }

IsHorizontalInverted

Is the horizontal analog value inverted

View Source
Declaration
public bool IsHorizontalInverted { get; set; }

IsVerticalInverted

Is the vertical analog value inverted

View Source
Declaration
public bool IsVerticalInverted { get; set; }

IsVerticalHorizonalSwapped

Swap horizontal and vertical

View Source
Declaration
public bool IsVerticalHorizonalSwapped { get; set; }

Position

The joystick position

View Source
Declaration
public AnalogJoystickPosition? Position { get; }

DigitalPosition

The digital joystick position

View Source
Declaration
public DigitalJoystickPosition? DigitalPosition { get; }

DefaultI2cAddress

The default I2C address for the peripheral

View Source
Declaration
public byte DefaultI2cAddress { get; }

Fields

i2cComms

I2C Communication bus used to communicate with the peripheral

View Source
Declaration
protected readonly II2cCommunications i2cComms

Methods

ReadSensor()

Convenience method to get the current position

View Source
Declaration
protected override Task<AnalogJoystickPosition> ReadSensor()
Returns

System.Threading.Tasks.Task<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>

StartUpdating(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.

View Source
Declaration
public override void StartUpdating(TimeSpan? updateInterval)
Parameters
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalA 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

View Source
Declaration
public override void StopUpdating()

SetLowPowerMode(byte)

Set the device into low power mode

View Source
Declaration
public void SetLowPowerMode(byte timing)
Parameters
TypeNameDescription
System.Bytetimingtiming between reads

SetScalingFactor(byte)

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

View Source
Declaration
public void SetScalingFactor(byte scalingFactor)
Parameters
TypeName
System.BytescalingFactor

InvertSpinning()

Invert the channel voltage function

View Source
Declaration
public void InvertSpinning()

SoftReset()

Soft reset the IC

View Source
Declaration
public void SoftReset()

DisableInterrupt()

Disable the interrupt pin

View Source
Declaration
public void DisableInterrupt()

EnableInterrupt()

enable the interrupt pin

View Source
Declaration
public void EnableInterrupt()

SetDefaultConfiguration()

Set the default configuration

View Source
Declaration
public void SetDefaultConfiguration()

Events

Interrupt

Event if interrupt port is provided for interrupt pin

View Source
Declaration
public event EventHandler Interrupt
Event Type

System.EventHandler

Implements

  • System.IObservable<Meadow.IChangeResult<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Peripherals.Sensors.Hid.AnalogJoystickPosition>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Peripherals.Sensors.Hid.IAnalogJoystick
  • Meadow.Hardware.II2cPeripheral