Pages: 1 [2]   Go Down
Author Topic: Using 2 Servos and a Display  (Read 1464 times)
0 Members and 1 Guest are viewing this topic.
TX
Offline Offline
Newbie
*
Karma: 2
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So far this is the code I have written which does not work and should not be posted but will be anyway so I can illustrate what I am thinking and be corrected if need be.  I am not asking for any help with the code and am simply showing it to see if I am on the right track.  As always it is in the public domain and you can feel free to manipulate it use it or modify it.  It is given as is with no expressed or implied cures for ailments and will not make you coffee and eggs in the morning.  As a matter of fact without some effort it won't even work!

Code:
//Kick and Start v 1.1  controls the start and ejection process
int startPin = 11; //start servo signal pin 11
int kickPin = 10; //kicker servo signal pin 10
int trimstartPin = A0; //start time trim pin A0
int trimkickPin = A1; //kicker time trim pin A1
int trimstartValue = 0;
int trimkickValue = 0;

trimstartValue = analogRead(trimstartPin);
trimkickValue = analogRead(trimkickPin);

#include <Wire.h>//Includes Wire Library
#include <LiquidCrystal.h>//Includes LCD Library

void setup() {
  pinMode(startPin, OUTPUT);//Makes pin 11 output
  pinMode(kickPin, OUTPUT);//Makes pin 10 output
  pinMode(trimstartPin, INPUT_PULLUP);//Makes pin a0 analog input
  pinMode(trimkickPin, INPUT_PULLUP);//Makes pin a1 analog input
 
  analogWrite(startPin, 64);//sets PWM for % duty cycle pin 11
  delay(trimkickValue);//Delays action for ~44sec+-5sec depending on value
  analogWrite(kickPin, 64);//sets PWM for % duty cycle pin 10
}
void loop() {
 
delay(trimstartValue);
analogWrite(startPin, 64);
delay(trimkickValue);
analogWrite(kickPin, 64);
}
 
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From my understanding of the arduino I was under the impression I needed a MOSFET transistor to insulate the pin from back feed and to keep from over amping the pin.  Am I under a false assumption?  I am going to use a regulated 5v power supply from my bread board to power the servo and the display and had intended to use the MOSFET to buffer the board from the load.

You're describing the situation when you drive a motor or other load directly from the Arduino - the Arduino's output would need to be amplified via a transistor in that case.

But I thought in your design you would be using servos. In this case the servo itself takes care of that and all you need from the Arduino is a PWM servo control signal that connects to the servo's control input. The servo also needs to have a high current power supply (typically 6V 1A or so, but check the specs for the servo you're using) and the Arduino ground and servo power supply ground need to be connected.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

TX
Offline Offline
Newbie
*
Karma: 2
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is crystal clear.  I did not know that and have been using 3v dc motors so far as an analog for the servos as they arrive and they need to be controlled in that way.  I did not know that the servo would be able to be used right off the shelf.  I found the example sketches yesterday and have begun tinkering with them.  I still can't get the example servo sketch to compile,  but I will get the hang of it.  Thank you for all of your help so far.
Logged

TX
Offline Offline
Newbie
*
Karma: 2
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now I have got this.  This code does compile but still needs quite a bit of work.  Again I am not looking for help with the code simply asking if I am headed in the right direction.  As always the code is in the public domain.  If you want to use it feel free (but you will still be basically writing your own code as this is very unfinished).  Again no promises or warranties expressed or implied.

Code:
//Kick and Start v 1.3  controls the start and ejection process
#include <Wire.h>//Includes Wire Library
#include <LiquidCrystal.h>//Includes LCD Library
#include <Servo.h>//includes Servo Library
#include <matrix_lcd_commands.h>//Includes LCD Matrix Commands Library
#include <TKLCD.h>//Includes TKLCD library

int trimstartPin = A0; //start time trim pin A0
int trimkickPin = A1; //kicker time trim pin A1
int trimstartValue = analogRead(trimstartPin);//sets value to trimstartPin
int trimkickValue = analogRead(trimkickPin);//sets value to trimkickPin
int pos = 0;//default servo position 0

pinMode(trimstartPin, INPUT_PULLUP);//Makes pin a0 analog input
pinMode(trimkickPin, INPUT_PULLUP);//Makes pin a1 analog input


Servo startServo;//defines startServo as a servo
Servo kickServo;//defines kickServo as a servo
startServo.attach(11);//Makes startServo signal pin 11 servo
kickServo.attach(10);//Makes kickServo signal pin 10 servo
for(pos = 0; pos < 360; pos += 120)//defines servo rotation

void setup() {
 
 
  startServo.write(pos);//rotates servo 360* in 120* increments
  delay(trimkickValue);//Delays action for ~44sec+-5sec depending on value
  kickServo.write(pos);//rotates servo 360* in 1* increments
}
void loop() {
 
delay(trimstartValue);
startServo.write(pos);
delay(trimkickValue);
kickServo.write(pos);
}
 
« Last Edit: January 27, 2013, 02:45:41 pm by 1202067 » Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, but the 'copy for forum' function in the Arduino IDE is not actually useful for posting code to the Arduino forum. You need to copy the text of your sketch (CTRL+A, CTRL+C) and paste it into the forum in between CODE tags.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

TX
Offline Offline
Newbie
*
Karma: 2
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well that is useful [/sacrasm]  I edited the post.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, there are various ways the IDE could have been improved, but it's free and it works.

You have some executable code there which is outside a function. It would need to go inside a function to compile. The compiler will point you to it soon enough.

I haven't tried to follow what the code does apart from seeing that it declares servos and moves them around - once you have some hardware and can run the sketch for yourself you'll soon find out whether it does what you need.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

TX
Offline Offline
Newbie
*
Karma: 2
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you.  As I stated the code is far from finished.  I have had to gut it about three times now and I still have not been able to write any code for the display or for the trimmers.  I will get the hardware soon enough and be able to tinker with it and figure out where I need revision.  I still need to introduce the display and set perimeters among other things.  When you told me to check the servo example I found the examples and started digging in to them.  I hacked together some code for the servos and was just wondering if I was on the right track with it.  As it becomes more fleshed out it will be easier to read and you will be more able to see what is going on with it.  From your input I assume that the code for the servos is at least close to something that will work and I am on the right track.  Thank you very much Peter and I appreciate your advice thus far.  I am still reading through example sketches and have MUCH more to do but I am starting out and I am having fun.
Logged

Pages: 1 [2]   Go Up
Jump to: