I recently purchased some magnetic encoders to use in an upcoming project and hooked them up to a Wemos D1 Mini to try and do some basic testing. The specific magnetic encoder is the AS5048. Three wires were soldered to the PWM output pins only as this is a lot easier than soldering wires to the very slim SPI tabs. As long as the PWM output works as expected then there will be no need for using the SPI interface.
To read the PWM output I uploaded a simple PWM read sketch to the Wemos and took a look at the output on a serial monitor. It was then that the output was seen to be not as expected.
The expected output was a series of numbers ranging from 0 to some other higher number as the magnet was rotated above the IC. However, the numbers seemed random and only seemed to match the expected output when the magnet was revolved around an axis that was on the edge of the magnet and not the centre. It was then that I realised that I was using the wrong kind of magnet. The standard neodymium magnets that you can buy for attaching things to your fridge etc. are magnetised with their poles on the opposite faces. Magnetic encoders are designed to work with diametrically magnetised magnets, i.e. those that have the north and south poles on the opposite edges of the magnet with a split down the middle of the face.
So some magnets were purchased from Amazon that were clearly marked as diametrically magnetised and even had in the description:
” Each magnet’s north and south pole are on opposite curved sides.
Unusually, diametrically magnetised magnets are not designed to hold the maximum possible weight for the size of the magnet but instead are used to provide rotational movement.
A diametrically magnetised magnet is magnetised across its diameter so that the north pole in on one curved side and the south pole is on the opposite curved side.
Diametrically magnetised magnets are used on the end of shafts to provide drive. “
Despite this, when the magnets arrived and were tested the output was exactly the same as a standard magnet. It was obvious to me that these were not diametrically magnetised at all. So I purchased a very small square of magnetic field view paper (really cool stuff). When it arrived I put a standard magnet and what was supposed to be the diametrically magnetised magnet under the paper. The result was this:
The standard magnet is on the left and the ‘diametrically magnetised’ magnet is on the right. As you can see clearly, they are identical. So I initiated a return and refund on Amazon immediately and reported the seller for selling magnets that were described as diametrically magnetised when they were not. Of course, Amazon has done f**k all about it and they are still being sold.
I then found https://www.first4magnets.com/ and spoke to a customer representative. They assured me that their magnets described as ‘diametrically magnetised’ were exactly that, so I ordered a small pack of 10 x 6mm disc magnets. When they arrived, I again tested them with the magnetic field view paper and voila!
As you can see the diametrically magnetised magnet on the right has a coffee bean shape with the north and south poles emanating from the left and right sides of the disc rather than top/bottom faces. This is exactly what I wanted.
Tests with the AS5048 show a more expected output, with the only difficulty being in keeping the magnet central to the IC when holding it by hand. However, the output is going from zero up to about 900ish and then going back to zero. This is more in line with what I was expecting. So next I am going to 3D print some kind of jig to keep the magnet dead centre on the IC and the correct distance from it, so it can be tested properly. I can then use this as a test-bed for the upcoming project I intend on using these for (watch this space).