Pages: [1]   Go Down
Author Topic: How to add Ping))) to this code  (Read 905 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was wondering how and where would I put the code for PING))) in the code below and how would I wire this to a L298N H-Bridge?


Code:
int PWM1  = 6;  // PWM Pin Motor 1
int PoM1  = 7;  // Polarity Pin Motor 1
int PWM2  = 5;  // PWm Pin Motor 2
int PoM2  = 4;  // Polarity Pin Motor 2

int ValM1  = 0;  // Initial Value for PWM Motor 1
int ValM2  = 0;  // Initial Value for PWM Motor 2

int i = 25;  // increment
boolean goUp = true;  // Used to detect acceleration or deceleration


void setup()
{
  pinMode(PWM1,  OUTPUT);
  pinMode(PoM1,  OUTPUT);
  pinMode(PWM2, OUTPUT);
  pinMode(PoM2, OUTPUT);
  
  digitalWrite(PoM1, LOW);  // Both motors with the sam polarity
  digitalWrite(PoM2, LOW);
  
  analogWrite(PWM1, ValM1);  // Stops both motors => ValMx = 0
  analogWrite(PWM2, ValM2);  
  Serial.begin(9600);        // Used to check value
}

// Main program

void loop()
{
  delay (500);                 // Give time to theh motor to adapt to new value
  if ((ValM1 < 250) && goUp)  // First phase of acceleration
  {
    ValM1 = ValM1 + i;  // Increase PWM value => Acceleration
    ValM1 = ValM1 + i;
  }
  else
  {
    goUp = false;        // Accerleration completed
    ValM1 = ValM1 - i;  // Decrease PWM => deceleration
    ValM2 = ValM2 - i;
    if (ValM1 < 75)
    {
      ValM1 = 0;
      ValM2 = 0;
      goUp =
      true;
    }
  }
  if ((ValM1 > 75) && ((ValM1 < 255)))
{
    analogWrite(PWM1, ValM1);
    analogWrite(PWM2, ValM2);
  }
  Serial.print(ValM1);
  Serial.print("\t");
  Serial.print(ValM2);
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do you want to wire a Ping to an H-bridge?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://en.wikipedia.org/wiki/Ping

I doubt it can be done.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@AWOL

I want to attach the Ping))) and L289N to an Arduino board to control two motors.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you had a look at the Playground?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's the basic code to use the PING)))  The tone is to hook up to a piezo speaker, and it changes pitch based off the distance.  I'm not entirely sure what you want to do with it, but if you needed the code, here you go.

Code:
int tone_freq=0;
  long duration, inches;
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
  delayMicroseconds(2);
  digitalWrite(3, HIGH);
  delayMicroseconds(5);
  digitalWrite(3, LOW);
  pinMode(3, INPUT);
  duration = pulseIn(3, HIGH);
  Serial.print(148, BYTE);
  Serial.print(duration);
  inches = (duration/2)/74;
  Serial.print(137, BYTE);
  Serial.print(inches);
  delay(100);
  tone_freq= inches*100;
  tone(2,tone_freq);
Logged

SF Bay area
Offline Offline
Sr. Member
****
Karma: 2
Posts: 266
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://en.wikipedia.org/wiki/Ping

I doubt it can be done.

I think he meant this
http://arduino.cc/en/Tutorial/Ping

Ping != Ping)))
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have searched the internet for about four hours trying to find a good example on how to wire and Arduino Mega, L289N Motor Control, and a Parallax Ping))) all together? I was tired of searching the internet and didn't look on the forum. If you know how or know of a good/great example that shows how and with some code, could you point me in that direction?

Thank you.

P.S. I did wire every but I didn't power it up since I am afraid that I would fry my Mega and I have already did that once.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I have to merge another of your duplicate posts, I'm going to start deleting them.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was wondering why are you merging them? My first question was about coding and the second question was about wire them altogether. 
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or, in the first case, both
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how to wire and Arduino Mega, L289N Motor Control, and a Parallax Ping))) all together?

How about a link to the datasheet for this Ping thing?
Logged

Pages: [1]   Go Up
Jump to: