Germany
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino in Visual Studio MODE
|
 |
« on: March 08, 2013, 09:22:38 am » |
hey gays i want to make my dc motor to run with a Precision potentiometer. 10 gears left and right when the max or min position its achieved and from reading the serial the motor should position it self have written some simple code but don't now how to do it further (didn't make this yet) so heave some understanding and if your could help me further i did it appreciated int Enable_A=13; int Enable_B=8; int Input_1=12; int Input_2=11; int Input_3=10; int Input_4=9; int Poti=A0; int val;
void setup() { Serial.begin(115200); Serial.println("REEDY"); pinMode(Enable_A,OUTPUT); pinMode(Enable_B,OUTPUT); pinMode(Input_1,OUTPUT); pinMode(Input_2,OUTPUT); pinMode(Input_3,OUTPUT); pinMode(Input_4,OUTPUT); }
void loop() { while(Serial.available() > 0) { char aChar = Serial.read(); if (aChar=='1') { Motor_ON(); Serial.print("Motor_ON and running 1_3 "); Motor_1_3(); Motor_OFF(); }
if (aChar=='2') { Motor_ON(); Serial.print("Motor_ON and running 2_4 "); Motor_2_4(); Motor_OFF(); } if (aChar=='3') { Potie(); } } }
void Motor_ON() { digitalWrite(Enable_A,HIGH); digitalWrite(Enable_B,HIGH); }
void Motor_OFF() { delay(100); digitalWrite(Enable_A,LOW); digitalWrite(Enable_B,LOW); Motor_Coast(); Serial.println("STOP"); }
void Motor_1_3() { digitalWrite(Input_1,HIGH); digitalWrite(Input_2,LOW); digitalWrite(Input_3,HIGH); digitalWrite(Input_4,LOW); }
void Motor_2_4() { digitalWrite(Input_1,LOW); digitalWrite(Input_2,HIGH); digitalWrite(Input_3,LOW); digitalWrite(Input_4,HIGH); }
void Motor_Coast() { digitalWrite(Input_1,LOW); digitalWrite(Input_2,LOW); digitalWrite(Input_3,LOW); digitalWrite(Input_4,LOW); Potie(); }
void Potie() { val=analogRead(Poti); Serial.print("Poti = "); Serial.println(val); }
|
|
|
|
« Last Edit: March 08, 2013, 10:16:47 am by THX_RoG »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: March 08, 2013, 09:45:55 am » |
i want to make my dc motor to run with a 10 gang poti links and right I'm assuming "links" means "left", but "10 gang poti" has me stumped.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Germany
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino in Visual Studio MODE
|
 |
« Reply #2 on: March 08, 2013, 10:15:41 am » |
heh ok edited sorry for that it should be Precision potentiometer. 10 gears
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: March 08, 2013, 10:27:47 am » |
No, sorry still not making a lot of sense (to me anyway). Are you saying there's a 10:1 gear ratio there? Or it is a ten turn potentiometer?
Are you saying you're trying to make a DC servo motor?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Germany
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino in Visual Studio MODE
|
 |
« Reply #4 on: March 08, 2013, 10:56:46 am » |
1. yes it have 3600° turn so its 10 turn potentiometer 2. yes over a h-bridge controller
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Online
God Member
Karma: 18
Posts: 839
Have you testrun your PDE file today?
|
 |
« Reply #5 on: March 08, 2013, 01:24:33 pm » |
Which bit of the program do you need help with? I can understand your test program.
What is the next step? I think to ask the motor to turn until a specific value is reached on the potentiometer. Initially hardcode the targetvalue in the program, making it dynamic from the serial port (or other source) comes later.
To avoid damaging you potentiometer, you can manually turn the potentiometer and see the motor move or not. Mechanically couple the two together when everything works.
In loop(), when not doing serial (ie when available()==0) check the pot value. If it is less than targetvalue call motorturn one direction. If it is more than targetvalue call motor turn other way.
Check that when you manually turn the knob you can make the motor tun one or other way.
The targetvalue test has to include a dead band, ie the test should be less than magicvalue-5 or greater then targetvalue+5
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino in Visual Studio MODE
|
 |
« Reply #6 on: March 08, 2013, 02:00:53 pm » |
u help a little now i need to write this code but basic it should look like this arduino read a value from serial.read and then motor turn left or right till my value is true
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Online
God Member
Karma: 18
Posts: 839
Have you testrun your PDE file today?
|
 |
« Reply #7 on: March 08, 2013, 03:32:07 pm » |
then motor turn left or right till my value is true You need to be specific here. Which value? What makes the value "true"? (In C, anything that is not zero is "true" - but you mean something else here, I think) In fact, the more specific and very clear you are, the easier it is to write the program. In fact that is how you write a program. You start of with a vauge idea. Then write a few sentences describing it in more detail. Then change each of those sentences into several with more excruciating detail. And again. And then suddenly you have written it in so small steps, that it is trivial to translate to C.
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino in Visual Studio MODE
|
 |
« Reply #8 on: March 08, 2013, 03:38:33 pm » |
value its form 0 to 1023 and if the serial.read input its lets see 500 then this while by my true value if the potentiometer "say so"
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Online
God Member
Karma: 18
Posts: 839
Have you testrun your PDE file today?
|
 |
« Reply #9 on: March 08, 2013, 03:57:47 pm » |
That is what I suggested. But take it in small steps. First write a program that calls your motor left/right code if the analogRead() is above/below a fixed value.
Search this forum for "nnnC" - it is a small function I wrote to send decimal values and a command letter using Serial. Good for quick debugging code/prototypes.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6553
Arduino rocks
|
 |
« Reply #10 on: March 08, 2013, 04:40:26 pm » |
One fairly inexpensive setup might be to take a standard servo, mechanically modify it for continous rotation, remove the internal pot and externally connect the 10 turn pot. Connect the pot to the gizmo being rotated and use the servo to rotate the gizmo. The below shows the general idea. http://www.servocity.com/html/belt_drive_pan_systems.html
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino in Visual Studio MODE
|
 |
« Reply #11 on: March 09, 2013, 08:06:47 am » |
om trying to write some code but it dont work have no clue void Motor() { val1=targetval1; val2=targetval2; if (targetval1!=targetval2) { Motor_ON(); { if (targetval1<targetval2) { Motor_1_3(); } if (targetval1>targetval2) { Motor_2_4(); } } } if (targetval1=targetval2) { Motor_OFF(); } } im using now 2 potentiometer one its mechanically paired with dc motor and the other its for putting my values
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6553
Arduino rocks
|
 |
« Reply #12 on: March 09, 2013, 09:58:34 am » |
Have you looked at the "knob" servo example in the arduino IDE?
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Jr. Member
Karma: 0
Posts: 53
Arduino in Visual Studio MODE
|
 |
« Reply #13 on: March 09, 2013, 10:24:28 am » |
yes im trying to "modifying" this code for my purpose
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6553
Arduino rocks
|
 |
« Reply #14 on: March 09, 2013, 11:10:46 am » |
The below code is for servos and different from your motor setup, but it includes a deadband setup that may eliminate position hunting by the motors. In your code you should add printing the generated values and such to the serial monitor so you can see if you are getting what you expect. //zoomkat dual pot/servo test 12-29-12
#include <Servo.h> Servo myservo1; Servo myservo2;
int potpin1 = 0; //my pot pin int potpin2 = 1;
int newval1, oldval1; int newval2, oldval2;
void setup() { Serial.begin(9600); myservo1.attach(2); myservo2.attach(3); Serial.println("testing dual pot servo"); }
void loop() { newval1 = analogRead(potpin1); newval1 = map(newval1, 0, 1023, 0, 179); if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ myservo1.write(newval1); Serial.print("1- "); Serial.println(newval1); oldval1=newval1; }
newval2 = analogRead(potpin2); newval2 = map(newval2, 0, 1023, 0, 179); if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){ myservo2.write(newval2); Serial.print("2- "); Serial.println(newval2); oldval2=newval2; } delay(50); }
|
|
|
|
|
Logged
|
|
|
|
|
|