motor shield code ??

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 11:59 pm

motor shield code ??

Post by CharlieJ »

i am trying to write some motor control codes and keep getting stopped. It seems like a simple issue but I cannot seem to get past it.
I have a code that I got and it verified ok. So I am using it as a guide and my work is below and for some reason I am getting the error; 'AR_DCMotor' does not name a type and it repeats for motor 2. Then the error ;'motor1' was not declared in this scope and that repeats for motor2. Why in one sketch the wording is ok but in another it is not ok? I have tried using parenthsis and still errors. Codes seem to be my biggest problem. Thanks for your help Charlie J

#include<AFMotor.h>

AF_DCMotor motor1(3);
AF_DCMotor motor2(4);

void setup()
{
  Serial.begin(9600);
  Serial.println("Duel Motor");
  motor1.setSpeed(250);
  motor2.setSpeed(250);
}

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: motor shield code ??

Post by Franklin97355 »

Do you have the AF_Motor library downloaded and installed in the correct location? That error usually means you don't.

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: motor shield code ??

Post by adafruit_support_bill »

As franklin says, that error typically means that the library is not installed in the correct location. Our library tutorial explains how to install libraries: http://www.ladyada.net/library/arduino/libraries.html

CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 11:59 pm

Re: motor shield code ??

Post by CharlieJ »

I am thinking that one motor code that was downloaded from another source verifies and works my motor shield, the proper files are in my computer? So if I enter my codes why do they not work, I have been on this road before, I did not like it. I have checked my computer and the motor files are in the library files and are properly renamed. ?? Charlie J

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: motor shield code ??

Post by adafruit_support_bill »

Let's take this one step at a time:

Can you open one of the AF_Motor example files and compile it?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: motor shield code ??

Post by adafruit_support_rick »

Charlie - here's a snapshot of my folder structure. Maybe this will help you get yours straightened out.
AFMotorlibrary.jpg
AFMotorlibrary.jpg (78.68 KiB) Viewed 1866 times

CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 11:59 pm

Re: motor shield code ??

Post by CharlieJ »

The best I can tell the files are correct; arduino-1.0.1\libraries\AFMotor is the line when I go to the file. In the file I see AFMotor.ccp and AFMotor.h files. But I entered #include <AF_Motor> it did not compile and gave me a long error message
core.a(main.ccp.o):In function 'main':
F:\arduino-1.0.1\hardware\arduino\cores\
arduino/main.cpp:11:undefined reference to 'setup'
F:\arduino-1.0.1\hardware\arduino\cores\arduino/main.cpp:14undefined reference to 'loop'
Yet when I compile a code from your website it verifies ok Again what am I doing wrong? Charlie J

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: motor shield code ??

Post by adafruit_support_rick »

Undefined references to loop and setup are a different animal. You may have a stray or missing curly bracket someplace. Post your code, and we'll have a look

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: motor shield code ??

Post by adafruit_support_bill »

Code: Select all

F:\arduino-1.0.1\hardware\arduino\cores\
arduino/main.cpp:11:undefined reference to 'setup'
F:\arduino-1.0.1\hardware\arduino\cores\arduino/main.cpp:14undefined reference to 'loop'
Every program must have a:

Code: Select all

void setup()
{
  // put your setup code here, to run once:
}
and a:

Code: Select all

void loop()
{
  // put your main code here, to run repeatedly: 
}
The best thing to do is start with one of the AF_Motor examples and modify the setup() and loop() code to do what you want to do.

CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 11:59 pm

Re: motor shield code ??

Post by CharlieJ »

I am home and reexamined my library, I looked at your folder page and mine is much the same, starts arduino-1.0.1; under that is other files (drivers; examples; hardware; java; lib; library) In the library is AFMotor and in the file is examples; AFMotor.ccp; AFMotor.h ; keywords; Readme. With the other files it is the same.
I entered a simple code to drive the motors forward and it did not verify Here is my code;
#include<AF_Motor.h>

AF_DCMotor motor1(3,motor);
AF_DCMotor motor2(4,motor);


void setup();
{
Serial.begin(9600);
Serial.println("Motor test");
motor1.setSpeed(200);
motor2.setSpeed(200);
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void loop()
{
serial.print("Forward");
motor1.run(FORWARD);
motor2.run(FORWARD);
}

This should drive the motors, there is a very long list of errors, I cannot make a copy of the errors to send Hpoe you can help Charlie J

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: motor shield code ??

Post by adafruit_support_rick »

The library folder *must* be named 'libraries', not 'library'

CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 11:59 pm

Re: motor shield code ??

Post by CharlieJ »

It is labeled libraries I just mistyped the name . I also forgot to capitalise one of the Serial lines. Still the motors are not right. Charlie J

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: motor shield code ??

Post by adafruit_support_bill »

Still the motors are not right
Are you seeing the exact same error messages as before? If not, please post the ones you are seeing now.

CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 11:59 pm

Re: motor shield code ??

Post by CharlieJ »

In your last post you asked for the error codes, I can copy the control codes but I cannot seem to copy the error codes. I have tried copy and paste and copy to forum and niether works. How can I di that? Charlie J

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: motor shield code ??

Post by adafruit_support_bill »

Use your mouse to select the error text in the IDE. Then use [Ctrl]-C to copy.
You can paste them into a forum message with [Ctrl]-V.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”