Newbie needing kind and gentle assistance w/code

Hello everyone, I am having a problem with some code that was sent to me to help me run 2 bump sensors and a 12v motor off of an arduino duemilanove and a motorshield from adafruit. My problem is that i keep getting 2 errors when compiling. one deals with AFmotor.h and the other with NewSoftSerial.h now, I have physically put them into the code, and it still gives me errors stating no such file or directory. Any suggestions? here is my code:

//ArduSentryMotor
//runs the motor in one direction until it gets a
//signal from either of two bump switches, reverses, repeats

//based on MotorTest code by Adafruit Industries, LLC
//and ButtonStateChange example by Tom Igoe
//this is public domain, be cool.



#ifndef _AFMotor_h_
#define _AFMotor_h_

#include <AFMotor.h>
#include <NewSoftSerial.h>

#include <inttypes.h>
#include <avr/io.h>

// comment out this line to remove microstepping support
// for smaller library. Be sure to delete the old library objects!
//#define MICROSTEPPING 1

#define MOTOR12_64KHZ _BV(CS20)  // no prescale
#define MOTOR12_8KHZ _BV(CS21)   // divide by 8
#define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS22)  // divide by 64

#define MOTOR34_64KHZ _BV(CS00)  // no prescale
#define MOTOR34_8KHZ _BV(CS01)   // divide by 8
#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00)  // divide by 64

#define MOTOR1_A 2
#define MOTOR1_B 3
#define MOTOR2_A 1
#define MOTOR2_B 4
#define MOTOR4_A 0
#define MOTOR4_B 6
#define MOTOR3_A 5
#define MOTOR3_B 7

#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4

#define SINGLE 1
#define DOUBLE 2
#define INTERLEAVE 3

#ifdef MICROSTEPPING
#define MICROSTEP 4
#endif

#define LATCH 4
#define LATCH_DDR DDRB
#define LATCH_PORT PORTB

#define CLK_PORT PORTD
#define CLK_DDR DDRD
#define CLK 4

#define ENABLE_PORT PORTD
#define ENABLE_DDR DDRD
#define ENABLE 7

#define SER 0
#define SER_DDR DDRB
#define SER_PORT PORTB



class AFMotorController
{
  public:
    AFMotorController(void);
    void enable(void);
    friend class AF_DCMotor;
    void latch_tx(void);
};

class AF_DCMotor
{
 public:
  AF_DCMotor(uint8_t motornum, uint8_t freq =  MOTOR34_8KHZ);
  void run(uint8_t);
  void setSpeed(uint8_t);

 private:
  uint8_t motornum, pwmfreq;
};

class AF_Stepper {
 public:
  AF_Stepper(uint16_t, uint8_t);
  void step(uint16_t steps, uint8_t dir,  uint8_t style = SINGLE);
  void setSpeed(uint16_t);
  uint8_t onestep(uint8_t dir, uint8_t style);
  void release(void);
  uint16_t revsteps; // # steps per revolution
  uint8_t steppernum;
  uint32_t usperstep, steppingcounter;
 private:
};

uint8_t getlatchstate(void);

#endif

/*
NewSoftSerial.h - Multi-instance software serial library
Copyright (c) 2006 David A. Mellis.  All rights reserved.
-- Interrupt-driven receive and other improvements by ladyada
-- Tuning, circular buffer, derivation from class Print,
   multi-instance support, porting to 8MHz processors,
   various optimizations, PROGMEM delay tables, inverse logic and 
   direct port writing by Mikal Hart

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

The latest version of this library can always be found at
http://arduiniana.org.
*/

#ifndef NewSoftSerial_h
#define NewSoftSerial_h

#include <inttypes.h>
#include "Print.h"

/******************************************************************************
* Definitions
******************************************************************************/

#define _NewSS_MAX_RX_BUFF 64 // RX buffer size
#define _NewSS_VERSION 10 // software version of this library
#ifndef GCC_VERSION
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif

class NewSoftSerial : public Print
{
private:
  // per object data
  uint8_t _receivePin;
  uint8_t _receiveBitMask;
  volatile uint8_t *_receivePortRegister;
  uint8_t _transmitBitMask;
  volatile uint8_t *_transmitPortRegister;

  uint16_t _rx_delay_centering;
  uint16_t _rx_delay_intrabit;
  uint16_t _rx_delay_stopbit;
  uint16_t _tx_delay;

  uint16_t _buffer_overflow:1;
  uint16_t _inverse_logic:1;

  // static data
  static char _receive_buffer[_NewSS_MAX_RX_BUFF]; 
  static volatile uint8_t _receive_buffer_tail;
  static volatile uint8_t _receive_buffer_head;
  static NewSoftSerial *active_object;

  // private methods
  void recv();
  bool activate();
  virtual void write(uint8_t byte);
  uint8_t rx_pin_read();
  void tx_pin_write(uint8_t pin_state);
  void setTX(uint8_t transmitPin);
  void setRX(uint8_t receivePin);

  // private static method for timing
  static inline void tunedDelay(uint16_t delay);

public:
  // public methods
  NewSoftSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
  ~NewSoftSerial();
  void begin(long speed);
  void end();
  int read();
  uint8_t available(void);
  bool active() { return this == active_object; }
  bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; }
  static int library_version() { return _NewSS_VERSION; }
  static void enable_timer0(bool enable);
  void flush();

  // public only for easy access by interrupt handlers
  static inline void handle_interrupt();
};

// Arduino 0012 workaround
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round

#endif

AF_DCMotor motor(4);
//motor shield uses all but 2, 13 and 9,10 if no servos
const int leftButtonPin = 9;
const int rightButtonPin = 10;
int leftButtonState = 0;
int rightButtonState = 0;
int leftButtonCounter = 1;//start of going right
int rightButtonCounter = 0;

//for serial
NewSoftSerial mySerialB(2, 13);//sets the rx, tx pins
char incomingChar = 'A'; //value to store incoming byte


void setup() {
  Serial.begin(57600);
  Serial.println("I'm a receiver.");

  // set the data rate for the NewSoftSerial port
  mySerialB.begin(4800);
  mySerialB.println("Reciever");

  motor.setSpeed(100);//turn on the motor
  motor.run(RELEASE);
  pinMode(leftButtonPin, INPUT);
  pinMode(rightButtonPin, INPUT);

}

void loop(){
//check serial port to see if the distance sensor arduino is saying to stop moving
  if (mySerialB.available()) {
      incomingChar=((char)mySerialB.read());
      Serial.print(incomingChar);
        if (incomingChar=='A'){
        Serial.println(" No target.");
          //read the state of the pushbuttons
          leftButtonState=digitalRead(leftButtonPin);
          rightButtonState=digitalRead(rightButtonPin);

          //then, add a value to each counter
          if (leftButtonState==HIGH){
          leftButtonCounter=1;
          rightButtonCounter=0;
          }
          else if (rightButtonState==HIGH){
            leftButtonCounter=0;
            rightButtonCounter=1;
          }

            //start the motor going forward until the right switch is hit
          if (leftButtonCounter==1){
          motor.run(FORWARD);
          }
          else
          motor.run(BACKWARD);
        }
        else {
          Serial.println(" Target acquired.");
          motor.run(RELEASE);
        }
  }
}

Please help! :’(

it still gives me errors

And the errors are…?

#ifndef _AFMotor_h_
#define _AFMotor_h_

#include <AFMotor.h>

I don’t think that is going to help any.

Direct from the program:

ArduSentryMotor.cpp:14:21: error: AFMotor.h: No such file or directory ArduSentryMotor.cpp:15:27: error: NewSoftSerial.h: No such file or directory

So, where have you put the header files?

Scary as this sounds, i dont know what you are referring to. What you see in that code is what I have. Im totally a fish out of water here. Sorry, I cant be more specific for you. :-/

Where is the file "AFMotor.h"? I'm sorry, I can't be more specific than this.

I put it into the code. Is this helpful? here it is:

#ifndef AFMotor_h
#define AFMotor_h

#include <inttypes.h>
#include <avr/io.h>

// comment out this line to remove microstepping support
// for smaller library. Be sure to delete the old library objects!
#define MICROSTEPPING 1

#define MOTOR12_64KHZ _BV(CS20) // no prescale
#define MOTOR12_8KHZ _BV(CS21) // divide by 8
#define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS22) // divide by 64

#define MOTOR34_64KHZ _BV(CS00) // no prescale
#define MOTOR34_8KHZ _BV(CS01) // divide by 8
#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64

#define MOTOR1_A 2
#define MOTOR1_B 3
#define MOTOR2_A 1
#define MOTOR2_B 4
#define MOTOR4_A 0
#define MOTOR4_B 6
#define MOTOR3_A 5
#define MOTOR3_B 7

#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4

#define SINGLE 1
#define DOUBLE 2
#define INTERLEAVE 3

#ifdef MICROSTEPPING
#define MICROSTEP 4
#endif

#define LATCH 4
#define LATCH_DDR DDRB
#define LATCH_PORT PORTB

#define CLK_PORT PORTD
#define CLK_DDR DDRD
#define CLK 4

#define ENABLE_PORT PORTD
#define ENABLE_DDR DDRD
#define ENABLE 7

#define SER 0
#define SER_DDR DDRB
#define SER_PORT PORTB

class AFMotorController
{
public:
AFMotorController(void);
void enable(void);
friend class AF_DCMotor;
void latch_tx(void);
};

class AF_DCMotor
{
public:
AF_DCMotor(uint8_t motornum, uint8_t freq = MOTOR34_8KHZ);
void run(uint8_t);
void setSpeed(uint8_t);

private:
uint8_t motornum, pwmfreq;
};

class AF_Stepper {
public:
AF_Stepper(uint16_t, uint8_t);
void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE);
void setSpeed(uint16_t);
uint8_t onestep(uint8_t dir, uint8_t style);
void release(void);
uint16_t revsteps; // # steps per revolution
uint8_t steppernum;
uint32_t usperstep, steppingcounter;
private:
};

uint8_t getlatchstate(void);

#endif

Where on your PC's hard disk is the file named "AFMotor.h?

Oringinally I had it my desktop, then I moved it into the arduino IDE folder, then into the libraries folder.

Normally, one would put the AFMotor.h (and other files that come with it) in a "libraries" directory. There are instructions here: http://www.ladyada.net/library/arduino/libraries.html

If you put the entire .h file inside your sketch, you would need to remove the #include as well, and the compile process would probably still have problems finding the other parts of the library (the actual code.)

I currently have them in the libraries folder of the arduino IDE folder...yet am still getting those errors. :(

What version of the IDE are you using? The proper placement of libraries depends on the version of the IDE.

Did you put both the .h and the .cpp files in a folder called AFMotor in the libraries folder?

What version of the IDE are you using

I am using the Arduino IDE-0021.

Did you put both the .h and the .cpp files in a folder called AFMotor in the libraries folder?

When I downloaded them from the website they were zip files, which I then unzipped all files into one folder. I moved that folder into the libraries folder of the IDE. :-/

I just heard some murmurings that the programming IDE typically dont work well with windows Vista. But 0021 is supposed to be FOR Vista. could that be the issue here? my computer sucks?

Open the IDE, with a blank sketch. Use the Sketch + Import Library... function. Does the ADFMotor library get listed? If not, use Windows Explorer and locate on of the libraries that does appear. Make sure you have AFMotor in the same place, in the same kind of directory structure,

Paul S. -

I followed your directives and both of the libraries were listed in the empty sketch + import library listing. This is so very confusing as to why its not working....

Did you stop and restart the IDE after installing the AFMotor library?

yes, several times. still no luck :(

Personally, by this point, I’d just copy off my own sketches if any to a folder as backup, then just completely de-install and re-install both the IDE and the libraries.

Having done systems support, this is sometimes the best approach, as figuring out where some file structure got messed up isn’t going to gain you anything but it will cost you time and aggravation. Deleting (de-installing) the entire application and such will probably be the fastest solution for you. “Back in the day”, we would copy off the user’s data (most was network storage anyway) and “flatten” (erase Hard drive and transfer on a standardized disk image, basically making the system “brand new” software-wise) if we estimated we’d be spending over an hour or so trying to track a problem down. We knew clean installs worked without fail… but hunting and cobbling sometimes doesn’t, due to things you didn’t consider. Starting from zero is something like nuking a city to kill a mosquito… it DOES work… luckily we’re only talking about a single application and not your whole system, so it’s really pretty painless. Half hour tops.

When you reinstall, make sure to follow the instructions carefully for how to bring the libraries on board… you will then have a clean, functional installation.

Yes, I know it’s not really the “right” answer, but often it’s better to find an answer that’s foolproof rather than “right”…

Focalist,

I de-installed and reinstalled my IDE and libraries, and still pulling my hair out. Do you have any other suggestions? Im really beginning to think this arduino stuff is just not for me...im very very discouraged.