The first thing that I always do with a new I2C part is connect it up and run the I2C scanner to confirm the device is on the bus and the I2C address is correct.
// I2C scanner by Nick Gammon. Thanks Nick.
#include <Wire.h>
void setup() {
Serial.begin (115200); //*********** make sure serial monitor baud matches **********
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 1; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
This entire thread seems a bit strange since the original question was about setting up differential analog output and then goes on to deal with pulling digital data out of the registers. Based on a quick look at the data sheet, I think the analog output is available on pins and not thru i2c. I think there is also a note that the analog output may make the digital values incorrect?
I only need to read the Rpos register to obtain the position of the magnet
You need to spend some time studying the data sheet. This is not a simple device, and I have no direct experience with it. However, from my reading of the data sheet, I think that your initialization of the encoder is wrong for what you are trying to do.
Also, the wire library commands used to read the register are not correct in your code.
Try
#include <Wire.h>
const int SLAVE_ADDRESS=0x00;
int encodercount=0;
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("Start");
Serial.print("Encoder Init:");
initEncoder();
Serial.println(" ok");
}
void loop()
{
Wire.beginTransmission(SLAVE_ADDRESS);
Wire.write(0x32);//register to read from
Wire.endTransmission();
Wire.requestFrom(SLAVEADDRESS,2);
encodercount = Wire.read ();//Read MSB Data
encodercount <<= 8;
encodercount |= Wire.read (); //Read LSB Data and combine with MSB
Serial.print("Encoder value: ");
Serial.println(encodercount);
delay(500);
}
void writeRegister1(byte thisRegister, int thisValue)
{
long result = 0;
Wire.beginTransmission (SLAVE_ADDRESS);
result = Wire.write(thisRegister);
result = Wire.write(thisValue);
Wire.endTransmission ();
}
void initEncoder()
{
writeRegister1(0x01, 0x0000);
writeRegister1(0x00, 0x0000);
writeRegister1(0x03, 0x0000);
}
Does anyone know how to enable UVW output on this sensor board? I know that i have to set “BufSel” to 0 and "UVW" to 110 but i have no idea how to do that.
Does anyone know how to enable UVW output on this sensor board? I know that i have to set "BufSel" to 0 and "UVW" to 110 but i have no idea how to do that.
Do you have the data sheet? See the information on page 13. The setting you are asking for on UVW is for 7 pole pairs and a signal period length of 51.4 degrees. Is that what you want?
In the code posted above in reply #8
writeRegister1(0x01, 0x0000); //will set bufsel to 0
To set UVW to 110
writeRegister1(0x03, 0x0030); //will set UVW to 110