|
楼主 |
发表于 2020-12-25 12:01:07
|
显示全部楼层
- /*
- 【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
- 实验一百五十二:GY-25 串口直接输出角度数据 倾斜度角度传感器模块 MPU-6050
- 使用步骤:
- 1.先下载GY25_uart程序至arduino
- 2.再接上GY25模块
- 3.按复位按键
- 4.打开串口,波特率115200
- 5、接线
- GY25 arduino uno
- VCC----------------------VCC
- RX-----------------------TX
- TX-----------------------RX
- GND----------------------GND
- ---------------------------------------
- IICLCD2004 arduino uno
- VCC----------------------VCC
- SCL----------------------A5
- SDA----------------------A4
- GND----------------------GND
- 实验之二:IICLCD2004显示动态角度数值
- */
- #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(0x27, 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;
- }
- }
- }
复制代码 |
|