Pages: [1]   Go Down
Author Topic: HELP! I cant get both HMC6352 Compass and ADNS2620 on ONE Arduino  (Read 1363 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Looking at the "2 nunchuck with arduino" solution http://www.wiimoteproject.com/general-discussion/2-nunchuck-with-arduino-help/?PHPSESSID=affa1d7af16fe51558af75e5789dbd31 it is possible to switch I2C reading between two devices on pins A4 & A5.

I am ready to follow the "nunchuck solution", but current working ADNS2620 communication requires the use of ADNS2620.h where Wire.h is not used.

So, I would like to communicate with ADNS2620 using Wire.h, this way I COULD read both HMC6352 Compass and ADNS2620 data.

Am I on the right track?
« Last Edit: March 28, 2011, 11:55:50 am by LucidGold » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

How can I implement Software I2C for Hmc6352 Compass http://www.arduino.cc/playground/Learning/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: http://code.google.com/p/fivevolt/source/browse/Quadcopter/Arduino/Telemetry/SoftTWI.cpp
.H: http://code.google.com/p/fivevolt/source/browse/Quadcopter/Arduino/Telemetry/SoftTWI.h

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.

Code:
#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?
« Last Edit: March 28, 2011, 12:03:37 pm by LucidGold » Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This may seem like a silly question but....

You have two different devices.

If you test them individually do they function correctly? Did you test them?

It would be nice to know that answer first.  You never said...
Logged

Just another Hacker

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

Quote
You have two different devices.

If you test them individually do they function correctly? Did you test them?

When you say two you mean: HMC6352 & ADNS2620? Yes I did, here is the working code for each:

ADNS2620
Code:
#include <adns2620.h>
ADNS2620 mouse(18,19);

void setup()
{
    mouse.begin();
    delay(100);
    mouse.sync();
    mouse.write(CONFIGURATION_REG, 0x01);
    Serial.begin(9600);
}

void loop()
{
 if (Serial.available() > 0)
   {
      int incomingByte = Serial.read();

      if (incomingByte == 'a')
      {       
        int8_t delta_X = mouse.read(DELTA_X_REG);
        int8_t delta_Y = mouse.read(DELTA_Y_REG);
       
        Serial.print(delta_X, DEC);
        Serial.print(',');
        Serial.println(delta_Y,DEC);
      }     
   }
}

HMC6352
Code:
#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!
Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok.

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.



Logged

Just another Hacker

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
ADNS2620 mouse(18,19);

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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
ADNS2620 mouse(18,19);

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

Just another Hacker

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

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.

Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Just another Hacker

Pages: [1]   Go Up
Jump to: