I would like to get values from both HMC6352 Compass and ADNS2620 using one arduino. I am currently using Arduino Duemilanove (ATMEGA328). The problem is that both of them use pins A4 & A5.
From what I gather the ADNS-2620 doesn't have a full I2C interface so it doesn't have an I2C address and can't share an I2C bus with real I2C devices. I think you will have to implement a separate, software I2C bus for it.
You might have better luck with the ADNS-3000 which has an SPI interface.
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);
}
#include "Wire.h"
void setup()
{
Serial.begin(9600); // Initiate Serial
Wire.begin();
}
void loop(){
Wire.beginTransmission(0x21);
Wire.send(65); // Send "Get Data" command, info from Datasheet
delay(100); // interface command delay, info from Datasheet
Wire.requestFrom(0x21, 2); //get the two data bytes, MSB and LSB
byte MSB = Wire.receive(); // Result will be in tenths of degrees (0 to 3599)
byte LSB = Wire.receive(); // Provided in binary format over two bytes."
Wire.endTransmission();
// Compute result from the two bytes results
float myres = ((MSB << 8) + LSB) / 10;
// Display result
Serial.print(myres);
Serial.println(" degrees");
delay(1000);
}
They both function correctly when either one of them is connected to the arduino alone. But together it will not work!
Knowing that information removes doubts about the device....
That's why I asked. So this is about making the sensors work on the same device -- it's not about project guidance.
Sorry I don't know where it is... where is this code???? Sorry if I missed it. #Include <adns2620.h>
Looking at that code may indicate why it does not play nice with the other sensor... It might also give a hint as to how to use the other libraries with it.
Wait... If the mouse library uses hardware I2C, why do you need to pass it the pin numbers?!?
I suspect the mouse library implements a SOFTWARE I2C-like interface. Have you tried specifying DIFFERENT pins when you create the mouse instance and connecting the mouse to those pins? If that works your problem is solved.
Wait... If the mouse library uses hardware I2C, why do you need to pass it the pin numbers?!?
I suspect the mouse library implements a SOFTWARE I2C-like interface. Have you tried specifying DIFFERENT pins when you create the mouse instance and connecting the mouse to those pins? If that works your problem is solved.
Like I2C to the compass sensor and the software I2C to the mouse???
Or use two instances of wire with different pins? (I think you mean this correct?)
WillR:
I am looking at it from a "project design" perspective: Should I use two Arduinos for what I would like to accomplish OR there are other methods like extending I2C capability?
I have already went through the 2 arduinos approach, however, not happy.
John:
I will try this out and get back to you. I will cry if that works.
LucidGold:
WillR:
I am looking at it from a "project design" perspective: Should I use two Arduinos for what I would like to accomplish OR there are other methods like extending I2C capability?
I have already went through the 2 arduinos approach, however, not happy.
John:
I will try this out and get back to you. I will cry if that works.
Or drink a bottle of fine scotch -- and send one to John!