CMPS11 Calibration

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!

Moderator: phalanx

Tomadevil
Posts: 12
Joined: Wed Feb 10, 2016 4:10 pm

CMPS11 Calibration

Post by Tomadevil » Wed Feb 10, 2016 4:13 pm

Hi Guys,

I've been working a project, which involves using a CMPS11 digital compass. I'm an amateur at programming, so please excuse me for my silly questions.
I'm building a robot, which need to know its heading accurately. I chose I2C communication as the update rate of the signals has to be at least 15hz.
I used this program to read out the orientation:
http://www.robot-electronics.co.uk/htm/cmps11i2c.htm

As far as I know, the "angle full" would give me the heading. For some reasons, It's not accurate at all, actually, pretty useless. I want to calibrate the compass, but I'm stuck with it. I tried to send the commands in, but it doesn't seem to work. Can someone help me out and tell me what's wrong?

Code: Select all

#include <Wire.h>

#define ADDRESS 0x60

void setup(){
  Wire.begin();
  Serial.begin(9600);
  }

void loop(){
}

void calibrate(){

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF0);
  delay(25);

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF5);
  delay(25);

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF6);
  Wire.endTransmission();
  delay(25);

}
Regards,
Tamas

jremington
Support Volunteer
Posts: 2275
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: CMPS11 Calibration

Post by jremington » Thu Feb 11, 2016 11:37 am

You are sending the wrong command (0xF6 instead of 0xF7).

From the web page:
First of all you need to enter the calibration mode by sending a 3 byte sequence of 0xF0,0xF5 and then 0xF7 to the command register, these MUST be sent in 3 separate I2C frames, you cannot send them all at once. There MUST be a minimum of 20ms between each I2C frame. The LED will then extinguish and the CMPS11 should now be rotated in all directions on a horizontal plane, if a new maximum for any of the sensors is detected then the LED will flash, when you cannot get any further LED flashes in any direction then exit the calibration mode with a command of 0xF8.

Tomadevil
Posts: 12
Joined: Wed Feb 10, 2016 4:10 pm

Re: CMPS11 Calibration

Post by Tomadevil » Thu Feb 11, 2016 2:30 pm

Thanks for pointing that out. I corrected it, but it still doesn't work. :(

jremington
Support Volunteer
Posts: 2275
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: CMPS11 Calibration

Post by jremington » Thu Feb 11, 2016 3:33 pm

What do you mean by "doesn't work"?

Tomadevil
Posts: 12
Joined: Wed Feb 10, 2016 4:10 pm

Re: CMPS11 Calibration

Post by Tomadevil » Thu Feb 11, 2016 4:17 pm

I cannot start the calibration. The LED is not flashing as it is supposed to.

jremington
Support Volunteer
Posts: 2275
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: CMPS11 Calibration

Post by jremington » Thu Feb 11, 2016 7:35 pm

Post the code you are actually using. It appears that you never even call calibrate().

Tomadevil
Posts: 12
Joined: Wed Feb 10, 2016 4:10 pm

Re: CMPS11 Calibration

Post by Tomadevil » Fri Feb 12, 2016 2:14 am

Code: Select all

#include <Wire.h>

#define ADDRESS 0x60

void setup(){
  Wire.begin();
  Serial.begin(9600);
  }

void loop(){
}

void calibrate(){

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF0);
  delay(25);

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF5);
  delay(25);

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF7);
  Wire.endTransmission();
  delay(25);

}
Last edited by Tomadevil on Fri Feb 12, 2016 1:08 pm, edited 1 time in total.

Tomadevil
Posts: 12
Joined: Wed Feb 10, 2016 4:10 pm

Re: CMPS11 Calibration

Post by Tomadevil » Fri Feb 12, 2016 2:56 am

Even if I'm able to start the process of calibration. How do I send the last command (0xF8) to the compass? I think I should it manually, but how?

jremington
Support Volunteer
Posts: 2275
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: CMPS11 Calibration

Post by jremington » Fri Feb 12, 2016 9:08 am

Please, always use code tags.

You need to actually call the function calibrate. Do that in setup() by adding this line:

Code: Select all

  calibrate(); 
I suggest to call calibrate, delay 30-90 seconds while you perform the procedure, then send the 0xF8.
Or, wait for a button press, then send 0xF8 when done calibrating.

Tomadevil
Posts: 12
Joined: Wed Feb 10, 2016 4:10 pm

Re: CMPS11 Calibration

Post by Tomadevil » Fri Feb 12, 2016 1:39 pm

Thank you. I put that into the program. It still doesn't want to start the calibration unfortunately. The program looks like this now:

Code: Select all

#include <Wire.h>

#define ADDRESS 0x60

void setup(){
  Wire.begin();
  Serial.begin(9600);
  while(!Serial);
  calibrate();
}

void loop(){
}

void calibrate(){

  Serial.println("Calibration Mode");
  delay(2000);  //2 second before starting
  Serial.println("Start");

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF0);
  delay(25);

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF5);
  delay(25);

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF6);
  delay(20000);

  Wire.beginTransmission(ADDRESS);
  Wire.write(0xF8);
  Wire.endTransmission();
  Serial.println("done");


}
(Btw, 0xF7 command is for horizontal operation only)

jremington
Support Volunteer
Posts: 2275
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: CMPS11 Calibration

Post by jremington » Fri Feb 12, 2016 2:16 pm

Why did you add this line, and what is its purpose?

Code: Select all

  while(!Serial);

Valen
Support Volunteer
Posts: 1743
Joined: Wed Dec 22, 2010 2:05 am

Re: CMPS11 Calibration

Post by Valen » Fri Feb 12, 2016 2:19 pm

Have you considered removing the potential infinite-loop:

Code: Select all

while(!Serial);
If for whatever reason the serial port on your Arduino does not activate then it gets stuck there.

Tomadevil
Posts: 12
Joined: Wed Feb 10, 2016 4:10 pm

Re: CMPS11 Calibration

Post by Tomadevil » Fri Feb 12, 2016 5:37 pm

I removed the "while". Still doesn't "work"

Valen
Support Volunteer
Posts: 1743
Joined: Wed Dec 22, 2010 2:05 am

Re: CMPS11 Calibration

Post by Valen » Sat Feb 13, 2016 3:34 am

Do you receive anything on the serial monitor? If so, then it is working. Just not how you expect it to do. And the serial port should have worked or else you couldn't upload the program to it. Though the baudrate might be set differenly. Since you have not explained what sort of microcontroller this is running on, I would like to know more about this. Evidently by the code it is an arduino of some kind. How have you connected the CMPS11 chip to it? Please show how the wires are connected, and if you have pull up resistors applied to the wires.

Tomadevil
Posts: 12
Joined: Wed Feb 10, 2016 4:10 pm

Re: CMPS11 Calibration

Post by Tomadevil » Sat Feb 13, 2016 11:50 am

Yes I do receive messages on the serial monitor, but that doesn't necessarily mean it is working properly.
I'm sorry, you are right. I should have mentioned that this is running on an Arduino UNO. You can see how I connected it to the arduino here, and yes I have pull up resistors in circuit:
http://www.robot-electronics.co.uk/htm/ ... PS11%20I2C

Post Reply