In this video we’re going to be looking at an alternative option to the mechanical rotary encoder I’m using in my Asteroids game controller.

The encoder I’m using is pretty good but the resolution it provides is pretty low. We’ve only got 20 steps which translates to 18 degrees per step.

Fortunately, I’ve been given a magnetic rotary sensor - an AS5048 - I’ve got the SPI version of the AS5048A, but there’s also an I2C version available which is called the AS5048B.

This has a potential resolution of 14bits which translates to 0.0219 degrees. Possibly overkill for our use case… watch the video to see how good the accuracy actually is.

In this video we:

[1:08] Solder up the breakout board of the AS5048. [2:09] Take apart one of my mechanical rotary encoders for parts [4:53] Design and 3D print an enclosure for the new components [5:27] And then assemble our new component and then see how well it works.

I was struggling to think about how I could build the shaft and bearing part of the component and then realised that I had a big bag of rotary encoders that I could try and cannibalise for parts.

When you take one of these apart you can see why it needs a lot of debouncing to get it to work well.

The code I’m using to talk to the AS5048A is in GitHub - I’ve based it on the code from here:

You can find my code here:

There’s a nice video here that delves into some details around rotary encoders -

And here’s the datasheet for the AS5048 chip -

As always, thanks for watching!

There are some audio videos in the pipeline so don’t forget to subscribe and hit the bell!

Patreon: ko-fi: