纸染 2023-03-25 23:17 采纳率: 75%
浏览 16
已结题

关于在arduino中编译现成程序失败的

求帮忙,在arduino中编译一个现成的程序,在库文件安装完成的情况下,编译报错


```c

//B站找 :arduino捣鼓室 欢迎大家评论区一起交流!如有不足请大家指正 共同进步!网址:https://space.bilibili.com/307396549
//根据需要下载要的库 可以根据编译查看结果
//所有的库打包在这个连接下方 https://www.bilibili.com/video/BV1r34y147SL?spm_id_from=333.999.0.0



#include <esp_now.h>
#include <WiFi.h>

//需要的安装库
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

#include "Wire.h"
#endif

// MPU control/status vars
MPU6050 mpu;
bool dmpReady = false;   //
uint8_t devStatus;       //
uint8_t fifoBuffer[64];  //
Quaternion q;            // [w, x, y, z]
VectorFloat gravity;     // [x, y, z]
float ypr[3];            // [yaw, pitch, roll]

// 记录MAC地址 // E0:5A:1B:75:36:6C

uint8_t receiverMacAddress[] = { 0xE0, 0x5A, 0x1B, 0x75, 0x36, 0x6C };

struct PacketData {
  byte xAxisValue;
  byte yAxisValue;
  byte zAxisValue;
};
PacketData data;

// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  //Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Message sent" : "Message failed");
}

void setupMPU() {
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
  Wire.begin();
  Wire.setClock(400000);  // 400kHz I2C clock. Comment this line if having compilation difficulties
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
  Fastwire::setup(400, true);
#endif

  mpu.initialize();
  devStatus = mpu.dmpInitialize();
  // make sure it worked (returns 0 if so)
  if (devStatus == 0) {
    // Calibration Time: generate offsets and calibrate our MPU6050
    mpu.CalibrateAccel(6);
    mpu.CalibrateGyro(6);
    mpu.setDMPEnabled(true);
    dmpReady = true;
  }
}

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  } else {
    Serial.println("Succes: Initialized ESP-NOW");
  }

  esp_now_register_send_cb(OnDataSent);

  // Register peer
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, receiverMacAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // Add peer
  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Failed to add peer");
    return;
  } else {
    Serial.println("Succes: Added peer");
  }

  //This is to set up MPU6050 sensor
  setupMPU();
}

void loop() {
  // if programming failed, don't try to do anything
  if (!dmpReady) return;
  // read a packet from FIFO. Get the Latest packet
  if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) {
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

    int xAxisValue = constrain(ypr[2] * 180 / M_PI, -90, 90);
    int yAxisValue = constrain(ypr[1] * 180 / M_PI, -90, 90);
    int zAxisValue = constrain(ypr[0] * 180 / M_PI, -90, 90);
    data.xAxisValue = map(xAxisValue, -90, 90, 0, 254);
    data.yAxisValue = map(yAxisValue, -90, 90, 0, 254);
    data.zAxisValue = map(zAxisValue, -90, 90, 0, 254);

    esp_err_t result = esp_now_send(receiverMacAddress, (uint8_t *)&data, sizeof(data));

    String inputData = inputData + "values " + xAxisValue + "  " + yAxisValue + "  " + zAxisValue;
    Serial.println(inputData);
    delay(50);
  }
}

![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/470373757976136.png "#left")


```

  • 写回答

2条回答 默认 最新

  • IT_service_mesh 2023-03-25 23:21
    关注

    参考GPT和自己的思路:根据你提供的代码,我们可以看到该程序使用了多个库文件,包括 "I2Cdev.h", "MPU6050_6Axis_MotionApps20.h" 和 "esp_now.h"。编译报错可能涉及到这些库文件的安装或者使用方式。

    建议你仔细检查这些库文件是否正确安装,包括库文件的路径和命名等,如果有问题建议重新安装库文件或者更新库文件版本。另外,如果编译报错信息具体,请提供报错信息,以便更好地解决问题。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月5日
  • 已采纳回答 3月28日
  • 创建了问题 3月25日

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)