0

This is my code:

#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);

}

It can work on Arduino IDE. Here are the warnings in Atmel Studio 6 (2 uninitialized warnings and 4 warnings generated by I2Cdev library), no errors.

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

Here is the output:

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

Who can help me? Many Thanks!!

kebs
  • 6,387
  • 4
  • 41
  • 70

1 Answers1

0

From the warnings, I assume that the compiler is telling you that some code/library is unavailable from within the environment you are using. So what happens is that the code compiles ok, but the linker fails, as it can't find the corresponding static libraries.

So if it can work on Arduino IDE, just stick to it (unless there is some reason you didn't tell us about).

Are you sure that you don't have more linker errors ? Maybe these are logged in some file, check it out.

kebs
  • 6,387
  • 4
  • 41
  • 70
  • Hi, Thanks for answering! actually the only problem is this error1, it didn't give me any other problems or errors. The reason why I want to use AS6 is that I need to use freeRTOS for atMega 2560 and I didn't find a good version for Arduino IDE, Do you have any good ideas? Thanks a lt! – deciding Sep 29 '14 at 09:09
  • Not more than what I have posted in my answer: in order to track down the problem, you need to find the linkers error message. Without this, I don't see how your question can be answered. – kebs Sep 29 '14 at 15:37