How can I implement Software I2C for Hmc6352 Compass Arduino Playground - Hmc6352 ?
If I can get my compass to work through Software I2C using other pins, then ADNS-2620 should work correctly with A5 and A4.
I have looked at:
SoftI2CMaster:
.CPP: http://blinkm-projects.googlecode.com/svn/trunk/blinkm_examples/arduino/BlinkMSoftI2CDemo/SoftI2CMaster.cpp
.H: http://blinkm-projects.googlecode.com/svn/trunk/blinkm_examples/arduino/BlinkMSoftI2CDemo/SoftI2CMaster.h
I did not use this because there is no Software RECIEVE method.
SoftTWI:
.CPP: Google Code Archive - Long-term storage for Google Code Project Hosting.
.H: Google Code Archive - Long-term storage for Google Code Project Hosting.
I am unable to get my code to work, I keep getting 0.00 degrees. I used A5 and A4 because using Wire.H through the same code (replace every "compass." with "Wire."), I am able to get compass data. However, when I switch to SoftTWI I get 0.00.
#include "SoftTWI.h"
SoftTWI compass;
void setup()
{
Serial.begin(9600); // Initiate Serial
compass.attach(A5, A4);
compass.begin();
}
void loop(){
compass.beginTransmission(0x21);
compass.send(65); // Send "Get Data" command, info from Datasheet
delay(100); // interface command delay, info from Datasheet
compass.requestFrom(0x21, 2); //get the two data bytes, MSB and LSB
byte MSB = compass.receive(); // Result will be in tenths of degrees (0 to 3599)
byte LSB = compass.receive(); // Provided in binary format over two bytes."
compass.endTransmission();
// Compute result from the two bytes results
float myres = ((MSB << 8) + LSB) / 10;
// Display result
Serial.print(myres);
Serial.println(" degrees");
delay(1000);
}
Any thoughts?