Hi everyone, I'm trying to write a code that will read an AS5048b magnetic encoder that is programmed with I2C using Arduino. I've been looking around a lot, but I'm extremely confused; I'm not sure even what my code will need in it to make it work. I know that I should be using the wire library, but I don't understand, for instance, what the high and low bits are, and how exactly I should initiate communication with the sensor and get it to return actual values. Any help would be greatly appreciated. Thanks!
I’m working on a similar project with a different sensor. You might get some useful hints here:
and I found this snippet of code and it’s comments informative:
//“Get Data. Compensate and Calculate New Heading”
Wire.write(HMC6352ReadAddress); // The “Get Data” command
//time delays required by HMC6352 upon receipt of the command
//Get Data. Compensate and Calculate New Heading : 6ms
Wire.requestFrom(HMC6352SlaveAddress, 2); //get the two data bytes, MSB and LSB
//“The heading output data will be the value in tenths of degrees //from zero to 3599 and provided in binary format over the two bytes.”
byte MSB =Wire.read();
byte LSB =Wire.read();
int headingSum = (MSB << 8) + LSB;//(MSB / LSB sum)
int headingInt = headingSum / 10;
Thank you very much. Sample code is really useful to be right now, as I'm having trouble figuring out what kind of commands my code will need.
Ok, so the encoder I’m using has two addresses listed for angular measurement, maybe one high byte and one low byte? How would I combine the two? Also, I got some help from someone who said I should send a 10000000 11111110 10000001 command to the sensor to initiate communication and read the high bytes and 10000000 11111111 10000001 for the low bytes. But I have no idea how to do that in Arduino with wire… Can someone help?