HTMAA 2023

Week 9

Input Devices.


Engineering Files

Magnetic Encoders

This week's assignment involved connecting input devices (sensors) to the PCBs we milled in Week 6. Because ultimately I wanted to use an encoder to observe the motion of my tourbillon, I looked into the various options available for measuring the angular position (and possibly velocity) of a rotating shaft. My main options seemed to be potentiometers, optical encoders, and magnetic encoders. I decided to go with magnetic encoders, because the first two introduce their own inertias and friction that I didn't want to deal with. Ideally, the rotating shaft of the tourbillon is as frictionless and smooth as possible, so I wanted to avoid introducing any additional resistances.

I found a magnetic encoder we had in lab, which was the AS5048 from AMS. The way it works is by measuring the direction of a radial magnet as the absolute angle of the magnet. For the future, I want to design a housing so that the main tourbillon shaft sits on a bearing, while the magnetic encoder is mounted on the shaft without introducing any friction.

From Week 6, I designed a breakout board for the Xiao with individual sockets for the different communication protocols. The magnetic encoder communicates with I2C, so I used some jumper cables to connect the pins to the sensor.

Unfortunately, I didn't see any kind of signal from the sensor or the pins, so I disconnected everything, and spent some time probing both the sensor and the PCB pins with a multimeter. I found that my analog and I2C breakouts actually seemed to have a short somewhere...

Fortunately, the sensor also had SPI and PWM communication capabilities, and probing the breakout pins for that communication protocol showed that those connections all still worked.

Next, I tried to write some Arduino code to program the Xiao board. I searched online to find libraries for the magnetic encoder, and someone had written a simple one for Arduino, found here. I had to manually install the library and fiddle a little bit with the pinout settings, but I was able to write a simple script to output the values to the Serial Monitor.

One really convenient aspect of the Arduino IDE is the Serial Plotter tool - if you print values to the terminal in a specific format, the Serial Plotter will automatically plot the values in real time. I used this to plot the angle readings from the magnetic encoder, and plot them live. Finally, with all the code setup, I carefully held the magnet close to the sensor and rotated it, confirming that the angle readings changed as expected.

Any kind of angular deflection from the parallel planes of the sensor and magnet introduced a wild amount of noise to the readings. Even when the magnet was held far away from the sensor, the readings were still very noisy. When I design the housing to hold both the magnet and the sensor, I'm going to have to be careful to align them as closely and precisely as possible.

×

How to Make Almost Anything 2023