Offline
Newbie
Karma: 0
Posts: 46
|
 |
« on: May 02, 2012, 09:51:00 pm » |
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? 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
Brattain Member
Karma: 137
Posts: 19006
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: May 03, 2012, 03:09:24 am » |
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.
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #2 on: May 03, 2012, 03:41:33 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 46
|
 |
« Reply #3 on: May 03, 2012, 10:27:55 am » |
@AWOL
I want to attach the Ping))) and L289N to an Arduino board to control two motors.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19006
I don't think you connected the grounds, Dave.
|
 |
« Reply #4 on: May 03, 2012, 12:20:37 pm » |
Have you had a look at the Playground?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 51
Arduino rocks
|
 |
« Reply #5 on: May 03, 2012, 01:48:50 pm » |
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. 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
Full Member
Karma: 0
Posts: 156
|
 |
« Reply #6 on: May 03, 2012, 03:25:26 pm » |
I think he meant this http://arduino.cc/en/Tutorial/PingPing != Ping)))
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 46
|
 |
« Reply #7 on: May 03, 2012, 03:29:50 pm » |
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
Brattain Member
Karma: 137
Posts: 19006
I don't think you connected the grounds, Dave.
|
 |
« Reply #8 on: May 03, 2012, 03:48:02 pm » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 46
|
 |
« Reply #9 on: May 03, 2012, 03:53:43 pm » |
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
Brattain Member
Karma: 137
Posts: 19006
I don't think you connected the grounds, Dave.
|
 |
« Reply #10 on: May 03, 2012, 03:57:31 pm » |
Or, in the first case, both
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #11 on: May 03, 2012, 04:54:03 pm » |
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
|
|
|
|
|
|