library and sketches

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

Moderators: adafruit_support_bill, adafruit

library and sketches

Postby CharlieJ » Wed Jun 20, 2012 11:55 am

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
CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 10:59 pm

Re: library and sketches

Postby pburgess » Wed Jun 20, 2012 1:31 pm

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 1152 times
User avatar
pburgess
 
Posts: 1408
Joined: Sun Oct 26, 2008 1:29 am

Re: library and sketches

Postby adafruit_support_rick » Wed Jun 20, 2012 1:40 pm

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: 3139
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: library and sketches

Postby adafruit_support_rick » Wed Jun 20, 2012 2:05 pm

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.
User avatar
adafruit_support_rick
 
Posts: 3139
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: library and sketches

Postby CharlieJ » Wed Jun 20, 2012 2:45 pm

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
CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 10:59 pm

Re: library and sketches

Postby adafruit_support_bill » Wed Jun 20, 2012 2:54 pm

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.
User avatar
adafruit_support_bill
 
Posts: 16617
Joined: Sat Feb 07, 2009 9:11 am

Re: library and sketches

Postby bmco2n » Mon Jul 09, 2012 10:31 pm

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;
     }
  }
}
bmco2n
 
Posts: 75
Joined: Thu Apr 14, 2011 3:34 pm

Re: library and sketches

Postby adafruit_support_bill » Tue Jul 10, 2012 4:53 am

@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
User avatar
adafruit_support_bill
 
Posts: 16617
Joined: Sat Feb 07, 2009 9:11 am

Re: library and sketches

Postby bmco2n » Wed Jul 11, 2012 10:40 pm

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;
     }
  }
}
bmco2n
 
Posts: 75
Joined: Thu Apr 14, 2011 3:34 pm

Re: library and sketches

Postby adafruit_support_bill » Thu Jul 12, 2012 5:04 am

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.
User avatar
adafruit_support_bill
 
Posts: 16617
Joined: Sat Feb 07, 2009 9:11 am

Re: library and sketches

Postby CharlieJ » Sun Jul 15, 2012 3:55 pm

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
CharlieJ
 
Posts: 50
Joined: Tue Nov 29, 2011 10:59 pm

Re: library and sketches

Postby adafruit_support_rick » Sun Jul 15, 2012 5:10 pm

Just delete them as you would delete any other file - using Windows Explorer, or Finder on a Mac.
User avatar
adafruit_support_rick
 
Posts: 3139
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: library and sketches

Postby bmco2n » Tue Jul 17, 2012 6:45 pm

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
bmco2n
 
Posts: 75
Joined: Thu Apr 14, 2011 3:34 pm

Next

Return to Arduino

Who is online

Users browsing this forum: aduboreadioff, ArekKindAcere and 5 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]