Go Down

Topic: CMPS03 Magnetic Compass Question (Read 2063 times) previous topic - next topic

nairda10

Hello everybody

I have a little problem with my CMPS03.

I use an Arduino Duemilanove, and I have connected the compass like this:

This is my code, its very easy, but it doesn't work. I read the PWM signal, not the I2C...

Code: [Select]
#define out 13
#define compass 7

int input = 0;
int heading = 0;

void setup() {
  pinMode(compass, INPUT);
  pinMode(out, OUTPUT);
}

void loop() {
  input = pulseIn(compass, HIGH);    //Read Compass
  heading = (input/1000-1)*10;       //Transform into degrees
  if(heading > 180)                  //When facing west,
  {digitalWrite(out, HIGH);
  delay(100);                        //Blink for 1/10 of a second
  digitalWrite(out, LOW);
  } else {                           //When facing east,
    digitalWrite(out, HIGH);
    delay(1000);                     //Blink for 1 second
    digitalWrite(out, LOW);
  }
}


It blinks almost only in 1 second intervals.

Can somebody enlighten me? Am I using wrong numbers?
Or could the controller create a magnetic field which influeces the compass?

This site was my reference: http://www.robot-electronics.co.uk/htm/cmps3tech.htm

Thank you very much for your help.

johnwasser

Even if it only briefly hits >180° it will spend ten times as long in that blink as in the shorter blinks.

Perhaps you can make it blink more often:

Code: [Select]

  {digitalWrite(out, HIGH);
  delay(heading);
  {digitalWrite(out, LOW);


You should then see the light blink fast for low azimuth angles and slower for high azimuth angles.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy