This is the 9DOF (Degrees Of Freedom) IMU (Inertial Measurement Unit) module that has 3 integrated sensor in one module board the ITG-3200 (Triple Axis Digital Output Gyroscope), ADXL345 (13bit Resolution ±16g Triple Axis Accelerometer), HMC5883L (Triple Axis, Digital Magnetometer) that provide you’re a 9 degrees of inertial measurement. The output of the sensors are process by the microcontroller. This enable the 9DOF module to be used as control mechanism like UAV (Autonomous Vehicles), Image stabilization system, or control mechanism. Some of board designs comes with programmed with 8MHz bootloader (STK500V1) that demonstration of the output of all the sensor just simply connect to the serial TX and RX pins with your USB TTL then open your Serial Terminal that runs at 57600bps.
Required Components
- Arduino Microcontroller, TEENSY, ATMEGA328 16/12, ATMEGA32u4 16/8/ MHz, ESP8266, ATMEGA250 16 MHz, ATSAM3x8E, ATSAM21D, ATTINY85 16/8 MHz
- ITG3200 / ADX345 /HMC5883L 9DOF/ GY-85 6DOF / GY-85 9DUP IMU Module
- USB TTL / UART FTDI (Optional)
- Bluetooth Module (Optional)
- Solder Less Bread Board
- Jumper Wire / DuPont Wire
Wiring Guide for SPI / i2C
Schematics Diagram and Pin-outs
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
#include <Wire.h> #include <ADXL345.h> // ADXL345 Accelerometer Library #include <HMC5883L.h> // HMC5883L Magnetometer Library #include <ITG3200.h> // ITG3200 GYRO Library ADXL345 acc; //variable adxl is an instance of the ADXL345 library HMC5883L compass; ITG3200 gyro = ITG3200(); float gx,gy,gz; float gx_rate, gy_rate, gz_rate; int ix, iy, iz; float anglegx=0.0, anglegy=0.0, anglegz=0.0; int ax,ay,az; int rawX, rawY, rawZ; float X, Y, Z; float rollrad, pitchrad; float rolldeg, pitchdeg; int error = 0; float aoffsetX, aoffsetY, aoffsetZ; float goffsetX, goffsetY, goffsetZ; unsigned long time, looptime; void setup(){ Serial.begin(9600); Serial.println("14CORE | ADX/HMC/ITG Test Code"); Serial.println("==============================="); Serial.println("Starting ....") Serial.println("") } acc.powerOn(); compass = HMC5883L(); error = compass.SetScale(1.3); // Set the scale to +/- 1.3 Ga of the compass if(error != 0) // If there is an error, print it out. Serial.println(compass.GetErrorText(error)); // Serial.println("Setting measurement mode to continous"); error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous if(error != 0) // If there is an error, print it out. Serial.println(compass.GetErrorText(error)); for (int i = 0; i <= 200; i++) { acc.readAccel(&ax, &ay, &az); if (i == 0) { aoffsetX = ax; aoffsetY = ay; aoffsetZ = az; } if (i > 1) { aoffsetX = (ax + aoffsetX) / 2; aoffsetY = (ay + aoffsetY) / 2; aoffsetZ = (az + aoffsetZ) / 2; } } for (int i = 0; i <= 200; i++) { gyro.readGyro(&gx,&gy,&gz); if (i == 0) { goffsetX = gx; goffsetY = gy; goffsetZ = gz; } if (i > 1) { goffsetX = (gx + goffsetX) / 2; goffsetY = (gy + goffsetY) / 2; goffsetZ = (gz + goffsetZ) / 2; } } delay(1000); gyro.init(ITG3200_ADDR_AD0_LOW); // Serial.print("zero Calibrating..."); // gyro.zeroCalibrate(2500, 2); // Serial.println("done."); } void loop(){ // code fragment for Accelerometer angles (roll and pitch) time = millis(); acc.readAccel(&ax, &ay, &az); //read the accelerometer values and store them in variables x,y,z rawX = ax - aoffsetX; rawY = ay - aoffsetY; rawZ = az - (255 - aoffsetZ); X = rawX/256.00; // used for angle calculations Y = rawY/256.00; // used for angle calculations Z = rawZ/256.00; // used for angle calculations rollrad = atan(Y/sqrt(X*X+Z*Z)); // calculated angle in radians pitchrad = atan(X/sqrt(Y*Y+Z*Z)); // calculated angle in radians rolldeg = 180*(atan(Y/sqrt(X*X+Z*Z)))/PI; // calculated angle in degrees pitchdeg = 180*(atan(X/sqrt(Y*Y+Z*Z)))/PI; // calculated angle in degrees // Code fragment for Magnetometer heading (yaw) MagnetometerRaw raw = compass.ReadRawAxis(); MagnetometerScaled scaled = compass.ReadScaledAxis(); int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis) float heading = atan2(scaled.YAxis, scaled.XAxis); float declinationAngle = 0.0457; heading += declinationAngle; if(heading < 0) heading += 2*PI; if(heading > 2*PI) heading -= 2*PI; float headingDegrees = heading * 180/M_PI; // Code fragment for Gyroscope (roll, pitch, yaw) gyro.readGyro(&gx,&gy,&gz); looptime = millis() - time; gx_rate = (gx-goffsetX) / 14.375; gy_rate = (gy-goffsetY) / 14.375; gz_rate = (gz-goffsetZ) / 14.375; delay(100); /* Serial.print(gx_rate); // calculated angle in degrees Serial.print(","); Serial.print(gy_rate); Serial.print(","); Serial.print(gz_rate); Serial.println(","); */ anglegx = anglegx + (gx_rate * looptime); anglegy = anglegy + (gx_rate * looptime); anglegz = anglegz + (gz_rate * looptime); // Accelerometer, Magnetometer and Gyroscope Output Serial.print(rolldeg); Serial.print(","); Serial.print(pitchdeg); // calculated angle in degrees Serial.print(","); Serial.print(headingDegrees); Serial.println(","); //Serial.print(anglegx); // Serial.print(","); //Serial.print(anglegy); //Serial.print(","); //Serial.println(anglegz); //Serial.println(looptime); //Output(raw, scaled, heading, headingDegrees); } void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees) { Serial.print("Raw:\t"); Serial.print(raw.XAxis); Serial.print(" "); Serial.print(raw.YAxis); Serial.print(" "); Serial.print(raw.ZAxis); Serial.print(" \tScaled:\t"); Serial.print(scaled.XAxis); Serial.print(" "); Serial.print(scaled.YAxis); Serial.print(" "); Serial.print(scaled.ZAxis); Serial.print(" \tHeading:\t"); Serial.print(heading); Serial.print(" Radians \t"); } |
Downloads
- ITG3200 Code Libraries | ZIP
- ADXL345 Code Libraries | ZIP
- HMC5883L Code Libraries | ZIP
- RAZOR AHRH Test Code | ZIP
- ITG3200 Datasheet Manual | PDF
- ADXL345 Datasheet Manual | PDF
- HMC5883L Datasheet Manual | PDF
감사 합니다, 기사 도와, 여전히 디지털 핀 문제가 >”<