Hello,
I'm in a bit of confusion about how to approach this implementation. What I am trying to do is use AS5048B Hall effect encoders to sense angle data and send it to my Teensy 3.6 Microcontroller programming with Teensyduino. The communication used is I2C for the AS5048B as opposed to the 5048A which uses SPI communication.
I have found a library GitHub - sosandroid/AMS_AS5048B: Arduino Lib for AMS AS5048B I2C - 14-bit magnetic rotary position sensor that has been very promising. I have decided to start with example code for detecting angles which is relevant to my project. The example code is below.
Here is the pinout for the Teensy 3.6. https://www.pjrc.com/teensy/card9a_rev1.pdf
I plan on using the following for pins. These pins correspond to the 7 pins on the encoder.
SCL Pin 7
SDA Pin 8
MOSI Pin 11
MISO Pin 12
GND
Vin (3.3 and 5V)
However, as much as I read into the library and datasheets for both the encoder and Teensy, I cannot get the sensor to read the change in an angle as I move the magnet that should activate the sensor. I have been stuck on this for a few days and would very much appreciate the help. I consider myself quite inexperienced so don't judge me if I'm missing something obvious.
#include <Wire.h> // Reference I2C bus library
#include <OneWire.h>
#include <ams_as5048b.h>
#define ONE_WIRE_BUS 4
//unit consts for AMS AS5048B sensor
#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
// Position sensor variables
AMS_AS5048B mysensor;
double EncoderAngle =0;
double deltaAngle = 0;
long steps = 0;
void setup() {
//Start serial
Serial.begin(11500);
while (!Serial) ; //wait until Serial ready
//init AMS_AS5048B object
mysensor.begin();
//consider the current position as zero
mysensor.setZeroReg();
}
void loop() {
getAngle();
Serial.print("Angle degree : ");
Serial.println(mysensor.angleR(U_DEG, false), DEC);
Serial.print("EncoderAngle: ");
Serial.println(EncoderAngle);
Serial.print("DeltaAngle: ");
Serial.println(mysensor.angleR(U_DEG, false)-EncoderAngle, DEC);
Serial.print("DeltaAngle: ");
Serial.println(mysensor.angleR(U_DEG, false)-EncoderAngle);
delay(2000);
}
void getAngle() {
// read sensor to get the encoder angle
EncoderAngle = mysensor.angleR(U_DEG, false);
delay(2000);
}
teensy.pdf (221 KB)