【问题标题】:How do I remove this library error in Arduino IDE?如何在 Arduino IDE 中删除此库错误?
【发布时间】:2018-09-14 09:26:44
【问题描述】:

所以,我使用的是 Raspberry pi 和 Arduino Uno,通过串行通信将它们连接起来。 我通过 python 库 pySerial 接收串行数据到 Rpi。 我已成功接收到 LED 开关动作等一般 I/O 数据。

现在我正在连接一个适用于 I2C 和 SPI 协议的 MPU9250(9 轴罗盘),我从 github 下载了 zip 库。

我知道我可以通过 I2C 通信直接使用 pi 操作传感器,但我想尝试完全使用 Arduino IDE。 我上传到董事会的代码是这样的:

/*
Basic_I2C.ino
Brian R Taylor
brian.taylor@bolderflight.com
Copyright (c) 2017 Bolder Flight Systems
Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
and associated documentation files (the "Software"), to deal in the Software without restriction, 
including without limitation the rights to use, copy, modify, merge, publish, distribute, 
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or 
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "MPU9250.h"

// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
MPU9250 IMU(Wire,0x68);
int status;

void setup() {
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}

  // start communication with IMU 
  status = IMU.begin();
  if (status < 0) {
    Serial.println("IMU initialization unsuccessful");
    Serial.println("Check IMU wiring or try cycling power");
    Serial.print("Status: ");
    Serial.println(status);
    while(1) {}
  }
}

void loop() {
  // read the sensor
  IMU.readSensor();
  // display the data
  Serial.print(IMU.getAccelX_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getAccelY_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getAccelZ_mss(),6);
  Serial.print("\t");
  Serial.print(IMU.getGyroX_rads(),6);
  Serial.print("\t");
  Serial.print(IMU.getGyroY_rads(),6);
  Serial.print("\t");
  Serial.print(IMU.getGyroZ_rads(),6);
  Serial.print("\t");
  Serial.print(IMU.getMagX_uT(),6);
  Serial.print("\t");
  Serial.print(IMU.getMagY_uT(),6);
  Serial.print("\t");
  Serial.print(IMU.getMagZ_uT(),6);
  Serial.print("\t");
  Serial.println(IMU.getTemperature_C(),6);
  delay(100);
}

在这里,我得到了库的成功导入消息,但是当我编译代码时,我得到了这个错误:

MPU9250.h:28:36: fatal error: Wire.h: No such file or directory

即使该文件存在于 zip 文件中并且在库中,我也面临这个问题。谁能帮我这个?您的帮助将不胜感激。 如果您对我提供的任何澄清有任何问题,请告诉我。 此外,我已经在我的窗口中成功编译了库并正确获得了结果。

【问题讨论】:

    标签: arduino arduino-ide


    【解决方案1】:

    您在 Raspberry Pi 上使用了非常过时的 Arduino IDE 版本。这很可能是因为您使用 apt-get 安装了 Arduino IDE。你永远不应该使用包管理器来安装 Arduino IDE,因为这会导致你得到一个过时和/或修改过的软件版本。您应该始终安装从以下位置下载的官方 Arduino IDE:

    https://www.arduino.cc/en/Main/Software

    对于 Raspberry Pi,您需要下载“Linux ARM”。


    如果出于某种原因您绝对要使用这样一个旧的 IDE 版本,则需要将 #include 指令添加到库的所有外部依赖项的草图中。在这种情况下:

    #include <Wire.h>
    

    自您使用的 IDE 版本发布以来的几年中,依赖解析已得到改进,因此不再需要这样做。所以大多数现代 Arduino 草图都不会为这些不必要的 #include 指令而烦恼。


    如果您对为什么包管理器的 IDE 版本已经过时感到好奇:

    https://github.com/arduino/Arduino/pull/2703

    【讨论】:

    • “你永远不应该使用包管理器来安装 Arduino IDE” 这句话是非常错误的。你的包管理器负责所有的依赖和其他东西,所以不要运行它。
    • @hellow 您有权使用已过时 4.5 年的软件。问题是你会要求 Arduino 社区帮助你使现代代码与过时的 IDE 和工具链一起工作,或者处理已经修复的错误。这一切都是因为您太固执而无法简单地下载 IDE。当包得到正确维护时,包管理器工作得很好,但在这种特殊情况下,它根本不可能。所以我们需要适应而不是固执己见。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多