|
給大家點好東西 ,這個資料挺不錯的,GY-25傾斜度角度模塊 串口直接輸出角度數據 MPU-6050模塊 傳感器.rar 就和大家分享下
0.png (47.98 KB, 下載次數: 174)
下載附件
2016-6-1 14:24 上傳
51單片機程序:
arduino程序:
- //GY-25 ARDUINO 測試代碼 IICLCD2004顯示角度
- //注意1:下載程序時候,請先斷開GY25的連線!否則將導致下載不成功
- //注意2:GY25模塊使用時,上電自校正,建議不要用手拿著模塊,
- // 保持3秒以上靜止狀態,才能發送命令開始工作
- // GY25 arduino pro mini
- // VCC----------------------VCC
- // RX-----------------------TX
- // TX-----------------------RX
- // GND----------------------GND
- //-----------------------------------------------
- // IICLCD2004 arduino pro mini
- // VCC----------------------VCC
- // SCL----------------------A5
- // SDA----------------------A4
- // GND----------------------GND
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- int YPR[3];
- unsigned char Re_buf[8],counter=0;
- unsigned char sign=0;
- int led = 13;
- LiquidCrystal_I2C lcd(0x20,20,4); // set the LCD address to 0x20 for a 20 chars and 4 line display
- //-----------------------------------------------------------
- void setup()
- {
- lcd.init(); // initialize the lcd
- // Print a message to the LCD.
- Serial.begin(115200);
- delay(2000);
- Serial.write(0XA5);
- Serial.write(0X52); //初始化GY25,連續輸出模式
- lcd.backlight();
- lcd.setCursor(0,0); //I2C接口LCD2004顯示初始值
- lcd.print("Yaw:");
- lcd.setCursor(0,1);
- lcd.print("Pitch:");
- lcd.setCursor(0,2);
- lcd.print("Roll:");
- }
- //-------------------------------------------------------------
- void loop() {
- if(sign)
- {
- sign=0;
- if(Re_buf[0]==0xAA && Re_buf[7]==0x55) //檢查幀頭,幀尾
- {
- YPR[0]=(Re_buf[1]<<8|Re_buf[2])/100; //合成數據,去掉小數點后2位
- YPR[1]=(Re_buf[3]<<8|Re_buf[4])/100;
- YPR[2]=(Re_buf[5]<<8|Re_buf[6])/100;
-
- lcd.setCursor(4,0);
- lcd.print(" ");
- lcd.setCursor(4,0);
- lcd.print(YPR[0]); //顯示航向
- lcd.setCursor(6,1);
- lcd.print(" ");
- lcd.setCursor(6,1); //顯示俯仰角
- lcd.print(YPR[1]);
- lcd.setCursor(5,2);
- lcd.print(" ");
- lcd.setCursor(5,2); //顯示橫滾角
- lcd.print(YPR[2]);
- delay(100);
- }
- }
- }
- //---------------------------------------------------------------
- void serialEvent() {
- while (Serial.available()) {
- Re_buf[counter]=(unsigned char)Serial.read();
- if(counter==0&&Re_buf[0]!=0xAA) return; // 檢查幀頭
- counter++;
- if(counter==8) //接收到數據
- {
- counter=0; //重新賦值,準備下一幀數據的接收
- sign=1;
- }
- }
- }
復制代碼
|
評分
-
查看全部評分
|