Judul : Sensor Kompas DJI Phantom (Edisi Memanfaatkan Bekas Repair DJI Phantom)
link : Sensor Kompas DJI Phantom (Edisi Memanfaatkan Bekas Repair DJI Phantom)
Sensor Kompas DJI Phantom (Edisi Memanfaatkan Bekas Repair DJI Phantom)
Hallo Sobat Arduino Indonesia, Bagaimana kabarnya.. Long time no see ( iya yang nulis lagi banyak kegiatan jadi jarang banget bikin tutorial)Oke iseng-iseng liat tumpukan banyak bangkai DJI Phantom bekas repairan Klinik Drone, rasanya harus ada yang bisa di manfaatin. Nah di mulai dari bagian paling bawah sendiri alias landing gear nya.
Setelah di urut-urut ada kabel di landing gear tersebut, otomatis pasti ada sesuatu. Nah sekarang kita coba untuk di bongkar, ada apa gerangan di landing gear nya
Ketemulah benda mungil seperti di bawah ini, tak lain adalah sensor kompas dari dji Phantom
oke, karena ada 4 kabel, ada 2 kemungkinannya si DJI ini mengakses sensor kompas tersebut dengan komunikasi Serial atau I2C. Tapi so far biasanya sih kalau akses sensor-sensor paling enak dengan menggunakan I2C. Nah sambil diurut2, ketemulah tulisan SDA, SCL, 5V, GND.Oke Fix berarti sensor ini menggunakan komunikasi I2C.
Sip, tugasnya sekarang adalah mencari alamat dari I2C tersebut, oke disambungkanlah dengan bantuan Arduino
Sensor DJI Kompas | Arduino |
Dari kabel warna Hitam (SDA) | A4 |
5V | 5V |
GND | GND |
SCL | A5 |
Untuk program arduino cari alamat I2C, bisa di lihat disini codingnya I2C Scanner
Dan hasilnya didapatlah alamat 1E
ALamat 1E ini familier banget dengan modul-modul kompas yang ada di pasaran, yakni modul gy 271 atau gy 273 dengan ic HMC5883. Nah kemungkinan modul kompas DJI ini pake IC Tersebut, okelah kita coba dengan coding kompas HMC5883, yangseperti di bawah ini
#include <Wire.h>
#include <math.h>
// updates to cope with Arduino V1.0( and newer?) and older versions (22 & lower)
#define I2C_TX write
#define I2C_RX read
//#define SCALE //use this to scale each axis if the test data does not give a circular (spherical 3D) plot
// done as #def for max performance of code not using the scale factors!
// use to switch the serial output data to a CSV format of raw x,y,z data values to help calibrate your compass
#define RAW_DATA_CSV
// ALSO use this #def to format output to easly paste into a data array - eg to display data in Processing. See usabledevices.com for example.
#define RAW_DATA_ARRAY
// Shift the device's documented slave address (0x3C) for write operation
// 1 bit right.This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)
#define HMC5883_WriteAddress 0x1E // i.e 0x3C >> 1
#define HMC5883_ModeRegisterAddress 0x02
#define HMC5883_ContinuousModeCommand (uint8_t)0x00 // cast to uint8_t added to get code to compile under Arduino v1.0
#define HMC5883_DataOutputXMSBAddress 0x03
int regb=0x01;
int regbdata=0x40;
int outputData[6];
// calibrate YOUR compass, so compass raw x,y (,z) data is centered around 0,0,0 axis!
// To do this read do an XY scatter plot for 2D xy data, and just "read"
// work out or guess the offset to center the data (you need to rotate the compass to get lots of data pairs)
// for my compass the values where x=-100, y=-100 (did not work out z axis!)
const int x_offset = 0;
const int y_offset = 0;
const int z_offset = 0;
#ifdef SCALE
const int x_scale = 1;
const int y_scale = 1;
const int z_scale = 1;
#endif
void setup()
{
Serial.begin(9600);
Wire.begin(); //Initiate the Wire library and join the I2C bus as a master
}
void loop() {
int i,x,y,z;
double angle;
Wire.beginTransmission(HMC5883_WriteAddress);
Wire.I2C_TX(regb);
Wire.I2C_TX(regbdata);
Wire.endTransmission();
delay(1000);
Wire.beginTransmission(HMC5883_WriteAddress); //Initiate a transmission with HMC5883 (Write address).
Wire.I2C_TX(HMC5883_ModeRegisterAddress); //Place the Mode Register Address in send-buffer.
Wire.I2C_TX(HMC5883_ContinuousModeCommand); //Place the command for Continuous operation Mode in send-buffer.
Wire.endTransmission(); //Send the send-buffer to HMC5883 and end the I2C transmission.
delay(100);
Wire.beginTransmission(HMC5883_WriteAddress); //Initiate a transmission with HMC5883 (Write address).
Wire.requestFrom(HMC5883_WriteAddress,6); //Request 6 bytes of data from the address specified.
delay(500);
//Read the value of magnetic components X,Y and Z
if(6 <= Wire.available()) // If the number of bytes available for reading be <=6.
{
for(i=0;i<6;i++)
{
outputData[i]=Wire.I2C_RX(); //Store the data in outputData buffer
}
}
x=outputData[0] << 8 | outputData[1]; //Combine MSB and LSB of X Data output register
z=outputData[2] << 8 | outputData[3]; //Combine MSB and LSB of Z Data output register
y=outputData[4] << 8 | outputData[5]; //Combine MSB and LSB of Y Data output register
#ifdef SCALE
angle= atan2((double)y * y_scale - y_offset,(double)x * x_scale - x_offset)* (180 / 3.14159265) +180; // angle in degrees
#else
angle= atan2((double)y - y_offset,(double)x - x_offset)* (180 / 3.14159265) +180; // angle in degrees
#endif
/*
Refer the following application note for heading calculation.
http://www.ssec.honeywell.com/magnetic/datasheets/lowcost.pdf
----------------------------------------------------------------------------------------
atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point
given by the coordinates (x, y) on it.
----------------------------------------------------------------------------------------
This sketch does not utilize the magnetic component Z as tilt compensation can not be done without an Accelerometer
--------------->y
|
\/
x
N
NW | NE
|
W----------E
|
SW | SE
S
*/
// only print the detail if NOT doing either sending either calibration data set to serial
// #ifndef RAW_DATA_CSV
// #ifndef RAW_DATA_ARRAY
//Print the approximate direction
Serial.print("You are heading ");
if((angle < 22.5) || (angle > 337.5 ))
Serial.print("South");
if((angle > 22.5) && (angle < 67.5 ))
Serial.print("South-West");
if((angle > 67.5) && (angle < 112.5 ))
Serial.print("West");
if((angle > 112.5) && (angle < 157.5 ))
Serial.print("North-West");
if((angle > 157.5) && (angle < 202.5 ))
Serial.print("North");
if((angle > 202.5) && (angle < 247.5 ))
Serial.print("NorthEast");
if((angle > 247.5) && (angle < 292.5 ))
Serial.print("East");
if((angle > 292.5) && (angle < 337.5 ))
Serial.print("SouthEast");
Serial.print(": Angle between X-axis and the South direction ");
if((0 < angle) && (angle < 180) )
{
angle=angle;
}
else
{
angle=360-angle;
}
Serial.print(angle,2);
Serial.println(" Deg");
//#endif
//#endif
delay(100);
}
#include <math.h>
// updates to cope with Arduino V1.0( and newer?) and older versions (22 & lower)
#define I2C_TX write
#define I2C_RX read
//#define SCALE //use this to scale each axis if the test data does not give a circular (spherical 3D) plot
// done as #def for max performance of code not using the scale factors!
// use to switch the serial output data to a CSV format of raw x,y,z data values to help calibrate your compass
#define RAW_DATA_CSV
// ALSO use this #def to format output to easly paste into a data array - eg to display data in Processing. See usabledevices.com for example.
#define RAW_DATA_ARRAY
// Shift the device's documented slave address (0x3C) for write operation
// 1 bit right.This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)
#define HMC5883_WriteAddress 0x1E // i.e 0x3C >> 1
#define HMC5883_ModeRegisterAddress 0x02
#define HMC5883_ContinuousModeCommand (uint8_t)0x00 // cast to uint8_t added to get code to compile under Arduino v1.0
#define HMC5883_DataOutputXMSBAddress 0x03
int regb=0x01;
int regbdata=0x40;
int outputData[6];
// calibrate YOUR compass, so compass raw x,y (,z) data is centered around 0,0,0 axis!
// To do this read do an XY scatter plot for 2D xy data, and just "read"
// work out or guess the offset to center the data (you need to rotate the compass to get lots of data pairs)
// for my compass the values where x=-100, y=-100 (did not work out z axis!)
const int x_offset = 0;
const int y_offset = 0;
const int z_offset = 0;
#ifdef SCALE
const int x_scale = 1;
const int y_scale = 1;
const int z_scale = 1;
#endif
void setup()
{
Serial.begin(9600);
Wire.begin(); //Initiate the Wire library and join the I2C bus as a master
}
void loop() {
int i,x,y,z;
double angle;
Wire.beginTransmission(HMC5883_WriteAddress);
Wire.I2C_TX(regb);
Wire.I2C_TX(regbdata);
Wire.endTransmission();
delay(1000);
Wire.beginTransmission(HMC5883_WriteAddress); //Initiate a transmission with HMC5883 (Write address).
Wire.I2C_TX(HMC5883_ModeRegisterAddress); //Place the Mode Register Address in send-buffer.
Wire.I2C_TX(HMC5883_ContinuousModeCommand); //Place the command for Continuous operation Mode in send-buffer.
Wire.endTransmission(); //Send the send-buffer to HMC5883 and end the I2C transmission.
delay(100);
Wire.beginTransmission(HMC5883_WriteAddress); //Initiate a transmission with HMC5883 (Write address).
Wire.requestFrom(HMC5883_WriteAddress,6); //Request 6 bytes of data from the address specified.
delay(500);
//Read the value of magnetic components X,Y and Z
if(6 <= Wire.available()) // If the number of bytes available for reading be <=6.
{
for(i=0;i<6;i++)
{
outputData[i]=Wire.I2C_RX(); //Store the data in outputData buffer
}
}
x=outputData[0] << 8 | outputData[1]; //Combine MSB and LSB of X Data output register
z=outputData[2] << 8 | outputData[3]; //Combine MSB and LSB of Z Data output register
y=outputData[4] << 8 | outputData[5]; //Combine MSB and LSB of Y Data output register
#ifdef SCALE
angle= atan2((double)y * y_scale - y_offset,(double)x * x_scale - x_offset)* (180 / 3.14159265) +180; // angle in degrees
#else
angle= atan2((double)y - y_offset,(double)x - x_offset)* (180 / 3.14159265) +180; // angle in degrees
#endif
/*
Refer the following application note for heading calculation.
http://www.ssec.honeywell.com/magnetic/datasheets/lowcost.pdf
----------------------------------------------------------------------------------------
atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point
given by the coordinates (x, y) on it.
----------------------------------------------------------------------------------------
This sketch does not utilize the magnetic component Z as tilt compensation can not be done without an Accelerometer
--------------->y
|
\/
x
N
NW | NE
|
W----------E
|
SW | SE
S
*/
// only print the detail if NOT doing either sending either calibration data set to serial
// #ifndef RAW_DATA_CSV
// #ifndef RAW_DATA_ARRAY
//Print the approximate direction
Serial.print("You are heading ");
if((angle < 22.5) || (angle > 337.5 ))
Serial.print("South");
if((angle > 22.5) && (angle < 67.5 ))
Serial.print("South-West");
if((angle > 67.5) && (angle < 112.5 ))
Serial.print("West");
if((angle > 112.5) && (angle < 157.5 ))
Serial.print("North-West");
if((angle > 157.5) && (angle < 202.5 ))
Serial.print("North");
if((angle > 202.5) && (angle < 247.5 ))
Serial.print("NorthEast");
if((angle > 247.5) && (angle < 292.5 ))
Serial.print("East");
if((angle > 292.5) && (angle < 337.5 ))
Serial.print("SouthEast");
Serial.print(": Angle between X-axis and the South direction ");
if((0 < angle) && (angle < 180) )
{
angle=angle;
}
else
{
angle=360-angle;
}
Serial.print(angle,2);
Serial.println(" Deg");
//#endif
//#endif
delay(100);
}
Eng Ing Eng
Ketemulah seperti diatas, berarti dugaan nya terbukti semua. So kalau sobat punya DJI sensor kompasnya tidak bekerja, bisa pake modul gy271 - gy273 (itu kalau sobat pengen terlihat DJI Phantomnya terlihat gak standart) :)
Selamat Mencoba
Demikianlah Artikel Sensor Kompas DJI Phantom (Edisi Memanfaatkan Bekas Repair DJI Phantom)
Sekianlah artikel Sensor Kompas DJI Phantom (Edisi Memanfaatkan Bekas Repair DJI Phantom) kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel Sensor Kompas DJI Phantom (Edisi Memanfaatkan Bekas Repair DJI Phantom) dengan alamat link https://arduinolibs.blogspot.com/2018/02/sensor-kompas-dji-phantom-edisi.html
0 Response to "Sensor Kompas DJI Phantom (Edisi Memanfaatkan Bekas Repair DJI Phantom)"
Post a Comment