|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 tgjohn 于 2022-7-14 07:06 编辑
主控还是esp8266,陀螺仪选mpu6050
引脚连线图
VCC VU (5V USB) Not available on all boards so use 3.3V if needed.
GND G Ground
SCL D1 (GPIO05) I2C clock
SDA D2 (GPIO04) I2C data
代码直接贴,代码里舵机接io2
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include <Servo.h>
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
//#define LED_PIN 13
//bool blinkState = false;
Servo sg90;
int servo_pin = 2;
void setup() {
sg90.attach ( servo_pin );
Wire.begin();
Serial.begin(115200);
Serial.println("Initializing I2C devices...");
mpu.initialize();
Serial.println("Testing device connections...");
Serial.println(mpu.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
//accelgyro.getAcceleration(&ax, &ay, &az);
//accelgyro.getRotation(&gx, &gy, &gz);
ax = map (ax, -17000, 17000, 5, 180) ;
ay = map (ay, -17000, 17000, 0, 120) ;
az = map (az, -17000, 17000, 5, 180) ;
/* Serial.print("a/g:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);*/
Serial.println (ax);
sg90.write (ax);
// delay(50);
}
补充内容 (2023-2-23 14:43):
群号209845016 |
| |