Pages: [1]   Go Down
Author Topic: Reading a Magnetic Encoder with I2C  (Read 764 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on a similar project with a different sensor. You might get some useful hints here:

http://wiring.org.co/learning/libraries/hmc6352sparkfun.html

here: https://sites.google.com/site/wayneholder/self-driving-rc-car/steering-to-a-heading

and I found this snippet of code and it's comments informative:

 //"Get Data. Compensate and Calculate New Heading"

  Wire.beginTransmission(HMC6352SlaveAddress);
  Wire.write(HMC6352ReadAddress);    // The "Get Data" command
  Wire.endTransmission();

  //time delays required by HMC6352 upon receipt of the command
  //Get Data. Compensate and Calculate New Heading : 6ms

  delay(6);

  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 << smiley-cool + LSB;//(MSB / LSB sum)
int headingInt = headingSum / 10;
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bump?
Logged

Pages: [1]   Go Up
Jump to: