library and sketches

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

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

library and sketches

Post by CharlieJ »

First of all I was a lot hasty in my postings on unable to verify codes. I am starting over with this forum.
I am still having problems getting motor control codes to work. Here is what I've done;
from the motor control page I down loaded 'Arduino stepper/servo Library with micro stepper support' then I unzipped the file. Then I put it into a new folder 'libraries' in the arduino libraries folder as 'adafruit-Adafruit-motor-shield-library-dd3da7' It contained the motor.h and motor.cpp and others.
I am not sure if I understand completely the structure of folders.
I need to recheck but the new libraries folder shows up in the examples drop down and shows the file but I did not see the AF_Motor.h or .cpp files. Where did go wrong?
Again sorry about the other postings, But I am struggling with this structure and codes Thanks Charlie j

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: library and sketches

Post by pburgess »

Hi Charlie,

After unzipping the file, rename the folder to just 'AFMotor'. It sounds like you might also have an extra nested 'Libraries' folder. Please see attached image for a depiction of how the folders should be arranged. Note that "Home Folder" and "Documents" are just examples in this case...the former will probably be your user name, and the latter may be "My Documents" if you're on a Windows system. But the nesting of folders within this is the same regardless. If you've gone and installed anything in your Arduino application folder (rather than within your home folder), undo those changes...everything can be done in your home folder. Also, make sure you're using the same upper and lower case as shown here.
hierarchy.png
hierarchy.png (9.43 KiB) Viewed 1672 times

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

Re: library and sketches

Post by adafruit_support_rick »

Sounds like you're almost there. First of all, your folder MUST be named "AFMotor".

Also, it sounds like you have one too many levels of "libraries" folders. Inside of your "arduino" folder, you should have a folder named "libraries". You want to put your "AFMotor" folder directly inside of that.

On your computer, you should have a folder structure like something like this:
Documents/Arduino/libraries/AFMotor

Inside the AFMotor folder, you should see the files AFMotor.cpp and AFMotor.h

You can check that you have the structure right: start up the Arduino application, open the 'Sketch' menu, and select "Import library…" You should see "AFMotor" in the list of libraries.

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

Re: library and sketches

Post by adafruit_support_rick »

One other thing - If you already have the Arduino app open when you set up your library folder, you'll have to quit and restart the app to see AFMotor in the list of libraries.

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

Re: library and sketches

Post by CharlieJ »

HEY, Guys, Well after many attempts the Arduino finally verified a motor control program all be it the test run.Again THANKS for putting up with me. I just did not understand the sturcture of the program, I'm not sure if I do now, but it works. Side question is it possible to reverse the Arduino to show the program that is in it, In all of this I lost the program that I wrote and installed in the Arduino. by the way the reason that I wound up with all the Arduino programs that it kept telling me about an update and when I would update it would install a complete program, so I ended up with about 3 or 4 programs in my computer which also confused me greatly. Thanks again and I hope I can reverse load my codes. Charlie J

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

Re: library and sketches

Post by adafruit_support_bill »

Great to hear that you got it working. :D
Unfortunately it is not possible to extract the source code back out of the Arduino. If you have trouble recreating it, don't be afraid to ask for assistance.

bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: library and sketches

Post by bmco2n »

Dear Forum, :P
In the sketch below a PIR motion sensor should turn on a motor to spread wings and lights up the eyes of a scarecrow, using the motor shield. The motor works with the AFMotor sketch from the tutorial for the DC motor, so the .h and .cpp files are installed OK. They both exist in the Arduino 0022 “library”.

Compiling, I get this error message: Scarecroweyesmotor.cpp:15:18: error: invalid suffix "_64KHZ" on integer constant. This is the declaration is made just above “void setup”. Can you advise? :mrgreen:


SCARECROWEYESMOTOR
[Edit - moderator - Please use the 'code' button when submitting code]

Code: Select all

/*
 * PIR activates Motor labeled “J” 
  #include <AFMotor.h>
 unsigned long time; 
          
const int ledPin = 13;             // choose the pin for the LED
const int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
  AF_DCMotor motor(12_64KHZ);    

void setup() 
{
  motor.setSpeed(200);
  pinMode(ledPin, OUTPUT);      // declare LED and Eye as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  
 }
void loop()
{
     float time = millis();  
  pirState = digitalRead(inputPin);  // read input value
  
   if (pirState == HIGH) {          // check for motion
     
      
      digitalWrite(ledPin, HIGH);    // turn motor ON
      motor.run(FORWARD);
      delay(1000);      
      digitalWrite(ledPin, LOW);      //turn relay off  
      motor.run(RELEASE);       
    
  } else {
    delay(1000);    
      if (pirState == HIGH) { 
      // We only want to acivate on the output change, not state
      pirState = LOW;
     } 
  }
}

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

Re: library and sketches

Post by adafruit_support_bill »

@bmco2n - Your motor definition is not complete.

Code: Select all

AF_DCMotor motor(12_64KHZ);   
You don't specify which motor port you are using (1, 2,3 or 4) and the PWM frequency constant is truncated. The line below will create the motor on port 2 and use 64 KHz as a PWM frequency.

Code: Select all

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: library and sketches

Post by bmco2n »

Dear Support,
RE Scarecroweyesmotor
:? I'm chagrined and beg your pardon for my making a typo; I knew the correct line should read: AF_DCMotor(2, MOTOR12_64KHZ); -- as you pointed out. Entering it carefully, I get the same error message, "unidentified ID before numerical constant", plus some others:

Scarecroweyesmotor:11: error: expected unqualified-id before numeric constant
Scarecroweyesmotor:11: error: expected `)' before numeric constant
Scarecroweyesmotor.cpp: In function 'void setup()':
Scarecroweyesmotor:15: error: 'motor' was not declared in this scope
Scarecroweyesmotor.cpp: In function 'void loop()':
Scarecroweyesmotor:30: error: 'motor' was not declared in this scope

I went to "Trouble Shooting" and there were lots of "unidentified ID" cases, all of which were answered by small corrections like ";" missing, etc. Going over my sketch several times didn't show me any errors that I could see. :oops: Could you see something? (Sorry, I can't find the "Code" button that you prefer I use:

Code: Select all

/*
 * PIR move wings 
 * ledPin is the relay
 */
 #include <AFMotor.h>
 unsigned long time; 
             
const int ledPin = 13;             // choose the pin for the LED
const int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
AF_DCMotor(2, MOTOR12_64KHZ);     // declaring as per 'AFMotor' sketch
void setup() 
{
     
  motor.setSpeed(200);
  pinMode(ledPin, OUTPUT);      // declare LED and Eye as output
  pinMode(inputPin, INPUT);     // declare sensor as input
     
 }
void loop()
{
   
  float time = millis();  
  pirState = digitalRead(inputPin);  // read input value
  
   if (pirState == HIGH) {          // check if relay is on  
     
      
      digitalWrite(ledPin, HIGH);    // turn eyes ON
      motor.run(FORWARD);            // move wings
      delay(1000);
      
      motor.run(RELEASE);
      delay(500);
      
      digitalWrite(ledPin, LOW);      //turn signal off  
      
      
    
  } else {
       
     
       
     if (pirState == HIGH) { 
      // We only want to print on the output change, not state
      pirState = LOW;
     } 
  }
}

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

Re: library and sketches

Post by adafruit_support_bill »

You are missing the "motor". It should be:

Code: Select all

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
The "code" button is just above the message editing box you use to post a message. Just click on that and paste your code between the tags.

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

Re: library and sketches

Post by CharlieJ »

I reference to librariesI was trying to delete some sketches that do not work but was saved as I was working on them. So how do I delete unwanted sketches? Charlie J

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

Re: library and sketches

Post by adafruit_support_rick »

Just delete them as you would delete any other file - using Windows Explorer, or Finder on a Mac.

bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: library and sketches

Post by bmco2n »

Dear Forum,

:oops: The DC motor goes the same direction whether it's FORWARD or BACKWARD, but I don't care ---My problem is solved. I don't know which is more astonishing: how stupid I'm getting or how patient you are. Thanks. :P :P

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

Return to “Arduino”