Go Down

Topic: ERROR: core.a(main.cpp.o): In function `main': (Read 2608 times) previous topic - next topic

Martha113

Hey,

I´m an studying art and I´m not totally fit in programming, but I need it for a project. I just try to controll motors and I always get these error-messages:
I´m using a mac, an Arduino mega 2560, quadstepper (sparkfun) and 4 motors. Please help me, thanks, Martha

Error:

core.a(main.cpp.o): In function `main':
/Users/martha/Desktop/Arduino/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:7: undefined reference to `setup'
/Users/martha/Desktop/Arduino/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:10: undefined reference to `loop'

I just took the arduino-library from the sparkfun website: here it is:
by Aaron Weiss

  Motor1 STP pin: mega pin 11
  Motor2 STP pin: meag pin 5
  Motor3 STP pin: meag pin 6
  Motor4 STP pin: mega pin 46
 
  Library Usage:
 
  motor_pins(x,y,z,l,m,n)
  x: motor channel number
  y: enable pin assignment
  z: direction pin assignment
  l: MS1 pin assignment
  m: MS2 pin assignment
  n: MS3 pin assignment
 
  motor_go(x,y,z,l)
  x: motor channel number
  y: step size: 1, 2, 4, 8, or 16
  z: increments for given step size
     for full step: 1 increment = 1.8deg
     for half step: 1 increment = 0.9deg and so on
     negaitve numbers rotate in the opposite direction
  l: torque/speed (0-10), 0 is high speed/low torque/low current
                          10 is low speed/high torque/high current (2.0A max)
                     
  stall(x)
  x: motor channel number
*/

// include the motor library
#include <quadstep.h>

// create an instance of the class motor
quadstep quadstep;

void setup() {
 
  // assign the pin connections
  quadstep.motor_pins(1,A1,36,A8,A9,A10); //ch 1
  quadstep.motor_pins(2,10,9,8,7,4);      //ch 2
  quadstep.motor_pins(3,22,23,24,25,26);  //ch 3
  quadstep.motor_pins(4,27,28,29,30,31);  //ch 4

}

//1.8deg = 1step
void loop() {
 
  // step motor 4 for 200 increments CW
  quadstep.motor_go(2,1,-200,2);
  delay(500);
´  // step motor 4 for 200 increments CCW
  quadstep.motor_go(2,1,200,2);
  delay(500);

  // holds the motor in one position with full torque/current
  //motor.stall(4);
  //delay(500);
}

Martha113

sorry, maybe this is better to read....

Code: [Select]

  Motor1 STP pin: mega pin 11
  Motor2 STP pin: meag pin 5
  Motor3 STP pin: meag pin 6
  Motor4 STP pin: mega pin 46
 
  Library Usage:
 
  motor_pins(x,y,z,l,m,n)
  x: motor channel number
  y: enable pin assignment
  z: direction pin assignment
  l: MS1 pin assignment
  m: MS2 pin assignment
  n: MS3 pin assignment
 
  motor_go(x,y,z,l)
  x: motor channel number
  y: step size: 1, 2, 4, 8, or 16
  z: increments for given step size
     for full step: 1 increment = 1.8deg
     for half step: 1 increment = 0.9deg and so on
     negaitve numbers rotate in the opposite direction
  l: torque/speed (0-10), 0 is high speed/low torque/low current
                          10 is low speed/high torque/high current (2.0A max)
                     
  stall(x)
  x: motor channel number
*/

// include the motor library
#include <quadstep.h>

// create an instance of the class motor
quadstep quadstep;

void setup() {
 
  // assign the pin connections
  quadstep.motor_pins(1,A1,36,A8,A9,A10); //ch 1
  quadstep.motor_pins(2,10,9,8,7,4);      //ch 2
  quadstep.motor_pins(3,22,23,24,25,26);  //ch 3
  quadstep.motor_pins(4,27,28,29,30,31);  //ch 4

}

//1.8deg = 1step
void loop() {
 
  // step motor 4 for 200 increments CW
  quadstep.motor_go(2,1,-200,2);
  delay(500);
´  // step motor 4 for 200 increments CCW
  quadstep.motor_go(2,1,200,2);
  delay(500);

  // holds the motor in one position with full torque/current
  //motor.stall(4);
  //delay(500);
}

PaulS

You are missing a /* at the start of the comment block.

You have a stray character in front of a comment in loop.

Fixing those two issues, the code almost compiles for me, except that I don't have quadstep.h to include.

Martha113

hej, I tried fix it, but there is still the old error.
I tried to delete every comment, but I always get the same error? Do you know what´s wrong? Please help me with the problem, I don´t find the mistake! Thanks, martha

Code: [Select]
core.a(main.cpp.o): In function `main':
/Users/martha/Desktop/Arduino/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:7: undefined reference to `setup'
/Users/martha/Desktop/Arduino/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:10: undefined reference to `loop'


Code: [Select]
/*
 Motor1 STP pin: mega pin 11
 Motor2 STP pin: meag pin 5
 Motor3 STP pin: meag pin 6
 Motor4 STP pin: mega pin 46
 
 Library Usage:
 
 motor_pins(x,y,z,l,m,n)
 x: motor channel number
 y: enable pin assignment
 z: direction pin assignment
 l: MS1 pin assignment
 m: MS2 pin assignment
 n: MS3 pin assignment
 
 motor_go(x,y,z,l)
 x: motor channel number
 y: step size: 1, 2, 4, 8, or 16
 z: increments for given step size
    for full step: 1 increment = 1.8deg
    for half step: 1 increment = 0.9deg and so on
    negaitve numbers rotate in the opposite direction
 l: torque/speed (0-10), 0 is high speed/low torque/low current
                         10 is low speed/high torque/high current (2.0A max)
                     
 stall(x)
 x: motor channel number
*/

#include <quadstep.h>

quadstep quadstep;

void setup() {
 
 quadstep.motor_pins(1,A1,36,A8,A9,A10);
 quadstep.motor_pins(2,10,9,8,7,4);      
 quadstep.motor_pins(3,22,23,24,25,26);  
 quadstep.motor_pins(4,27,28,29,30,31);  

}

void loop() {
 
 quadstep.motor_go(2,1,-200,2);
 delay(500);

 quadstep.motor_go(2,1,200,2);
 delay(500);
}


thats the quadstep.h:
Code: [Select]
/*

created by Aaron Weiss, SparkFun electronics 2011

Beerware - do what you wish with this ish

*/

#ifndef quadstep_h
#define quadstep_h

#include "WProgram.h"

class quadstep
{
 public:
quadstep();
void motor_pins(int motnum,int motor_enable,int motor_dir,int motor_ms1, int motor_ms2, int motor_ms3);
   void motor_go(int motnum, int step_size, int number_of_steps, int torque);
void stall(int motnum);
//void motor1rpm(int direction,int level);

 private:
void current_control(int step);
int _torque;
int step1;
int step2;
int step4;
int step8;
int step16;

int _motor_enable_1;
int _motor_dir_1;
int _motor_ms_11;
int _motor_ms_12;
int _motor_ms_13;

int _motor_enable_2;
int _motor_dir_2;
int _motor_ms_21;
int _motor_ms_22;
int _motor_ms_23;

int _motor_enable_3;
int _motor_dir_3;
int _motor_ms_31;
int _motor_ms_32;
int _motor_ms_33;

int _motor_enable_4;
int _motor_dir_4;
int _motor_ms_41;
int _motor_ms_42;
int _motor_ms_43;
};
#endif



Martha113

and this is the quadstep.ccp:

Code: [Select]
#include "WProgram.h"
#include "quadstep.h"

#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask))

#define STEPMIN 800

quadstep::quadstep()
{
pinMode(11, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(46, OUTPUT);

cbi(PORTB, 5);
cbi(PORTE, 3);
cbi(PORTH, 3);
cbi(PORTL, 3);

Serial.begin(9600);
}

void quadstep::motor_pins(int motnum,int motor_enable,int motor_dir,int motor_ms1,int motor_ms2,int motor_ms3)
{
if(motnum == 1)
{
pinMode(motor_enable, OUTPUT);
pinMode(motor_dir, OUTPUT);
pinMode(motor_ms1, OUTPUT);
pinMode(motor_ms2, OUTPUT);
pinMode(motor_ms3, OUTPUT);

digitalWrite(motor_enable, HIGH);
digitalWrite(motor_dir, LOW);
_motor_enable_1 = motor_enable;
_motor_dir_1 = motor_dir;
_motor_ms_11 = motor_ms1;
_motor_ms_12 = motor_ms2;
_motor_ms_13 = motor_ms3;
}
else if(motnum == 2)
{
pinMode(motor_enable, OUTPUT);
pinMode(motor_dir, OUTPUT);
pinMode(motor_ms1, OUTPUT);
pinMode(motor_ms2, OUTPUT);
pinMode(motor_ms3, OUTPUT);

digitalWrite(motor_enable, HIGH);
digitalWrite(motor_dir, LOW);
_motor_enable_2 = motor_enable;
_motor_dir_2 = motor_dir;
_motor_ms_21 = motor_ms1;
_motor_ms_22 = motor_ms2;
_motor_ms_23 = motor_ms3;
}
else if(motnum == 3)
{
pinMode(motor_enable, OUTPUT);
pinMode(motor_dir, OUTPUT);
pinMode(motor_ms1, OUTPUT);
pinMode(motor_ms2, OUTPUT);
pinMode(motor_ms3, OUTPUT);

digitalWrite(motor_enable, HIGH);
digitalWrite(motor_dir, LOW);
_motor_enable_3 = motor_enable;
_motor_dir_3 = motor_dir;
_motor_ms_31 = motor_ms1;
_motor_ms_32 = motor_ms2;
_motor_ms_33 = motor_ms3;
}
else if(motnum == 4)
{
pinMode(motor_enable, OUTPUT);
pinMode(motor_dir, OUTPUT);
pinMode(motor_ms1, OUTPUT);
pinMode(motor_ms2, OUTPUT);
pinMode(motor_ms3, OUTPUT);

digitalWrite(motor_enable, HIGH);
digitalWrite(motor_dir, LOW);
_motor_enable_4 = motor_enable;
_motor_dir_4 = motor_dir;
_motor_ms_41 = motor_ms1;
_motor_ms_42 = motor_ms2;
_motor_ms_43 = motor_ms3;
}
else Serial.println("error: incorrect value for motor_pins, motor number");
}

void quadstep::motor_go(int motnum, int step_size, int number_of_steps, int torque)
{
_torque = torque;

if(motnum == 1)
{
int dir = (number_of_steps > 0) ? HIGH : LOW;
number_of_steps = abs(number_of_steps);

digitalWrite(_motor_dir_1, dir);

if(step_size == 1)
{
current_control(1);

digitalWrite(_motor_ms_11, LOW);    
digitalWrite(_motor_ms_12, LOW);    
digitalWrite(_motor_ms_13, LOW);

digitalWrite(_motor_enable_1, LOW);    
for(int i=1;i<=number_of_steps;i++)
{
sbi(PORTB, 5);
delayMicroseconds(step1);
cbi(PORTB, 5);
delayMicroseconds(step1);
}
cbi(PORTB, 5);
digitalWrite(_motor_enable_1, HIGH);  
}

else if(step_size == 2)
{
current_control(2);

digitalWrite(_motor_ms_11, HIGH);    
digitalWrite(_motor_ms_12, LOW);    
digitalWrite(_motor_ms_13, LOW);

digitalWrite(_motor_enable_1, LOW);    
for(int i=1;i<=number_of_steps;i++)
{
sbi(PORTB, 5);
delayMicroseconds(step2);
cbi(PORTB, 5);
delayMicroseconds(step2);
}
cbi(PORTB, 5);
digitalWrite(_motor_enable_1, HIGH);    
}

else if(step_size == 4)
{
current_control(4);

digitalWrite(_motor_ms_11, LOW);    
digitalWrite(_motor_ms_12, HIGH);    
digitalWrite(_motor_ms_13, LOW);

digitalWrite(_motor_enable_1, LOW);    
for(int i=1;i<=number_of_steps;i++)
{
sbi(PORTB, 5);
delayMicroseconds(step4);
cbi(PORTB, 5);
delayMicroseconds(step4);
}
cbi(PORTB, 5);
digitalWrite(_motor_enable_1, HIGH);    
}
else if(step_size == 8)
{
current_control(8);

digitalWrite(_motor_ms_11, HIGH);    
digitalWrite(_motor_ms_12, HIGH);    
digitalWrite(_motor_ms_13, LOW);

digitalWrite(_motor_enable_1, LOW);    
for(int i=1;i<=number_of_steps;i++)
{
sbi(PORTB, 5);
delayMicroseconds(step8);
cbi(PORTB, 5);
delayMicroseconds(step8);
}
cbi(PORTB, 5);
digitalWrite(_motor_enable_1, HIGH);    
}
else if(step_size == 16)
{
current_control(16);

digitalWrite(_motor_ms_11, HIGH);    
digitalWrite(_motor_ms_12, HIGH);    
digitalWrite(_motor_ms_13, HIGH);

digitalWrite(_motor_enable_1, LOW);    
for(int i=1;i<=number_of_steps;i++)
{
sbi(PORTB, 5);
delayMicroseconds(step16);
cbi(PORTB, 5);
delayMicroseconds(step16);
}
cbi(PORTB, 5);
digitalWrite(_motor_enable_1, HIGH);  
}
else Serial.println("error: incorrect value for step_size");
}

...........}

PeterH

Errors about setup() and loop() suggest there's something fundamentally wrong with your Arduino IDE, or your sketch. Are you able to compile and run the example sketches OK?
I only provide help via the forum - please do not contact me for private consultancy.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Martha113

hej,

I tried my best.....but nothing works :-(
I bought the totally new arduino mega 2560 - maybe this is the problem?

I also tried older Versions 0018/ 0019/ 0022..... all the examples are working and compiling:

the arduino library is from here: http://www.sparkfun.com/products/10507

it seems to be that I´m too stupid to compile an arduino library from others!!!

....


nicodes


Hi,

I got the same error. It was because I renamed my folder and my skecth name to "main"... I just change the filename and folder name and it compiles ok!

majenko

#9
Jun 09, 2014, 05:42 pm Last Edit: Jun 09, 2014, 05:44 pm by majenko Reason: 1
Things I can see wrong:

1. Library uses "WProgram.h" - this is for an ancient version of the Arduino core, and needs updating.
2. Library has ".........}" in it which isn't real C code...
3. Library code is incomplete and missing functions.

I suspect you didn't copy and paste the code properly.

Go Up