0

这是我的代码:

#include <Wire.h>
#include <I2Cdev.h>
#include <HMC5883L.h>
#include <MPU6050.h>

#include "Arduino.h"
void setup();
void loop();

MPU6050 accelgyro;
HMC5883L mag;

int16_t mx, my, mz;

void setup() {
    Wire.begin();
    accelgyro.initialize();
    accelgyro.setI2CBypassEnabled(true);
    Serial.begin(9600);

    // initialize device
    Serial.println("Initializing I2C devices...");
    mag.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(mag.testConnection() ? "HMC5883L connection successful" : "HMC5883L connection failed");

}

void loop() {
    mag.getHeading(&mx, &my, &mz);

    Serial.print("mag:\t");
    Serial.print(mx); Serial.print("\t");
    Serial.print(my); Serial.print("\t");
    Serial.print(mz); Serial.print("\t");

    float heading = atan2(my, mx);
    if(heading < 0)
    heading += 2 * M_PI;
    Serial.print("heading:\t");
    Serial.println(heading * 180/M_PI);

}

它可以在 Arduino IDE 上运行。这是 Atmel Studio 6 中的警告(2 个未初始化的警告和 4 个由 I2Cdev 库生成的警告),没有错误。

warning 5   **'progBuffer' may be used uninitialized in this function [-Wuninitialized]**   D:/Program Files (x86)/Arduino/libraries/MPU6050/MPU6050.cpp    2971    14  HMC
warning 6   **'progBuffer' may be used uninitialized in this function [-Wuninitialized]**   D:/Program Files (x86)/Arduino/libraries/MPU6050/MPU6050.cpp    3076    101 HMC
warning 4   **#warning - Timeout detection (some Wire requests block forever) [-Wcpp]** D:/Program Files (x86)/Arduino/libraries/I2Cdev/I2Cdev.cpp  67  14  HMC
warning 2   **#warning Arduino IDE v1.0.1+ with I2CDEV_BUILTIN_FASTWIRE implementation is recommended. [-Wcpp]**    D:/Program Files (x86)/Arduino/libraries/I2Cdev/I2Cdev.cpp  65  14  HMC
warning 3   **#warning This I2Cdev implementation does not support: [-Wcpp]**   D:/Program Files (x86)/Arduino/libraries/I2Cdev/I2Cdev.cpp  66  14  HMC
warning 1   **#warning Using current Arduino IDE with Wire library is functionally limiting. [-Wcpp]**  D:/Program Files (x86)/Arduino/libraries/I2Cdev/I2Cdev.cpp  64  14  HMC

这是输出:

collect2: ld returned 1 exit status
make: *** [HMC.elf] Error 1

谁能帮我?非常感谢!!

4

1 回答 1

0

从警告中,我假设编译器告诉您某些代码/库在您使用的环境中不可用。所以发生的情况是代码编译正常,但链接器失败,因为它找不到相应的静态库。

因此,如果it can work on Arduino IDE,请坚持下去(除非有某些原因您没有告诉我们)。

你确定你没有更多的链接器错误吗?也许这些记录在某个文件中,检查一下。

于 2014-09-29T07:06:09.360 回答