Pages: [1]   Go Down
Author Topic: CMPS03 Magnetic Compass Question  (Read 1336 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Pages: [1]   Go Up
Jump to: