در این پست قصد داریم راه اندازی قطب نما ی سه محوره به کمک آردوئینو را به شما آموزش دهیم کدهای برنامه را هم برای راحتی حالتون در پایان همین مطلب در اختیارتون گذاشتیم تا دیگه به راحیتی برین برای ساخت پروژه مورد نظرتون پس با ما همراه باشید…
HMC5883 محصول Honeywell يك قطب نماي 3 محوره ديجيتال است كه ميتواند شدت ميدان مغناطيسي تا 8± گاوس را با دقت 5 ميلي گاوس اندازه گيري نمايد. توسط اين ماژول ميتوان به دقت 1 تا 2 درجه در جهت يابي و ناوبري رسيد. اين ماژول از طريق رابط I2C به میکروکنترلر متصل ميشود. ولتاژ تغذيه اين ماژول 2.16 تا 3.6 ولت ميباشد. جريان مصرفي HMC5883 تنها 100 ميكرو آمپر مي باشد.
خصوصيات:
- ADC داخلي 12 بيتي
- ولتاژ کار: 2.16 تا 3.6 ولت
- برقراري ارتباط با رابط I2C
- جريان مصرفي 100 ميكرو آمپر
- اندازه گيري ميدان مغناطيسي تا 8± گاوس را با دقت 5 ميلي گاوس
- قابليت دريافت اطلاعات سنسور تا 160 بار در ثانيه
كاربردها:
- ساخت قطب نماي ديجيتال
- استفاده در تلفن همراه و لپتاپ به عنوان قطب نما
- ساخت سيستم ناوبري اتوماتيك
- استفاده در سيستم جهت يابي ربات
نحوه اتصال به برد آردوینو

شماتیک ماژول قطب نمای الکترونیکی سه محوره GY-271 HMC5883L
کد راه اندازی قطب نمای الکترونیکی سه محوره GY-271 HMC5883L با آردوینو
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 |
#define HMC5883_WriteAddress 0x1E // i.e 0x3C >> 1 #define HMC5883_ModeRegisterAddress 0x02 #define HMC5883_ContinuousModeCommand 0x00 #define HMC5883_DataOutputXMSBAddress 0x03 int regb=0x01; int regbdata=0x40; int outputData[6]; 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.send(regb); Wire.send(regbdata); Wire.endTransmission(); delay(1000); Wire.beginTransmission(HMC5883_WriteAddress); //Initiate a transmission with HMC5883 (Write address). Wire.send(HMC5883_ModeRegisterAddress); //Place the Mode Register Address in send-buffer. Wire.send(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=Wire.receive(); //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 angle= atan2((double)y,(double)x) * (180 / 3.14159265) + 180; // angle in degrees /* 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 */ //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"); delay(100); } |
خب این مطلب هم به پایان رسید امیدوارم براتون مفید بوده باشه و لذت کافی رو از خوندن این پست برده باشید منتظر نظارت شما هستیم باتشکر…