Hallo Leute,
ich habe folgendes Problem.
Ich brauche einen Kompassschaltung, am besten mit dem HMC8553L wo mir
unabhängig von der Einbaulage des Kompassmodules immer die richtige
Heading Richtung ( KURS) angezeigt wird.
D.h richte ich dass Ding auf Kurs W 270° aus, so soll dieser bei
schräger, kopfüberer Haltung immer den selben Kurswert liefern. Also so
wie es im Flugzeug auch ist, wenn dieses eine Rolle fliegt.
Wie bewerkstelligt man das?
Oder ist das Modul ungeeignet?
lg
Dieter
PS:
Das Modul habe ich mit diesem Code aus Arduino Kochbuch getestet. Der
Sketch ist analog zum Sample Sketch von Sparkfun.
1 | /*
|
2 | Uses HMC5883L to get earths magnetic field in x,y and z axis
|
3 | Displays direction as angle between 0 and 359 degrees
|
4 | */
|
5 |
|
6 | #include <Wire.h> //I2C Arduino Library
|
7 |
|
8 | const int hmc5883Address = 0x1E; //0011110b, I2C 7bit address of HMC5883
|
9 | const byte hmc5883ModeRegister = 0x02;
|
10 | const byte hmcContinuousMode = 0x00;
|
11 | const byte hmcDataOutputXMSBAddress = 0x03;
|
12 |
|
13 |
|
14 | void setup(){
|
15 | //Initialize Serial and I2C communications
|
16 | Serial.begin(9600);
|
17 | Wire.begin();
|
18 |
|
19 | //Put the HMC5883 IC into the correct operating mode
|
20 | Wire.beginTransmission(hmc5883Address); //open communication with HMC5883
|
21 | Wire.write(hmc5883ModeRegister); //select mode register
|
22 | Wire.write(hmcContinuousMode); //continuous measurement mode
|
23 | Wire.endTransmission();
|
24 | }
|
25 |
|
26 | void loop(){
|
27 |
|
28 | int x,y,z; //triple axis data
|
29 |
|
30 | //Tell the HMC5883 where to begin reading data
|
31 | Wire.beginTransmission(hmc5883Address);
|
32 | Wire.write(hmcDataOutputXMSBAddress); //select register 3, X MSB register
|
33 | Wire.endTransmission();
|
34 |
|
35 |
|
36 | //Read data from each axis, 2 registers per axis
|
37 | Wire.requestFrom(hmc5883Address, 6);
|
38 | if(6<=Wire.available()){
|
39 | x = Wire.read()<<8; //X msb
|
40 | x |= Wire.read(); //X lsb
|
41 | z = Wire.read()<<8; //Z msb
|
42 | z |= Wire.read(); //Z lsb
|
43 | y = Wire.read()<<8; //Y msb
|
44 | y |= Wire.read(); //Y lsb
|
45 | }
|
46 |
|
47 | //Print out values of each axis
|
48 | Serial.print("x: ");
|
49 | Serial.print(x);
|
50 | Serial.print(" y: ");
|
51 | Serial.print(y);
|
52 | Serial.print(" z: ");
|
53 | Serial.print(z);
|
54 |
|
55 | int angle = atan2(-y , x) / M_PI * 180; // angle is atan(-y/x)
|
56 | if(angle < 0)
|
57 | angle = angle + 360; // angle from 0 to 359 instead of plus/minus 180
|
58 | Serial.print(" Direction = ");
|
59 | Serial.println(angle);
|
60 |
|
61 | delay(250);
|
62 | }
|