Need Help Making Code For Compass DC-SS503

Hi i bought this Dual Axis compass from the ebay store SureElectronics
http://cgi.ebay.com/NEW-Dual-axis-Magnetic-Sensor-Module-Interface-improved-/220752790999?pt=LH_DefaultDomain_0&hash=item3365e445d7

Thinking that there was Arduino codes for this already out there, But i don’t think a lot of people has put it on the web. I have found one post with some codes but it was written for the larger Arduino and it also used 74LS595.

I need help making a basic Compass code so i can read 0-359 degrees

Here is the link to where you can find the manual http://www.sure-electronics.net/download/index.php?name=DC-SS503&type=0

I am not able to do this on my own, thanks Eric

P1060926.jpg

Have connected it succesfully to your arduino? I mean, are you ready to start and test it?

Cheers,
Kari

Take a look at the examples in the playground page on i2C:
http://www.arduino.cc/playground/Learning/I2C

You need to dive into I2C programming and for Arduino there exist the Wire library for this. I2C is hardcoded on analog pin 4 and 5, furthermore you need to connect the GND of the Arduino and the compass.

device address is [0110000]

Code should be something like below (but as I don’t have such a compass I can’t test it. Hopes this helps,
Rob

setup()
{
...
  Wire.begin(); // join i2c bus (as master)
...
}

unsigned int getCompass()
{
  Wire.beginTransmission(0x30);  // this is 0110000
  Wire.send(0x01);      // TM Take Measurement Page 10 - http://www.sure-electronics.net/download/DC-SS503_Ver1.0_EN.pdf
  delay(?); 
  register = wire.receive();
  int X = wire.receive();
  X = X * 256 + wire.receive();
  int Y = wire.receive();
  Y *= 256 + wire.receive();
  msbY = wire.receive();
}

robtillaart:
You need to dive into I2C programming and for Arduino there exist the Wire library for this. I2C is hardcoded on analog pin 4 and 5, furthermore you need to connect the GND of the Arduino and the compass.

device address is [0110000]

Code should be something like below (but as I don't have such a compass I can't test it. Hopes this helps,
Rob

setup()

{
...
 Wire.begin(); // join i2c bus (as master)
...
}

unsigned int getCompass()
{
 Wire.beginTransmission(0x30);  // this is 0110000
 Wire.send(0x01);      // TM Take Measurement Page 10 - http://www.sure-electronics.net/download/DC-SS503_Ver1.0_EN.pdf
 delay(?);
 register = wire.receive();
 int X = wire.receive();
 X = X * 256 + wire.receive();
 int Y = wire.receive();
 Y *= 256 + wire.receive();
 msbY = wire.receive();
}

Hi thanks for the reply
So how do i test the code you have written for me.
I have so far been able to measure temperature, voltage (from a voltage divider i made) and have it displayed on a LCD screen. But i have just been combining and modifying codes i have found. I am interested in using my arduino for actual use's thats why i got the compass but it's proving to be really difficult to program.

IDK i will spend some more time trying to figure it out. Thanks you.. maybe i just need some one with the programing knowledge to explain it to me.

Bump =(

Eric1180:
Bump =(

Why are you crying?

IDK i will spend some more time trying to figure it out. Thanks you.. maybe i just need some one with the programing knowledge to explain it to me.

How did you spent your time?

What did you try?

Have you try to send the readings to your serial monitor?

Cheers,
Kari

So how do i test the code you have written for me.

Use it in a sketch. and work through the I2C tutorials on Arduino.cc

As the device addres is 7 bit you might need to shift it one bit right. 0x30 => 0X18
You can use the I2C scanner below to confirm the address.

/**
 * I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr, 
                void(*callback)(byte address, byte result) ) 
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,DEC);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}


byte start_address = 1;
byte end_address = 100;

// standard Arduino setup()
void setup()
{
    Wire.begin();

    Serial.begin(19200);
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,DEC);
    Serial.print(" to ");
    Serial.print(end_address,DEC);
    Serial.println("...");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");
}

// standard Arduino loop()
void loop() 
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}

Hopes this helps you to get started