Show Posts
|
|
Pages: [1]
|
|
1
|
Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.4
|
on: July 30, 2012, 07:54:06 am
|
|
Well, I found the source of the false short ping readings. I had placed the 2 sensors 5 & 10 cm away from the Arduino Uno (with wav shield) on my pedestal. Something on the board emits a directional noise that the sensors heard and misreported the distance as short. When I moved the sensors 20 cm away and put a piece of wood between them and the computer, the noise no longer spoofed the Ping sensors. Thanks, everyone, for helping with suggestions. Tim - I am going to implement your new ping library next. I will post my results after testing.
|
|
|
|
|
2
|
Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.4
|
on: July 29, 2012, 09:03:00 am
|
|
Thanks, Tim, for the reply. I am trying to get around short false readings from the Parallax ping sensor. I have the same thing with v 1.4 of NewPing as I do with the std. ping library. Around the middle of the servo sweep I get short readings, typically 15 cm, for a couple of servo moves. Curiously, the ping will read below 15 cm during this dead band. My space has no influence on the position of servo. I have moved it all around to see if I am getting bad readings from my environment. NewPing works fine on both sides of the dead band. I have removed the servo from the project electrically (disconnect power and signal) and I still get low readings around the center of the sweep when I move it by hand. I have tried it on both servos and ping sensors. I have no idea how the servo position is effecting the ping sensor even when it is not moving and disconnected. My project is to sweep 360 deg around my sculpture pedestal with 2 servos and 2 pings. When someone comes close the wav shield plays a short file depending on distance and position. Any distance reading will trigger another wav file and if you walk the "right" way, the whole song will play. I got everything working and started to test when I discovered the short bad distances. I reduced the sketch to just the std. libraries and the short readings persist. I can manipulate them with delays and code but never get rid of them all. I hope that this description will aid you in suggesting how best to use NewPing. And ANY thoughts on the dead band of the servos would be greatly appreciated! Many Thanks!!
|
|
|
|
|
3
|
Using Arduino / Programming Questions / Re: Servo2Timer and Parallax ultrasonic sensors
|
on: July 27, 2012, 07:10:44 am
|
Hello again. I rewrote my sketch using the servo and ping librarys that come with the IDE. I am still getting low distance values in the middle of the sweep. I can take the servo out of the sketch and the same thing happens. For 9 readings in the middle of the sweep, the distance is 15 cm instead of maximum. I can hold my hand in front of the sensor and it will read shorter distances so the sensor is working properly. I moved the sensor around to eliminate the effect of what I am pinging and can turn the servo by hand but still get low readings in the middle of the sweep. I have 2 servos and 2 ping sensors from Parallax and it happens to both of them. I am attaching the ping sensors to pins 6 & 8 and the servos to pins 7 & 9. // Sweep // by BARRAGAN <http://barraganstudio.com> // This example code is in the public domain. #include <Servo.h> const int ping1 = 7; const int ping2 = 9; int cm; Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup() { // initialize serial communication: Serial.begin(115200); myservo.attach(8); // attaches the servo on pin 9 to the servo object }
int ping(int pingPin){ // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH); cm = microsecondsToCentimeters(duration);
return cm; }
long microsecondsToInches(long microseconds) { // According to Parallax's datasheet for the PING))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }
void loop() { for(pos = 0; pos < 180; pos += 10) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(50); ping(ping1); Serial.print(cm); Serial.println(" cm up"); delay(50); ping(ping2); } for(pos = 180; pos>=1; pos-=10) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(50); // waits 15ms for the servo to reach the position ping(ping1); Serial.print(cm); Serial.println(" cm down"); delay(50); ping(ping2); } }
I have put 470mf capacitors across the servos and 33 mf caps across the ping sensors. I drive the servos with a separate 5vDC power supply. These measures had no effect. Does anyone have a suggestion for me? Thanks! --Cappy Jack
|
|
|
|
|
4
|
Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.4
|
on: July 24, 2012, 04:11:03 am
|
|
I am interested in using the new ping library but am concerned about the interrupt driven version. I am using an arduino uno, 2 parallax ping sensors mounted on servo motors (from Parallax). I want to drive each servo 180 deg to make a full 360 sweep as fast as I can. After each servo move, I want to ping a distance and use that value to play a small wav file. I put an Adafruit wav shield on my arduino and found that it uses the only 16 bit timer. The servo library from arduino uses it too. So I found another servo library that uses an 8 bit timer on the AT328 and I can play wavs and mover servos. I cannot get good pings all the time with the standard ping code.
It appears that the new ping libary uses the 16 bit timer, too. But, in the revision history, it appears that an earlier version does not. Is that correct? I would appreciate any suggestions. Thank you.
|
|
|
|
|
5
|
Using Arduino / Sensors / unreliable measurment using an uno with parallax ping sensor and servo
|
on: July 23, 2012, 08:30:23 am
|
Hello! I am using a ping sensor with an arduino uno board. I bought a kit with ping sensor, servo motor and mount. I am sweeping the servo back and forth ~180 deg. and pinging between moves. I have tried two approaches with differing unreliable output. I describe the unreliable output below. The sketch is very small so I will post the whole thing. // sketch to move servo and ping a distance// two different ways with different results
#include <ServoTimer2.h> const int pin6 = 6; //attaches servo to pin 6 const int ping1 = 7; //attaches ping sensor to pin 7
long duration1; // used in ping function long cm1; // distance value int num1; // direction value out of servo1 int dir; // var for switch to sweep servo back & forth in move
ServoTimer2 servo1; // declare objects for servos
void setup() { Serial.begin(9600); // initialize serial communication: servo1.attach(pin6); // attach pins to the servos dir = 0; // set initial direction of switch statement int num1 = 0; // initialize servo movement var duration1 = 0; // initialize ping var }
long ping() // function to drive the ping sensors { pinMode(ping1, OUTPUT); digitalWrite(ping1, LOW); delayMicroseconds(4); //was 2 digitalWrite(ping1, HIGH); delayMicroseconds(10); //was 5 digitalWrite(ping1, LOW); pinMode(ping1, INPUT); duration1 = pulseIn(ping1, HIGH); cm1 = microsecondsToCentimeters(duration1); return cm1; }
long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; } // end of ping
long out() { Serial.print(cm1); Serial.println(" cm1 "); }
int move_another(){ // this gets good distance values from i = 45 down to i = 12 then bad distance int count = 0; int i; for ( i = 1; i != 60; i++){ // servo starts in the middle so for the first loop it hangs from i = 30 until i = 60 if ( i <= 30 ){ // then it sweeps back and forth ~180 deg correctly num1 = (servo1.read() - 50); delay(5); servo1.write(num1); delay(400); ping(); out(); count = count + 1; Serial.print(i); Serial.println(" i < 15 "); } else{ num1 = (servo1.read() + 50); delay(5); servo1.write(num1); delay(400); ping(); out(); count = count + 1; Serial.print(i); Serial.println(" i > 15 "); } } }
int move(){ // This one gets 29 good distances then 29 bad ones ( always 15 cm) switch (dir) { case 0: ping(); out(); num1 = (servo1.read() + 50); delay(5); servo1.write(num1); delay(250); if (num1 >= 2250){ dir = 1; } break; case 1: ping(); out(); num1 = (servo1.read() - 50); delay(5); servo1.write(num1); delay(250); if (num1 <= 800){ dir = 0; } break; } }
void loop() { move(); // move_another(); }
/code]
The servo moves as expected, back and forth for ~180 deg. The ping sensor works when the servo is off.
the function move_another gets good distance values from i = 45 down to i = 12 then bad distance Now a good distance is the maximum range- 350 cm and the bad distance is 15 cm. Oddly enough, if I hold my hand in front of the bad reading, it gives me a good reading under 15 cm.
The function move gets 29 good distances then 29 bad ones ( always 15 cm) It measures good values, i.e 350 cm, which I can influence with my hand to give different accurate values. The bad values start in the middle of a sweep, i.e. num1 < 1550 go down to 750 and back up to 1650 then get good again.
I wrote another function which has good and bad readings and a few dodgy reading, i.e. 120 cm when it should be 350. I am trying to keep the sketch as simple as possible in order to understand why ping works sometimes and not others. I thought perhaps the servo motor gives an interference sound and I tested another servo motor with the same result. I also tested another ping sensor with the same results.
Thanks for having a look. Any suggestions are welcome!
Regards, Cappy
|
|
|
|
|
6
|
Using Arduino / Programming Questions / Servo2Timer and Parallax ultrasonic sensors
|
on: July 22, 2012, 01:43:10 pm
|
Hello. I am trying to drive a servo from Adafruit 180 deg. in increments back and forth. Between moves of the servo I am pinging a parallax ultrasonic sensor to determine distance. I am using Servo2Timer because ultimately I will use the wav shield from Lady Ada which has an interrupt conflict with the standard servo library. The ping sensor does not give a valid distance all the time. The whole sketch is so small I will post it. // sketch to move servo and ping a distance // two different ways with different results
#include <ServoTimer2.h> const int pin6 = 6; //attaches servo to pin 6 const int ping1 = 7; //attaches ping sensor to pin 7
long duration1; // used in ping function long cm1; // distance value int num1; // direction value out of servo1 int dir; // var for switch to sweep servo back & forth in move
ServoTimer2 servo1; // declare object for servo
void setup() { Serial.begin(9600); // initialize serial communication: servo1.attach(pin6); // attach pin to the servo dir = 0; // set direction of servo to zero int num1 = 0; // initialize direction of servo movement duration1 = 0; // used in the ping function }
long ping() //function to drive the Parallax ultrasonic sensors { pinMode(ping1, OUTPUT); digitalWrite(ping1, LOW); delayMicroseconds(2); digitalWrite(ping1, HIGH); delayMicroseconds(5); digitalWrite(ping1, LOW); pinMode(ping1, INPUT); duration1 = pulseIn(ping1, HIGH); cm1 = microsecondsToCentimeters(duration1); return cm1; }
long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; } // end of ping
long out() //function to print distances { Serial.print(cm1); Serial.println(" cm1 "); }
int move_another(){ // this code gets good distance values from i = 45 down to i = 12 // then bad distance- always ~ 15 cm int count = 0; int i; for ( i = 1; i != 60; i++){ // servo starts in the middle so for the first loop it // hangs from i = 15 until i = 60...doesn't matter... if ( i <= 30 ){ // then it sweeps ~180 deg correctly num1 = (servo1.read() - 50); delay(5); servo1.write(num1); delay(400); ping(); out(); count = count + 1; Serial.print(i); Serial.println(" i < 15 "); } else { num1 = (servo1.read() + 50); delay(5); servo1.write(num1); delay(400); ping(); out(); count = count + 1; Serial.print(i); Serial.println(" i > 15 "); } } }
int move(){ // This one gets 29 good distances then 29 bad ones ( always 15 cm) switch (dir) { // ad infinitum case 0: ping(); out(); num1 = (servo1.read() + 50); delay(5); servo1.write(num1); delay(250); if (num1 >= 2250){ dir = 1; } break; case 1: ping(); out(); num1 = (servo1.read() - 50); delay(5); servo1.write(num1); delay(250); if (num1 <= 800){ dir = 0; } break; } }
void loop() { move(); // move_another(); }
I have tried delays in a variety of values and places in the code because I determined the ping sensors are sensitive to timing. I would appreciate any help anyone can give me. Thanking you in advance.
|
|
|
|
|
7
|
Using Arduino / Programming Questions / Re: Errors Installing External Libraries (MegaServo, ServoTimer2 , SoftwareServo)
|
on: May 14, 2012, 08:21:16 am
|
Hello....I am using an arduino uno with a adafruit wav shield. I got a conflict with the serv.ccp and waveHC.ccp over using Timer1. I am trying to work around by using ServoTimer2 but with the simplest sketch I get these errors: sketch_may14b.cpp.o: In function `__static_initialization_and_destruction_0': C:\Users\cappy\AppData\Local\Temp\build987738042993949936.tmp/sketch_may14b.cpp:7: undefined reference to `ServoTimer2::ServoTimer2()' C:\Users\cappy\AppData\Local\Temp\build987738042993949936.tmp/sketch_may14b.cpp:8: undefined reference to `ServoTimer2::ServoTimer2()' sketch_may14b.cpp.o: In function `loop': C:\Users\cappy\AppData\Local\Temp\build987738042993949936.tmp/sketch_may14b.cpp:19: undefined reference to `ServoTimer2::write(int)' C:\Users\cappy\AppData\Local\Temp\build987738042993949936.tmp/sketch_may14b.cpp:21: undefined reference to `ServoTimer2::write(int)' C:\Users\cappy\AppData\Local\Temp\build987738042993949936.tmp/sketch_may14b.cpp:24: undefined reference to `ServoTimer2::write(int)' C:\Users\cappy\AppData\Local\Temp\build987738042993949936.tmp/sketch_may14b.cpp:26: undefined reference to `ServoTimer2::write(int)' sketch_may14b.cpp.o: In function `setup': C:\Users\cappy\AppData\Local\Temp\build987738042993949936.tmp/sketch_may14b.cpp:12: undefined reference to `ServoTimer2::attach(int)' C:\Users\cappy\AppData\Local\Temp\build987738042993949936.tmp/sketch_may14b.cpp:13: undefined reference to `ServoTimer2::attach(int)' The code is as follows: #include <ServoTimer2.h> // the servo library
ServoTimer2 a; ServoTimer2 b;
void setup() { a.attach(5); b.attach(6); }
void loop() { a.write(2000); delay(500); a.write(1000); delay(500); b.write(2000); delay(5000); b.write(1000); delay(500); }
I have found several versions of ServoTimer2 here and at the Adafruit forum. None of them are working for me. Please advise! Thank you!! Cappy Jack
|
|
|
|
|