Digitális iránytű kalibráció (CMPS11)

Processing/Wiring (illetve C) nyelvű programozási fogások, tippek. (AVR-Duino, Arduino, EthDuino, Diecimila, Severino, Nano, LilyPad)
Válasz küldése
Tomadevil
Újonc
Újonc
Hozzászólások: 5
Csatlakozott: 2016. január 27. szerda, 20:03

Digitális iránytű kalibráció (CMPS11)

Hozzászólás Szerző: Tomadevil »

Sziasztok,

Segítséget szeretnék kérni a fent nevezett digitális iránytű kalibrációjában. Itt található meg hozzá a kalibrációhoz szükséges információk.
http://www.robot-electronics.co.uk/htm/cmps11i2c.htm

I2C kommunikációt használok, de sajnos még nem tudtam elindítani a kalibráció módot. Az oldal alján mellékeltem a kódot, amivel eddig próbálkoztam. Mit kellene a kódon változtatni, hogy működjön? Elég új vagyok a programozásban, szóval légyszíves ne akadjatok ki, ha kicsit szájbarágósan kérem az információt.

Kód: Egész kijelölése

#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);

}
Tomadevil
Újonc
Újonc
Hozzászólások: 5
Csatlakozott: 2016. január 27. szerda, 20:03

Re: Digitális iránytű kalibráció (CMPS11)

Hozzászólás Szerző: Tomadevil »

Senki se kompetens a témában?
Avatar
kapu48
Elektronbűvölő
Hozzászólások: 3375
Csatlakozott: 2008. augusztus 29. péntek, 6:00

Re: Digitális iránytű kalibráció (CMPS11)

Hozzászólás Szerző: kapu48 »

Próbáld ezt!

Kód: Egész kijelölése

/*****************************************
 * cmps11_I2C.ino
 * http://www.robot-electronics.co.uk/htm/arduino_examples.htm#CMPS11%20I2C 
*     CMPS11 I2C example for Arduino     *
*        By James Henderson, 2014        * 
*****************************************/

#include <Wire.h>

#define CMPS11_ADDRESS 0x60  // Address of CMPS11 shifted right one bit for arduino wire library
#define ANGLE_8  1           // Register to read 8bit angle from

unsigned char high_byte, low_byte, angle8;
char pitch, roll;
unsigned int angle16;

void setup()
{
  Serial.begin(9600);  // Start serial port
  Wire.begin();
}

void loop()
{

  Wire.beginTransmission(CMPS11_ADDRESS);  //starts communication with CMPS11
  Wire.write(ANGLE_8);                     //Sends the register we wish to start reading from
  Wire.endTransmission();
 
  // Request 5 bytes from the CMPS11
  // this will give us the 8 bit bearing, 
  // both bytes of the 16 bit bearing, pitch and roll
  Wire.requestFrom(CMPS11_ADDRESS, 5);       
  
  while(Wire.available() < 5);        // Wait for all bytes to come back
  
  angle8 = Wire.read();               // Read back the 5 bytes
  high_byte = Wire.read();
  low_byte = Wire.read();
  pitch = Wire.read();
  roll = Wire.read();
  
  angle16 = high_byte;                 // Calculate 16 bit angle
  angle16 <<= 8;
  angle16 += low_byte;
    
  Serial.print("roll: ");               // Display roll data
  Serial.print(roll, DEC);
  
  Serial.print("    pitch: ");          // Display pitch data
  Serial.print(pitch, DEC);
  
  Serial.print("    angle full: ");     // Display 16 bit angle with decimal place
  Serial.print(angle16 / 10, DEC);
  Serial.print(".");
  Serial.print(angle16 % 10, DEC);
  
  Serial.print("    angle 8: ");        // Display 8bit angle
  Serial.println(angle8, DEC);
  
  delay(100);                           // Short delay before next loop
}
Tomadevil
Újonc
Újonc
Hozzászólások: 5
Csatlakozott: 2016. január 27. szerda, 20:03

Re: Digitális iránytű kalibráció (CMPS11)

Hozzászólás Szerző: Tomadevil »

kapu48 írta:Próbáld ezt!

Kód: Egész kijelölése

/*****************************************
 * cmps11_I2C.ino
 * http://www.robot-electronics.co.uk/htm/arduino_examples.htm#CMPS11%20I2C 
*     CMPS11 I2C example for Arduino     *
*        By James Henderson, 2014        * 
*****************************************/

#include <Wire.h>

#define CMPS11_ADDRESS 0x60  // Address of CMPS11 shifted right one bit for arduino wire library
#define ANGLE_8  1           // Register to read 8bit angle from

unsigned char high_byte, low_byte, angle8;
char pitch, roll;
unsigned int angle16;

void setup()
{
  Serial.begin(9600);  // Start serial port
  Wire.begin();
}

void loop()
{

  Wire.beginTransmission(CMPS11_ADDRESS);  //starts communication with CMPS11
  Wire.write(ANGLE_8);                     //Sends the register we wish to start reading from
  Wire.endTransmission();
 
  // Request 5 bytes from the CMPS11
  // this will give us the 8 bit bearing, 
  // both bytes of the 16 bit bearing, pitch and roll
  Wire.requestFrom(CMPS11_ADDRESS, 5);       
  
  while(Wire.available() < 5);        // Wait for all bytes to come back
  
  angle8 = Wire.read();               // Read back the 5 bytes
  high_byte = Wire.read();
  low_byte = Wire.read();
  pitch = Wire.read();
  roll = Wire.read();
  
  angle16 = high_byte;                 // Calculate 16 bit angle
  angle16 <<= 8;
  angle16 += low_byte;
    
  Serial.print("roll: ");               // Display roll data
  Serial.print(roll, DEC);
  
  Serial.print("    pitch: ");          // Display pitch data
  Serial.print(pitch, DEC);
  
  Serial.print("    angle full: ");     // Display 16 bit angle with decimal place
  Serial.print(angle16 / 10, DEC);
  Serial.print(".");
  Serial.print(angle16 % 10, DEC);
  
  Serial.print("    angle 8: ");        // Display 8bit angle
  Serial.println(angle8, DEC);
  
  delay(100);                           // Short delay before next loop
}
Ez a kód csak az adatok kiolvasására alkalmas, nem kalibrációra.
Tomadevil
Újonc
Újonc
Hozzászólások: 5
Csatlakozott: 2016. január 27. szerda, 20:03

Re: Digitális iránytű kalibráció (CMPS11)

Hozzászólás Szerző: Tomadevil »

Köszönöm a segítséget. Téma törölhető :)
Válasz küldése