Week 17
Encoder
Now the magnets and TLE chips had finally arrived and I could continue.
First I finished soldering the breakout boards.
Then prepared the wiring between the main PCB and breakout boards. It is so much easier, when you have the right tools for this job.
Because the seat for the magnets, is in the hex head of the bolts, I needed to remove the embossed marking (A4-70) and drill a pocket for the magnet.
Here I'm working on the machining:
Once finished, the magnet sat nicely into the pocket and I glued it in place.
As you can see on the picture, the mounting plate has different pocket depths, because the AS5048B and TLE5012B don't have the same height, but need to be placed in similar distance to the magnet's surface.
I machined the bolts both for Ø6 mm and Ø8 mm magnets to see if there is a difference.
Note
It is necessary to use diametric magnets for this encoder applictions.
========================
Next was to connect the AS5048B encoder and see if I could get it running. I used the AMS_AS5048B library.
My first attempt wasn't succesful. No response from the encoder. I decided to run an I2C scanner and see if I could find the address - it didn't seem to work and I got no response. After that I decided to connect an OLED display parallel to the encoder and suddenly I found two devices.
Question
I don't understand what is going on, but when I have the OLED display connected, I can get a reading from the encoder. If I disconnect the display, the encoder stops working as well.
For now, I will continue with the OLED connected...
Here is the output from the Serial Plotter, when rotating the bolt.
And the next screenshot shows the noise of the signal. It is around ± 0,07° and I think averaging might be useful.
Another thing I have to take a look at is the bus address of the sensor. There two hardware pins, that should be used to change the address, but when I set the corresponding pin to HIGH or LOW - it doesn't seem to make any difference. The chip always has the same address (0x40
).
Here is the code I used until this point:
#include <SoftwareSerial.h>
#include <ams_as5048b.h>
#include <Wire.h>
//unit consts
#define U_RAW 1
#define U_TRN 2
#define U_DEG 3
#define U_RAD 4
#define U_GRAD 5
#define U_MOA 6
#define U_SOA 7
#define U_MILNATO 8
#define U_MILSE 9
#define U_MILRU 10
AMS_AS5048B mysensor;
// Encoder Pinout
#define A1 PIN_PF1
#define A2 PIN_PF0
// Pinout other
#define TTL_TX PIN_PF4
#define TTL_RX PIN_PF5
SoftwareSerial mySerial(TTL_RX, TTL_TX); // Serial for debugging
void setup(){
mySerial.begin(9600);
delay(1000);
mySerial.println("VÍ SKÖLL");
mySerial.println("Sun Tracker");
mySerial.println(".........");
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
Wire.begin();
delay(100);
mysensor.begin();
delay(100);
mySerial.println("Setup complete");
}
void loop(){
mysensor.updateMovingAvgExp();
mySerial.print(">");
mySerial.print("angle:");
mySerial.print(mysensor.angleR(U_DEG, false), DEC);
mySerial.print(",");
mySerial.print("avg:");
mySerial.println(mysensor.getMovingAvgExp(U_DEG), DEC);
delay(200);
}
Eventually, after a lot of troubleshooting, I found out that the wiring harness was damaged. One crimping was faulty (no connectivity), but for no obvious reason.
I checked the other harness and there I found two more faulty crimpings!
After having doublechecked and fixed all wiring issues, the pins A1 and A2 could be used to set the I2C address. Because I shorted A1 and A2 on one breakout board and not on the other, it is ensured that I will always get two different addresses, with the address pins set HIGH (0x41
and 0x43
).
Next I looked into zeroing the angles. This should be possible, by sending a zeroing command to the encoder.
First I tried setZeroReg();
and it did indeed zero the angle, but only until the next reboot.