Show Posts
Pages: 1 2 3 [4] 5 6 ... 35
46  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: May 12, 2014, 10:49:19 am
First, thank you for this valuable Ping Library,

I am attempting to use the same trigger ping for three HC-SR04 sensor on a Pro-Mini Arduino and so far, things appear to be working fine on the bench. My question is, are there any know issues with using the same trigger pin for two or more sensors?

Thank you.

I've never tried using the same trigger pin for multiple sensors nor is the library designed to work this way.  What NewPing would do would be to actually try to initiate a ping three times each sensor.  The sensor would probably ignore this, but there's no guarantee.  Also, I would be concerned with the higher likelihood of echos giving bad results or the pulsing from multiple sensors confusing the sensors.

It would be better (avoiding echos and cross-talk issues) and use fewer pins to just wire a single pin to each sensor's trigger and echo pin.  In other words, you would use 3 pins, each pin going to each sensor's trigger and echo pins.  This would use 3 pins instead of (I assume) the 4 pins you're currently using.  Yes, you would need to ping each sensor individually, but using the non-blocking ping_timer() method your microcontroller could be doing other things while the ping sound is traveling.  I would consider this a more "sound" way to implement 3 sensors.

May I ask, why do you want to ping all three at the same time?  Would it really matter if each ping was 30ms apart?  You could still ping 3 sensors 10 times a second while still "multi-tasking" and doing other processes in your sketch.  Insight on your project and the reasoning would be helpful.

Tim
47  Using Arduino / Audio / Re: TONE library and External interrupt code collision on: May 06, 2014, 08:58:09 am
Thank for tour answer teckel, one more question, the toneAC library can playa 2 different tones at the sale time, like the library i used?

toneAC plays one tone but uses two SPECIFIC pins to do it.  It does this in a push/pull manor which creates a high sound volume level (and allows you to control the volume).  If you want to play two notes at once, you could probably use toneAC and toneAC2.  I've never tried it but as they use different timers and toneAC2 can use different pins they should work just fine together.  You'll use both timer 1 and timer 2 in the process.  But, to play multiple tones at the same time you probably will used multiple timers.

I also have a tone generator library that doesn't use timers at all, TimerFreeTone.  It runs in blocking mode (doesn't return the the code till the tone is complete).  So, it doesn't work well if you're trying to play music.  But if you just want to play two tones at once and only use one timer, you can use toneAC and TimerFreeTone together as well.

Lots of options, all depending on your needs.

Tim
48  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: May 05, 2014, 03:00:54 pm
Thanks Tim,

I actually managed it before seeing this post but. I have actually soldered the sensor to the control board as this passes the commands to the motor board. The only problem I seem to be having is that once it detects an object within the desired range the pinging stops as do the measurements to the serial monitor. So when it is supposed to rotate and then carry on doing the same again it just seems to end and then the motors go into a wiggling action?

Thanks again!

Jay.

My guess is that it has something to do with the while loop where you never set a ping variable and never output serial results.  Like usual, it's just doing what you're telling it to do.

I don't know why you have two nestled curly brackets after loop(), either or what that would even do.   Also, you're doing multiple pings and probably shouldn't be.  You're doing one to set the variable cm and print the results, then another ping in the while statement that's actually being used to detect an object.  My guess is that your loop() routine should be more like this:

Code:
void loop() {
  unsigned int cm = sonar.ping_cm(); // Do a ping and set the distance in centimeters to variable cm
  Serial.println(cm); // Output the ping distance in centimeters
  if (cm < 20) { // If an obstacle is less than 20cm away
    Robot.motorsStop(); // stop the motors
    setFace(false); //shows an unhappy face
    Robot.turn(45); // turn to the right and try again
    delay(500); // wait for a moment while it turns (this isn't required if Robot.turn() is a blocking command)
  } else {
    Robot.motorsWrite(155, 155); // if there are no objects in the way, keep moving
    setFace(true); // happy face
    delay(50); // Delay between pings
  }
}

But, I don't ultimately know what you're trying to accomplish, nor have an Arduino Robot to test this with.  But, this code makes more sense than what you had and it compiles.  Also, this has nothing really to do with NewPing.  This is more just simple programming debugging.  You were creating a while loop where it wasn't setting a new distance variable nor sending that value to the serial port, so of course it won't output anything for as long as it's stuck in the while loop.

Tim
49  Using Arduino / Audio / Re: TONE library and External interrupt code collision on: May 05, 2014, 10:37:42 am
Hi guys, good day

Sorry a long tiem without working with arduino, and now i'm stuck on one big problem, i need your help. I'm making this project, with external interrupt to generate super mario bros sound, but it doesn't make any sound. someone can help me??

i see that the interrupt use the uint_8t and the TONE library too, how can i solve it? what i need to change, add or erase  in the code. When i compile the software don't send me any error or warning.

I attach the tone library

If you have a timer conflict, just use a different library that doesn't use the same timer.  The tone library uses timer 2.  So, use a library that uses timer 1 instead.  I created two libraries that do just this:

NewTone - Plug-in replacement for the tone library, uses timer 1, much smaller and faster.
toneAC - Twice as loud, ability to control volume, uses timer 1, must use two specific pins.

I also have a 3rd library that would work that doesn't use any timers at all.  This is useful if you have a project that both uses timer 1 and timer 2 but you still want to play sound.  That library can be found here:

TimerFreeTone - Doesn't use timers at all, but in blocked mode (can't do other things while the tone is being played).

Between these 3, you should find something that works.  All have example sketches that show working examples.  I even have a 4th audio library called toneAC2 that works similar to toneAC but uses timer 2.  That won't work for you, as your conflict is with timer 2.  Yes, I do have a lot of audio libraries smiley-wink

Tim
50  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: May 05, 2014, 10:12:45 am
Thanks for your help Tim, I have now attached the sensor to D3 and I am able to get readings via serial. Could you or anybody else help me change this code to work with your library:

Code:
#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>

int sensorPin = M1;  // pin is used by the sensor

void setup() {
  // initialize the Robot, SD card, and display
  Serial.begin(9600);
  Robot.begin();
  Robot.beginTFT();
  Robot.beginSD();
  Robot.displayLogos();

  // draw a face on the LCD screen
  setFace(true);
}

void loop() {
  // If the robot is blocked, turn until free
  while (getDistance() < 40) { // If an obstacle is less than 20cm away
    setFace(false); //shows an unhappy face
    Robot.motorsStop(); // stop the motors
    delay(1000); // wait for a moment
    Robot.turn(90); // turn to the right and try again
    setFace(true); // happy face
  }
  // if there are no objects in the way, keep moving
  Robot.motorsWrite(255, 255);
  delay(100);
}

// return the distance in cm
float getDistance() {
  // read the value from the sensor
  int sensorValue = Robot.analogRead(sensorPin);
  //Convert the sensor input to cm.
  float distance_cm = sensorValue * 1.27;
  return distance_cm;
}

// make a happy or sad face
void setFace(boolean onOff) {
  if (onOff) {
    // if true show a happy face
    Robot.background(0, 0, 255);
    Robot.setCursor(44, 60);
    Robot.stroke(0, 255, 0);
    Robot.setTextSize(4);
    Robot.print(":)");
  } else {
    // if false show an upset face
    Robot.background(255, 0, 0);
    Robot.setCursor(44, 60);
    Robot.stroke(0, 255, 0);
    Robot.setTextSize(4);
    Robot.print("X(");
  }
}

This is meant to be used with an analog sensor like a Maxbotix EZ10.

Thanks for your help so far!
Jay.

P.S. All of the LCD stuff isn't important, it is just the sensor working with the motors I need working. Thanks again!

To use NewPing, all you would do is include the library, setup the constructor, and send a ping.  The basic NewPing example shows how to do this.

But, basically you would include the library like this:
Code:
#include <ArduinoRobot.h>

Setup the constructor:
Code:
NewPing sonar(sensorPin, sensorPin, 100);

And initiate a ping and get the result, which in your code would look something like this:
Code:
  while (sonar.ping_cm() < 40) { // If an obstacle is less than 40cm away

However, the sensor would need to be connected to the motor board, not the control board.  I don't have an Arduino Robot to be able to tell you how to write your code.  My guess is that you need two sketches, one for the control board and one for the motor board, and your sketch would need to communicate between the two boards to accomplish this.  I have no first-hand usage of the Arduino Robot so there's no way for me to write working code for you.  I tried, and it wouldn't compile.

I do know that you would need to connect the ultrasonic senor to one of the pins on the motor board (TK1-TK4).  Other than that, you're on your own to write your own code.  It should be VERY easy if you know how to program Arduino sketches and have any experience with using the Arduino Robot.  If this is your first sketch, maybe you should start with something really basic first.

Tim
51  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: May 02, 2014, 09:25:38 am
Do you just name the same digital pin twice when you want to use the same pin for trigger and echo?  That simple?

Yup, that simple.

Tim
52  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: May 02, 2014, 08:36:50 am
Hi Tim,

I was wondering if you could advise me on how to connect a HC-SR04 to the official arduino robot, I am stumped and have promised some kids a model of R2-D2 for a music event on Sunday using the robot as it's base but only realised afterwards that it doesn't support digital sensors out of the box, please help!

Thanks,
Jay.

I don't know what you mean buy it doesn't support digital sensors.  The Arduino Robot's control board has 5 digital I/O ports and the motor board has 4 I/O ports.  It looks like the control board has 8 multiplexed pins labeled TK0-TK7 that can't be used with NewPing.  But, the specs say there's 5 digital I/O pins, so the interfaces to these pins are in other locations.  The motor board's 4 I/O pins TK1-TK4 do have connection ports right on the board that are not multiplexed so they can go straight to the ultrasonic sensor.  NewPing can interface with a HC-SR04 using only one pin, so you can wire both the trigger and echo pins on the sensor to the same I/O pin on the Arduino Robot.  While TK1 and TK2 are analog pins, they will work just fine as digital pins as well.  Remember, analog pins are also always digital pins (but not vice versa).

Since it seems that the motor board is the easier to connect an ultrasonic sensor via NewPing, here's some code that should work (keep in mind that I don't have an Arduino Robot so this is just a shot in the dark, anyone willing to donate one?):

Code:
#include <NewPing.h>

NewPing sonar(TK3, TK4, 200);

void setup() {}

void loop() {
  delay(50);
  unsigned int cm = sonar.ping_cm();
  // Do something with the results
}

To conserve available pins, you could also use the same pin for trigger and echo.  Also, remember that you could just as well use TK1 and TK2 even though they're analog pins, they will work as digital.

Hope this helps!

Tim
53  Using Arduino / Audio / Re: how can i display high frequencies (40kHz to 75 kHz) on: April 30, 2014, 11:57:36 am
My toneAC library was designed to work at very high frequencies, 2.66 MHz even!  As a bonus, it will also drive the two ultrasonic leads in a push/pull manor which will generate much louder output (almost twice as loud).  So, you'll be able to scare those little buggers from further away.

Here's an example sketch that will loop from 40 kHz to 75 kHz.  You would connect your speaker leads to pins 9 & 10 if you're using an Arduino Uno.  If you're using different hardware, you should check the toneAC website to see what pins to use.  You'll also (obviously) need a transducer that can generate sufficient output in this frequency range (I have some that are designed to peak at 40 kHz and 60 kHz).

Code:
#include <toneAC.h>

void setup() {}

void loop() {
  for (unsigned long freq = 40000; freq <= 75000; freq += 20) {  
    toneAC(freq); // Play the frequency (40 kHz to 75 kHz in 20 Hz steps).
    delay(2);     // Wait 2 ms so it will generate output.
  }
}
54  Using Arduino / Audio / Re: TimerFreeTone Library v1.1 - Generate audio tones without any timer conflicts on: April 30, 2014, 11:44:55 am
New version of the Timer FreeTone library released.

Download TimerFreeTone v1.1

This release was actually tested on an Arduino, so I'm sure it works now.  I also fixed/changed a few things.  It generates code that's a bit smaller as well.  Let me know how it works for you!

Tim
55  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: April 28, 2014, 07:56:52 pm
Hi I'm trying to use your library with arduino due and the 1.5 version direct seem to have support. I noticed on the Google code page a note said that 1.6 will have support but it's not released yet. I tried to find the source on the Google code page but u don't seem to host the source code on it. Is there due support available?

Version 1.6 does support the Due.  Well, I believe it does.  I don't have a Due to verify this.

Tim
56  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: April 25, 2014, 04:38:14 pm
little confused on the "code.google" site changes.  are the "issues" you marked as done going to have the changes in the next version?  also, why remove that issues list?  it seems a very effective way to track features and bugs.  the forum thread is kind of overwhelming, and very difficult to track any issues on.


I'm not notified when issues are created or when people make comments to sketches.  Also, there isn't a good way of communicating about an issue.  On this forum, I get notifications and others or myself can answer.  No issues were looked at on the code.google site.  If you have an issue or a suggestion, just post to this thread.

Thanks!

Tim
57  Using Arduino / Audio / TimerFreeTone Library v1.1: Play tones without timers and therefore no conflicts on: April 25, 2014, 09:45:42 am
I've already written 3 alternative tone libraries (toneAC/toneAC2 & NewTone).  However, a user asked for a way to create tones without using any timers as he had conflicts with both timer 1 and timer 2.  This seemed like a perfect opportunity to confuse people further by creating a 4th library that did essentially the same thing, generate sound.  So, I wrote up sample code that evolved into the TimerFreeTone library.  As a bonus, it works with all ATmega/ATtiny AVR microcontrollers as well as the Arduino Due, Teensy 3.0/3.1 and other ARM-based microcontrollers equally well.

Download TimerFreeTone v1.1

Version 1.1 added a few small changes (after I got around to actually tested the library first-hand with an Arduino).

Code:
#include <TimerFreeTone.h>

#define TONE_PIN 10 // Pin you have speaker/piezo connected to (be sure to include a 100 ohm resistor).

int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 };
int duration[] = { 250, 125, 125, 250, 250, 250, 250, 250 };

void setup() {
  for (int thisNote = 0; thisNote < 8; thisNote++) { // Loop through the notes in the array.
    TimerFreeTone(TONE_PIN, melody[thisNote], duration[thisNote]); // Play thisNote for duration.
    delay(50); // Short delay between notes.
  }
}

void loop() {}

TimerFreeTone Library home page

Tim
58  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: April 23, 2014, 05:44:55 pm
Hi,

I am using 3 HC-SR04 sensors. I tried the sketch but it doesnt even print out anything. What should I do

Check your settings and sketch, as I'm 101% sure it works.  Thousands have used it.  Maybe you don't have the serial baud rate set correctly to match the sketch?

Tim
59  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: April 23, 2014, 04:37:23 pm
@Teckel thank you for this library contribution. Is it possible to use this with an ultrasonic sensor like the Hagisonic HG-M40DAI? Its signal output timing is from rising edge of input pulse (trigger) to rising edge of output pulse (echo). In other words, almost the reverse of sensors like Ping.

Datasheet: http://www.robotshop.com/media/files/pdf/hagisonic-anibat-data-sheet.pdf.

If you're curious why the Hagisonic sensor, this "AniBat" model has the unique advantage (AFAIK) of an extremely wide field of view - 180°.

Thanks,

Eric

It sounds like it's similar to the URM37 sensor (hi/low switched).  I'm sending you a private message that may help.

Tim
60  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: April 11, 2014, 10:13:35 am
Got it working on my obstacle avoidance robot with three SR04 sensors up front and it is working very well.   Great improvement.

The "multi-tasking" or maybe I should correctly stay "event-driven" or "task-switching" method of pinging even one sensor that NewPing uses is a vast improvement over other methods.  Using multiple sensors multiplies this improvement.  Glad it's working for you!

Tim
Pages: 1 2 3 [4] 5 6 ... 35