Enter Your Electronics & Design Project for a chance to win a $200 shopping cart! Back to homepage |
Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
Introduction.
It was interesting for me to try using a hall sensor to determine the steering angle and try it in the game.
Description AS5600. (Description taken from datasheet.)
The AS5600 is an easy to program magnetic rotary position sensor with a high-resolution 12-bit analog or PWM output. This contactless system measures the absolute angle of a diametric magnetized on-axis magnet. This AS5600 is designed for contactless potentiometer applications and its robust design eliminates the influence of any homogenous external stray magnetic fields. The industry-standard I²C interface supports simple user programming of non-volatile parameters without requiring a dedicated programmer. An easy start and stop position programming in a so called “3 wire mode” without a programmer or digital interface is also implemented. The default range of the output is 0 to 360 degrees. The AS5600 can be applied to smaller range by programming a zero angle (start position) and a maximum angle (stop position). The AS5600 is also equipped with a smart low power mode feature to automatically reduce the power consumption.
This microcircuit contains four Hall sensors arranged in a circle. The internal Hall elements are placed in the center of the package on a circle with a radius of 1 mm.
The typical airgap is between 0.5 mm and 3 mm, and it depends on the selected magnet. A larger and stronger magnet allows a larger airgap. Using the AGC value as a guide, the optimal airgap can be found by adjusting the distance between the magnet and the AS5600 so that the AGC value is in the center of its range. The maximum allowed displacement of the rotational axis of the reference magnet from the center of the package is 0.25 mm when using a magnet with a diameter of 6mm.
The AS5600 allows controlling the direction of the magnet rotation with the DIR pin. If DIR is connected to GND (DIR = 0) a clockwise rotation viewed from the top will generate an increment of the calculated angle. If the DIR pin is connected to VDD (DIR = 1) an increment of the calculated angle will happen with counterclockwise rotation.
Arduino module.
Pin | Description |
---|---|
Vcc |
3.3V |
GND |
Power Ground |
OUT |
PWM /Analog voltage output |
DIR |
Rotational direction (ground=Value increases clockwise; thenVCC =Clockwise values are decreased) |
SCL |
The communication clock line |
SDA |
Data communication line |
GPO |
Mode selection (internal pull ground=Programming mode) |
Connecting to Arduino.
In order for Arduino to be defined as a joystick in Windows, you need to use Arduino Pro Micro or Leonardo.
Connection diagram:
AS5600 Module Pin | Arduino Pro Micro 3v3 Pin |
---|---|
Vcc | Vcc |
GND | GND |
DIR | GND |
SCL | 3 |
SDA | 2 |
The DIR pin must be connected to ground in order for the values to increase clockwise.
For this module, I took a diametrical magnet. The picture below shows how the poles of the magnet are located.
You can identify them by how they are magnetised. They should magnetically sideways to each other.
I also printed a small case and a magnet holder.
Code.
You will need to download two libraries. AS5600.h for working with the module and Joystick.h for Arduino to be defined as a game device (Links will be at the end of the article.)
#include <AS5600.h> #include <Joystick.h> AS5600 encoder; Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_MULTI_AXIS, 4, 0, false, false, false, false, false, false, false, false, true, true, true); int Wheel; void setup() { // Initialize Joystick Library Joystick.begin(); Joystick.setSteeringRange(0, 4059); } void loop() { Wheel = encoder.getPosition(); // Output Controls Joystick.setSteering(Wheel); Joystick.sendState(); }
Running.
After you upload the firmware, the Arduino will be detected as a game device. To check this press the key combination Win + r.
And enter the command joy.cpl.
A menu of game devices will open.
The list will show an Arduino with an OK status.
Click the properties item and you will see the game device check menu. Where you can see the rudder axis movement.
Now you can start the game and try.
Links:
Library for AS5600 module: https://github.com/kanestoboi/AS5600
Joystick Library: https://github.com/MHeironimus/ArduinoJoystickLibrary
3D Model: https://www.thingiverse.com/thing:4656550
Datasheet AS5600: https://ams.com/documents/20143/36005/AS5600_DS000365_5-00.pdf/649ee61c-8f9a-20df-9e10-43173a3eb323
Top Comments