Let's Make Robots!

Arduino Librairy Compiling errors

Hello there,

 

Here is the situation, I have the Newping Librairy correctly added to my librairy folders and Ive been testing the example codes without success. . I cant attach it by importing it from the import librairy function on the sketch. Any help?

Note: I have more detailed information on second post.

 

Thanks

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Newping library works with the latest Arduino versions. I use Arduino 1.0.3 and have no problems with the newping library. It's the best library for ultrasonic sensors I have used.

Arduino IDE versions 1.0 and later require libraries to be modified to work with them. Most libraries have been updated but maybe the newping library has not. Go to the Arduino website and read the release notes for version 1.0. This explains the change that needs to be made.

You are totally right, I did change those pins for the IR. This sketch is the base sketch Im working with from someone else. On the other hand I did find what was wrong with the librairys!!! The librairy didnt show in the import librairy menu because I was using the arduino shortcut on my desktop. When I opened my arduino software directly from the folder (not with a shortcut) I had all my new librairy, it took me a while to find that one out. So for all the new guys using an arduino shortcut, make sure to redo your shortcut everytime you add a librairy to your arduino folder.

 

Thanks Maxhirez!

You aren't trying to use an Infra Red distance sensor with the NewPing library, are you? It's set up for a digital ultrasonic sensor. Most IR distance sensors are analog. Glad to hear you got the library registered though!
One thing I see is a conflict between your echo pin and your use of AFMotor 4-the af motor shield uses D6 for that. Check Limor's FAQ at http://www.ladyada.net/make/mshield/faq.html. I'm not precisely sure of this, but my assumption is that the NewPing library fails because the shield is actually attached in the "bus" ahead of the ultrasonic. Try reassigning your echo pin to one not used by the AFMotor shield for a stepper/dc and see if it helps.

This is the code

 

I am an arduino duelimove board with adafruit motorshield. Im running my arduino programm on windows 7.

 

#include <NewPing.h>
#include <AFMotor.h>

#define TRIGGER_PIN  5  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     6  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 100 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

AF_DCMotor motor2(2);
AF_DCMotor motor4(4);

void setup() {
  Serial.begin(9600); // Open serial monitor at 9600 baud to see ping results.
 
 // turn on motor
 motor2.setSpeed(200);
 motor4.setSpeed(200);

 
}

void loop() {
 
  delay(50);                // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  int cm = sonar.ping_cm(); // Send out the ping, get the results in centimeters.
  Serial.print("Ping: ");
  Serial.print(cm);         // Print the result (0 = outside the set distance range, no ping echo)
  Serial.println("cm");
 
 }

 

 

and here is the error:

 




nouveautest:9: error: 'NewPing' does not name a type
nouveautest.cpp: In function 'void loop()':
nouveautest:27: error: 'sonar' was not declared in this scope
 

Post the full code that's giving you problems and copy and paste the errors you get at run/compile.  Include your board/com/processor/OS configurations.