Show Posts
|
|
Pages: 1 2 [3] 4
|
|
32
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: code for PWM signals to H bridge
|
on: December 24, 2010, 01:49:07 pm
|
|
I have tested the sketch and it works fine. I had to use outputs 2 and 3, 1 is not a PWM output.
When I try to open 2 transistors using one output it doesn't work???
When I use one transistor I can it works and I have checked direction using leds.
Could there be a timing problem? I checked the transistors and they work fine until I make the base common and it will not work anymore. Even when it's working with one transistor and I only connect the base of the second transistor (so not using collector and emiter) it doesn't work anymore. EDIT: base only works but collector of second transistor connected makes it go bad.
I knew there was magic smoke involved in electronics but apperently there is even more magic???
|
|
|
|
|
33
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: code for PWM signals to H bridge
|
on: December 24, 2010, 09:49:22 am
|
You mean like this? I have broadened the dead-band. int potpin1 = A1; // analog pin used to read the potentiometer voltage int PWMPin1 = 1; // PWM signal to digital pin 1 int PWMPin2 = 2; // PWM signal to digital pin 2 int value1; int value2; int pinread;
void setup() { // nothing happens in setup }
void loop() { pinread == analogRead(potpin1); if (pinread < 482) { value1 = map(pinread, 0, 481, 255, 0); analogWrite (PWMPin1, value1); } else if (pinread > 554) { value2 = map(pinread, 555, 1023, 0, 255); analogWrite (PWMPin2, value2); } else { analogWrite (PWMPin1, 0); analogWrite (PWMPin2, 0); } }
Thanks Groove, fixed it.
|
|
|
|
|
34
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / code for PWM signals to H bridge
|
on: December 24, 2010, 08:10:42 am
|
I'm about to order a small motor and components to build a H-bridge. I have written the following code and compiling gives no trouble. Will this work? I mean to control both directions with one potentiometer so the mapping is very important in this sketch. The value in the first mapping is inverted, will this work? int potpin1 = A1; // analog pin used to read the potentiometer voltage int PWMPin1 = 1; // PWM signal to digital pin 1 int PWMPin2 = 2; // PWM signal to digital pin 2 int value1; int value2;
void setup() { // nothing happens in setup }
void loop() { if (analogRead(potpin1) < 512) { value1 = map(potpin1, 0, 511, 255, 0); analogWrite (PWMPin1, value1); } else if (analogRead(potpin1) > 524) { value2 = map(potpin1, 525, 1023, 0, 255); analogWrite (PWMPin2, value2); } else { analogWrite (PWMPin1, 0); analogWrite (PWMPin2, 0); } }
Thanks, Leo
|
|
|
|
|
36
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: XBEE how does it work?
|
on: December 15, 2010, 03:59:35 pm
|
Thanks, didn't think about latency. I was thinking about an Emaxx type vehicle with an aluminum/plastic sheet on top to put all the stuff on. Getting somewhere however would be more important than getting there fast. (fortunately in this case) There is no real goal in building the car other than learning from it. I made a mistake in my previous post. I meant the esc has to receive a PWM signal from the XBEE/board like the servos do. (I'm getting there slowely, tonight I managed to make a walking string of 8 leds with a potentiometer  )
|
|
|
|
|
37
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: XBEE how does it work?
|
on: December 15, 2010, 11:42:14 am
|
|
I would like to have an Arduino in the controller (stationary) with an XBEE on top.
In my car I only want an XBEE, battery, esc, motor and servo and maybe sensors (have to think of a use for sensors)
Can I use the XBEE in the car to generate the PWM signals for the servos and motor and send back data from the sensors to the controller?
The Arduino in the controller can process the sensor data and send new PWM commands to the car.
|
|
|
|
|
38
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: XBEE how does it work?
|
on: December 14, 2010, 01:39:53 pm
|
|
Ok, thanks. Would it be possible to keep the Arduino in the controller so it won't be bashed around in the car? The XBEE in the car would only have to give PWM signals to the servos and controller and send back info from sensors or maybe other things.
I would like to extend the Arduino pins wirelessly.
|
|
|
|
|
39
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / XBEE how does it work?
|
on: December 13, 2010, 11:31:51 am
|
|
Today I discovered the XBEE and since I play with RC cars I asked myself how it works.
Can I make a panel with a joystick, potmeters and so on and control my car with it? I would need one Arduino board with a XBEE on it and another XBEE in my car. Or do I also need another Arduino board in my car?
It would be nice if I could use the remote XBEE to give the PWM signals to the car and give sensor data (if applicable) back to the base where it can be processed and be turned into steering commands if needed. This way a second board isn't necessary. (it would be a wireless extension of my Arduino pins)
Leo
|
|
|
|
|
41
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / constant for delay
|
on: December 16, 2010, 01:03:26 pm
|
Hi, I'm trying to make some led light walk like on Kit. I'm trying to use a constant for the delay so when I have to change the interval I don't have to change a large number of delay values. This is the code so far but compiling this already gives trouble. void setup() { pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); const int val = 30; } void loop() { digitalWrite(2, HIGH); delay (val); }
After compiling I'm told "'val' was not declared in this scope". I think I just did??? Anybody know how to do it? Thanks,
|
|
|
|
|
44
|
Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: unable to control a servo with Arduino
|
on: December 11, 2010, 09:24:46 am
|
|
You guys rule!
A have connected a 4 cell NiMH receiver pack to the servo and it's working fine now.
Thanks,
Edit: This is the code I used to control 2 servos.
// Controlling servo positions using potentiometers // by Michal Rinott, edited by Leo Groeneveld
#include <Servo.h> Servo myservo1; // create servo object to control servo1 Servo myservo2; // create servo object to control servo2 int potpin1 = 0; // analog pin used to connect the potentiometer int val1; // variable to read the value from the analog pin int potpin2 = 1; // analog pin used to connect the potentiometer int val2; // variable to read the value from the analog pin void setup() { myservo1.attach(9); // attaches servo1 on pin 9 to the servo object myservo2.attach(10); // attaches servo2 on pin 10 to the servo object } void loop() { val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023) val1 = map(val1, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) myservo1.write(val1); // sets the servo position according to the scaled value int sensorValue1 = analogRead(potpin1); val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023) val2 = map(val2, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) myservo2.write(val2); // sets the servo position according to the scaled value int sensorValue2 = analogRead(potpin2); delay(15); // waits for the servo to get there }
Why are these statements "int sensorValue2 = analogRead(potpin2);" in the sketch? I don't understand what they are doing.
|
|
|
|
|