Pages: [1]   Go Down
Author Topic: undefined setup() and loop() even though these are defined  (Read 700 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Working on a project that involves i2c devices:
-8 MPU6050 gyro/accelerometers from Invensense
-SDA and SCL lines multiplexed via two separate multiplexers
-i2cDevLib for C++ classes to control the MPU6050s (https://github.com/jrowberg/i2cdevlib/tree/master/Arduino)
-Arduino 1.0.1 on a linux 3.6.5 kernel

I've written a class file (MpuSensor.cpp) that has an MPU6050 object and performs some operations on the data it receives (integration, kalman filtering, and quaternion math). This class isn't complete yet, but the methods inside it have worked separately as functions in a basic ino file, and there is enough of it written that it should compile so far as I can tell.

When I try to compile the file MpuSensor.ino I get the following errors in Arduino's main.cpp:
undefined reference to setup()
undefined reference to loop()

despite these functions being defined in my ino file.

Can anyone help? Why aren't these functions being linked during compilation?

The code I'm using is attached.
MpuSensor.ino
MpuSensor.h
MpuSensor.cpp
Kalman.h - 3rd party class file for kalman filtering (works)

* MpuSensor.ino (2.28 KB - downloaded 13 times.)
* MpuSensor.h (1.78 KB - downloaded 14 times.)
* MpuSensor.cpp (3.22 KB - downloaded 17 times.)
* Kalman.h (3.3 KB - downloaded 18 times.)
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11672
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One thing, for some odd reason the Arduino compilation system seems to require _all_ of the library .h files to be included at top level in the .ino file (or at least this has seemed necessary for me).  kalman.h isn't mentioned in MpuSensor.ino.

Did you post the complete set of compiler error messages?
Logged

[ I won't respond to messages, use the forum please ]

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You shouldn't name your .ino file the same as a .cpp file in the same project. The .ino file is converted into a .cpp file before compiling and so you get a conflict.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Changing the ino file name worked. It is also true that all of the header files need to be declared in the scope of that ino file. Thanks a bunch folks.
Logged

Scottsdale
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Funny, I had the same problem a few months ago. It took me about 3 or 4 hours of trying to solve the issue before I finally decided to post a question on the forum. Go figure!

Zachary
Logged

RadarProject - Arduino Autopilot for RC http://radarproject.wordpress.com/

Pages: [1]   Go Up
Jump to: