Ich hab hier ein CMPS10 Modul aber weiß nicht wie ich die Werte interpretieren soll
Verwende ihn am Arduino mit folgendem Sketch:
Spoiler anzeigen
C
/*
CMPS10 Kompass - i2c
needed: 2x 1k8 or 4k7 resistors between:
Arduino pin A4 and 5V -> CMPS10 SCL
Arduino pin A5 and 5V -> CMPS10 SDA
To enter the I2C mode of operation leave the mode pin unconnected
To enter the serial mode of operation connect the mode pin to ground
To enter the PWM mode of operation connect the select PWM pin to ground
http://www.hobbytronics.co.uk/cmps10-tilt-compass
*/
#include <Wire.h>
#include <CMPS10.h>
CMPS10 compass;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("Bearing: "); // Peilung
Serial.print(compass.bearing());
Serial.print(" Pitch: "); // Gefaelle
Serial.print(compass.pitch());
Serial.print(" Roll: "); // Neigung
Serial.println(compass.roll());
delay(100);
}
Alles anzeigen
Ich habs aber auch schon mit diesem Sketch probiert:
Spoiler anzeigen
Code
#include <Wire.h> // needed for CMPS10 Compass
#define COMPASS_I2C_ADDRESS 0x60 // CMPS10 Compass I2C address (default: 0x60)
void setup() {
Serial.begin(9600);
Wire.begin(); // Connect to I2C
}
void Compass() {
byte byteHigh, byteLow, 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(COMPASS_I2C_ADDRESS); //starts communication with CMPS10
Wire.write(2); //Sends the register we wish to start reading from
Wire.endTransmission();
Wire.requestFrom(COMPASS_I2C_ADDRESS, 4); // Request 4 bytes from CMPS10
while(Wire.available() < 4); // Wait for bytes to become available
byteHigh = Wire.read();
byteLow = Wire.read();
pitch = Wire.read();
roll = Wire.read();
bearing = ((byteHigh << 8) + byteLow) / 10; // Calculate full bearing
fine = ((highByte<<8)+lowByte)%10; // Calculate decimal place of bearing
Serial.print("Bearing: "); // Peilung
Serial.println(bearing);
Serial.print("Bearing decimal: "); // Peilung
Serial.println(fine);
Serial.print("Pitch: "); // Gefaelle
Serial.println(pitch);
Serial.print("Roll: "); // Neigung
Serial.println(roll);
}
Alles anzeigen
Als Wert gibt er mir zum Beispiel folgendes aus:
Pitch und Roll interessieren mich erst mal nicht, sondern nur Bearing. Die Werte liegen zwischen 0 und 359.9
Was sagt mir dieser Wert nun? Welcher Wert entspricht Norden, welcher Süden usw?
(er müsste jetzt glaub ich Richtung Westen liegen)
Sehe ich das richtig das:
270 --> Westen
180 --> Süden
90 --> Osten
0 --> Norden
entsprechen müsste
Muss man das Teil auch noch kalibrieren?