I saw this video from James Bruton. See the links to the GitHub repos in the video description.
I bought a few AS5048B boards from AMS, so I can measure the position of my stepper motors.
In the sosandroid
repo, I ran program_address
and was able to get one of them working, but they all have the same I2C address, and because I want to have 6 of them running simultaneously, it of course won't work. I know I could get an I2C multiplexer...
I also tried setting the A1 and A2 pins on the AS5048B to high and low, which change the I2C address (for a total of 4)... But I want to change the I2C address permanently for each board.
It looks to me like program_address
is supposed to permanently program the I2C address, which the user can specify in the .ino file:
// Construct our AS5048B object with an I2C address of 0x40
AMS_AS5048B mysensor(0x40);
But no matter what I set it to (e.g. 0x40, 0x41, 0x42, 0x43, 0x44
), the Arduino I2C scanner always finds 0x44
, which is the default address, so the program_address
must not be working.
EDIT: the default address is actually 0x40
. I must have programmed it to 0x44
without knowing (I was playing around with this board trying to figure this all out).
I know that normally the I2C addresses cannot be changed, but it looks like this one can:
Here's a snippet from the link above. It says the OTP bits can be programmed/burned (only once!). My understanding is that the I2C address is saved in the OTP bits.
Program the OTP bits permanently:
- Write dec.253 into the OTP control register (dec.3) to enable the special programming mode
- Set the Burn bit (dec.8) in the OTP control register (dec.3) to enable automatic programming procedure
- Write dec.0 into the OTP control register (dec.3) to disable the special programming mode
I am using the Teensy 4.1 using PlatformIO in VS Code, and I also tried using an Arduino Uno in the Arduino IDE.
My wiring is as follows:
So how do I program the I2C address on the AS5048B boards?
EDIT:
- I changed an image to text, and cleaned things up.
As @6v6gt requested, I used the I2C scanner and it is still showing 0x40 (on this particular board), so it must not have been programmed (unless it's possible to program it to 0x40 even though 0x40 is its default value). The only thing I changed from the program_address
repo is this line in the .ino file:
// Construct our AS5048B object with an I2C address of 0x40
AMS_AS5048B mysensor(0x48);
I changed the 0x40 to 0x48. But now I am getting this in the serial monitor:
Angle degree : I2C error: 2
359.9780273437
Since I must have programmed the other board to 0x44 successfully, I am trying to think of what I did differently, but I don't remember.
There are hundreds of lines of code in program_address
(and the .h and .cpp file), so I probably shouldn't post all of it here. But here's the GitHub repo.