Community
cancel
Showing results for 
Search instead for 
Did you mean: 
AGUIM2
New Contributor I
1,142 Views

How to solve mraa multiple definitions error?

Hi all,

I use Edison with Arduino Board and I'm developing a project in c++ with Eclipse. But, as I have more than one file I've a problem to share mraa object between my files. I've declare my pins to drive a stepper motor in my .hpp file (Header.hpp) as below:

# ifndef HEADER_HPP_

# define HEADER_HPP

.....................................................

...................code.................................

.....................................................

mraa_gpio_context pin_5;

mraa_gpio_context pin_7;

mraa_aio_context pin_A2;

mraa_gpio_context pin_3;

mraa_gpio_context pin_11;

..................................................

......................................

.............................................

# endif /* HEADER_HPP_ */

So, i've # include it in my .cpp files were I want to define an check them. But after debug I've the follow errors:

multiple definition of pin_5

multiple definition of pin_7

multiple definition of pin_A2

multiple definition of pin_3

multiple definition of pin_11

Someone can tell me what have I done wrong and how can I do to solve this problem?

Thanks

4 Replies
idata
Community Manager
66 Views

Hello Guimficus,

 

 

This issue usually happens when you declare variables more than once in your code. I ran an example following your configuration to see if I got the same results as you, however I was not able to do so. Could you share your .cpp and your .hpp to see if we can find what's causing the issue?

 

 

Peter.
AGUIM2
New Contributor I
66 Views

Hello Peter,

Thanks to help me. I think you've right about the cause of this problem, but I don't know how to solve it. I'm just starting with the mraa library. Here are the contain of my files. Sorry but there is no icon to join my files, so I've just copy them. You can give me your email if you really want the files.

**********main file: Soft_Edison.cpp***************

# include

# include "Header.hpp"

# include "Stepper.hpp"

using namespace std;

int main() {

/* Setup your example here, code that should run once

*/

initialisation();

moteurMarche();

/* Code in this loop will run repeatedly

*/

for (;;) {

sensTrigo();

}

return 0;

}

***************Stepper.hpp*****************

/*

* Stepper.hpp

*

* Created on: 18 avr. 2016

* Author: Utilisateur

*/

# ifndef STEPPER_HPP_

# define STEPPER_HPP_

# include "mraa.hpp"

mraa_gpio_context motpin_1;

mraa_gpio_context motpin_2;

// library interface description

class Stepper {

public:

// constructors:

Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2);

// speed setter method:

void setSpeed(long whatSpeed);

// mover method:

void step(int number_of_steps);

private:

void stepMotor(int this_step);

int direction; // Direction of rotation

unsigned long step_delay; // delay between steps, in ms, based on speed

int number_of_steps; // total number of steps this motor can take

int step_number; // which step the motor is on

// motor pin numbers:

int motor_pin_1;

int motor_pin_2;

unsigned long last_step_time; // time stamp in us of when the last step was taken

};

# endif /* STEPPER_HPP_ */

*********************Header.hpp******************************************

/*

* Header.hpp

*

* Created on: 18 avr. 2016

* Author: Utilisateur

*/

# ifndef HEADER_HPP_

# define HEADER_HPP_

# include "mraa.hpp"

//mode debug

# define debug true;

//--------------------------------------------------------------------------------//

// Etats des broches //

//--------------------------------------------------------------------------------//

# define HIGH true

# define LOW false

//Define output

# define CTRLPIN_A 3 // Enable (PWM)A on Motor Control Shield

# define CTRLPIN_B 11 // Enable (PWM)B on Motor Control Shield

# define dirA 12 // Direction pin dirA on Motor Control Shield

# define dirB 13 // Direction pin dirB on Motor Control Shield

//Define constantes moteur

# define MOT_ZERO 14

# define MOT_ERREUR_COURSE 2

# define MOT_COURSE_AGITATION 100

# define direct true;

# define indirect false;

# define capteurPosition1 5

# define capteurPosition2 7

//Tête optique

# define capteurOptique 2

//Broche de remise à zéro du moteur

# define RESETLINE 4 // Change this if you are not using an Arduino Adaptor Shield R3

//--------------------------------------------------------------------------------//

// Hardware resources allocation //

//--------------------------------------------------------------------------------//

mraa_gpio_context pin_5;

mraa_gpio_context pin_7;

mraa_aio_context pin_A2;

mraa_gpio_context pin_3;

mraa_gpio_context pin_11;

// Fonction inclu dans init.cpp

void initialisation(void);

# endif /* HEADER_HPP_ */

*******************Init.cpp*********************************

/*

* Init.cpp

*

* Created on: 18 avr. 2016

* Author: Utilisateur

*/

# include "Header.hpp"

# include "mraa.hpp"

void initialisation(void)

{

//Serial.begin(115200);

//Serial1.begin(115200); // serial1 to communicate with the screen

mraa_init();

pin_5 = mraa_gpio_init(capteurPosition1);

pin_7 = mraa_gpio_init(capteurPosition2);

pin_A2 = mraa_aio_init(capteurOptique);

pin_3 = mraa_gpio_init(CTRLPIN_A);

pin_11 = mraa_gpio_init(CTRLPIN_B);

mraa_gpio_dir(pin_5, MRAA_GPIO_IN);

mraa_gpio_mode(pin_5, MRAA_GPIO_PULLUP);

mraa_gpio_dir(pin_7, MRAA_GPIO_IN);

mraa_gpio_mode(pin_7, MRAA_GPIO_PULLUP);

mraa_gpio_dir(pin_3, MRAA_GPIO_OUT);

mraa_gpio_dir(pin_11, MRAA_GPIO_OUT);

return;

}

********************Stepper.cpp**********************************

//

# include "Header.hpp"

# include "Stepper.hpp"

# include // for clock

clock_t t1;

Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)

{

this->step_delay = 0; //delay between steps, in ms

this->step_number = 0; // which step the motor is on

this->direction = 0; // motor direction

this->last_step_time = 0; // time stamp in us of the last step taken

this->number_of_steps = number_of_steps; // total number of steps for this motor

// Arduino pins for the motor control connection:

this->motor_pin_1 = motor_pin_1;

this->motor_pin_2 = motor_pin_2;

// setup the pins on the microcontroller:

motpin_1 = mraa_gpio_init(motor_pin...

idata
Community Manager
66 Views

Are these files the latest versions, you are currently using? I'm encountering different issues from what you described, that's why I ask.

 

Do you receive any error messages regarding motpin_1 and motpin_2? I managed to "solve" them but I would like to know if you've made any modifications.

 

 

Peter.
AGUIM2
New Contributor I
66 Views

Yes, the are the lastest versions of my files. Fortunately, I've been able to solve this problem: a I've declared the motor pins in an other hpp file and I've included it only in one cpp file.

Thank you for your help!

Guimficus.

Reply