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

Hello, does anyone know about serial control on cmps10 ( Tilt Compensated Magnetic Compass) with aduino?
Thanks.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8821
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.robot-electronics.co.uk/htm/cmps10doc.htm

http://www.robot-electronics.co.uk/htm/arduino_examples.htm#Tilt%20Compensated%20Magnetic%20Compass
Logged

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

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

I know those links but I don't wanna drive a LCD display with arduino, I just wanna read the output value of cmps10.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8821
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you implying that you want someone to write the sketch for you?  Perhaps you should offer money.
Logged

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

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

I know those links but I don't wanna drive a LCD display with arduino, I just wanna read the output value of cmps10.

This is not perfekt
a little step forward?


#include <Wire.h>

#define ADDRESS 0x60                                          // Defines address of CMPS10

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

void loop(){
   byte highByte, lowByte, fine;              // highByte and lowByte store high and low bytes of the bearing and fine stores decimal place of bearing
   char pitch, roll;                          // Stores pitch and roll values of CMPS10, chars are used because they support signed value
   int bearing;                               // Stores full
   
   Wire.beginTransmission(ADDRESS);           //starts communication with CMPS10
   Wire.write(2);                              //Sends the register we wish to start reading from
   Wire.endTransmission();

   Wire.requestFrom(ADDRESS, 4);              // Request 4 bytes from CMPS10
   while(Wire.available() < 4);               // Wait for bytes to become available
   highByte = Wire.read();     
   lowByte = Wire.read();   
   pitch = Wire.read();             
   roll = Wire.read();   
   
   
   bearing = ((highByte<<smiley-cool+lowByte)/10;      // Calculate full bearing
   fine = ((highByte<<smiley-cool+lowByte)%10;         // Calculate decimal place of bearing
   
   display_data(bearing, fine, pitch, roll);  // Display data to the LCD03
   
   delay(3000);
}

void display_data(int b, int f, int p, int r){    // pitch and roll (p, r) are recieved as ints instead oif bytes so that they will display corectly as signed values.
 
  /*lcd03.write(LCD03_SET_CUR);                     // Set the LCD03 cursor position
  lcd03.write(1); 
  lcd03.print("CMPS10 Example V:");
  lcd03.print(soft_ver());                        // Display software version of the CMPS10
 
  delay(5);                                       // Delay to allow LCD03 to proscess data 
 
  lcd03.write(LCD03_SET_CUR);
  lcd03.write(21); 
  lcd03.print("Bearing = ");                      // Display the full bearing and fine bearing seperated by a decimal poin on the LCD03
  lcd03.print(b);                               
  lcd03.print(".");
  lcd03.print(f);
  lcd03.print("  ");

  delay(5);

  lcd03.write(LCD03_SET_CUR);                     // Display the Pitch value to the LCD03
  lcd03.write(41);
  lcd03.print("Pitch = ");
  lcd03.print(p);
  lcd03.print(" ");

  delay(5);
 
  lcd03.write(LCD03_SET_CUR);                     // Display the roll value to the LCD03
  lcd03.write(61);
  lcd03.print("Roll = ");
  lcd03.print(r);
  lcd03.print(" ");*/
  Serial.print("bearing: ");
  Serial.println(b);
 
  Serial.print("fine: ");
  Serial.println(f);
  Serial.print("pitch: ");
  Serial.println(p);
  Serial.print("roll: ");
  Serial.println(r);
}



int soft_ver(){
   int data;                                      // Software version of  CMPS10 is read into data and then returned
   
   Wire.beginTransmission(ADDRESS);
   // Values of 0 being sent with write need to be masked as a byte so they are not misinterpreted as NULL this is a bug in arduino 1.0
   Wire.write((byte)0);                           // Sends the register we wish to start reading from
   Wire.endTransmission();

   Wire.requestFrom(ADDRESS, 1);                  // Request byte from CMPS10
   while(Wire.available() < 1);
   data = Wire.read();           
   
   return(data);
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have modified the code from robot-electronics.com, and it's works:

Code:
/****************************************************************
*                  Arduino CMPS10 example code                  *
*                    CMPS10 running I2C mode                    *
*                    by James Henderson, 2012                   *
*****************************************************************/
#include <Wire.h>
//#include <SoftwareSerial.h>

#define ADDRESS 0x60                                          // Defines address of CMPS10

//#define LCD_RX              0x02                              // RX and TX pins used for Wire03 serial port
//#define LCD_TX              0x03
#define Wire_HIDE_CUR      0x04
#define Wire_CLEAR         0x0C
#define Wire_SET_CUR       0x02

//SoftwareSerial Wire =  SoftwareSerial(LCD_RX, LCD_TX);      // Defines software serial port for Wire

void setup(){
  Wire.begin();                                               // Conects I2C
  Serial.begin(9600);
  Wire.write(Wire_HIDE_CUR);
  Wire.write(Wire_CLEAR);
}

void loop(){
   byte highByte, lowByte, fine;              // highByte and lowByte store high and low bytes of the bearing and fine stores decimal place of bearing
   char pitch, roll;                          // Stores pitch and roll values of CMPS10, chars are used because they support signed value
   int bearing;                               // Stores full bearing
   
   Wire.beginTransmission(ADDRESS);           //starts communication with CMPS10
   Wire.write(2);                              //Sends the register we wish to start reading from
   Wire.endTransmission();

   Wire.requestFrom(ADDRESS, 4);              // Request 4 bytes from CMPS10
   while(Wire.available() < 4);               // Wait for bytes to become available
   highByte = Wire.read();           
   lowByte = Wire.read();           
   pitch = Wire.read();             
   roll = Wire.read();               
   
   bearing = ((highByte<<8)+lowByte)/10;      // Calculate full bearing
   fine = ((highByte<<8)+lowByte)%10;         // Calculate decimal place of bearing
   
   display_data(bearing, fine, pitch, roll);  // Display data to the Wire
   
   delay(100);
}

void display_data(int b, int f, int p, int r){    // pitch and roll (p, r) are recieved as ints instead oif bytes so that they will display corectly as signed values.
 
  Wire.write(Wire_SET_CUR);                     // Set the Wire cursor position
  Wire.write(1); 
  //Serial.print("CMPS10 Example V:");
  //Serial.print(soft_ver());                        // Display software version of the CMPS10
 
  delay(5);                                       // Delay to allow Wire to proscess data 
 
  Wire.write(Wire_SET_CUR);
  Wire.write(21); 
  Serial.print("Bearing = ");                      // Display the full bearing and fine bearing seperated by a decimal poin on the Wire
  Serial.print(b);                               
  Serial.print(".");
  Serial.print(f);
  Serial.print(" \n");

  delay(5);

  Wire.write(Wire_SET_CUR);                     // Display the Pitch value to the Wire
  Wire.write(41);
  //Serial.print("Pitch = ");
  //Serial.print(p);
  //Serial.print(" /t");

  delay(5);
 
  Wire.write(Wire_SET_CUR);                     // Display the roll value to the Wire
  Wire.write(61);
  //Serial.print("Roll = ");
  //Serial.print(r);
  //Serial.print(" /n");
}

/*
int soft_ver(){
   int data;                                      // Software version of  CMPS10 is read into data and then returned
   
   Wire.beginTransmission(ADDRESS);
   // Values of 0 being sent with write need to be masked as a byte so they are not misinterpreted as NULL this is a bug in arduino 1.0
   Wire.write((byte)0);                           // Sends the register we wish to start reading from
   Wire.endTransmission();

   Wire.requestFrom(ADDRESS, 1);                  // Request byte from CMPS10
   while(Wire.available() < 1);
   data = Wire.read();           
   
   return(data);
}
*/
Logged

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

Not trying to raise this thread from the dead, but for anyone who comes to this thread via google like I did,  I ended up using this library someone made: https://github.com/kragniz/CMPS10
Logged

Pages: [1]   Go Up
Jump to: