Using 2 Servos and a Display

Hello,

I am new to the community and also new to the world of programmable micro controllers. That said I am very interested in automating a very mundane pair of tasks at my work. I operate a cnc lathe that is attached to a plc which uses a magnet to bring my work piece into and away from the machine. I have a joystick on one control panel and I have a button on another. I would like to use the uno as an intermittent delay timer to control these button presses to free me up to preform other mandated tasks. So far I have figured out how to program the uno with windows and how to use a transistor to power a load. I have written a simple sketch that intermittently blinks two leds as proof of concept but I am looking to do more. I purchased a display and two Rheostats in the hopes that I can set up the board to give me visual feed back of the time delay and use the rheostats to trim the delay. I would just like to know your opinions on the feasibility of this and link me to some sources to help me get started with this project. I would like to thank the members of this board in advance for any and all help and advice and I would also like to apologize for running right in here and starting a new thread. I did try the search button but the forum is quite large and rather unwieldy to a new user. I am sure as time goes by and I become a more active member of the community it will become easier to navigate the forum and I will become a more useful poster.

1202067:
I have a joystick on one control panel and I have a button on another. I would like to use the uno as an intermittent delay timer to control these button presses to free me up to preform other mandated tasks.

You're aiming to have the Arduino operate the button only, or is the joystick involved somehow? Have you figured out how it will know when to operate the 'button', and for how long?

Peter, thank you for the prompt reply. I intend to automate both the joystick and the button. I will be using servos to actuate the exisiting hardware. I will use pulse width (pwm) to insure that the servos make the proper revolution. This end of what I am doing is rather cookie cutter. What I am having trouble wrapping my mind around is how to display and trim the delays.

So far as the scetch goes I have it timed pretty well, but I need to be able to override the delay when I speed up or slow down the machine and I figured using a pot would be the best way.

Does the joystick just operate switches, or is it a proportional control? If it's only operating switches, you could bypass it using relays rather than push it physically with servos. (In my opinion, connecting a few wires and relays into a circuit is easier and more reliable than trying to make hardware assemblies to move things around.)

Is the joystick+button operation going to be free-running on a timed basis, or will it be triggered somehow (and if so, by what)?

PeterH:
Does the joystick just operate switches, or is it a proportional control? If it's only operating switches, you could bypass it using relays rather than push it physically with servos. (In my opinion, connecting a few wires and relays into a circuit is easier and more reliable than trying to make hardware assemblies to move things around.)

Is the joystick+button operation going to be free-running on a timed basis, or will it be triggered somehow (and if so, by what)?

Thank you again Peter,

Your advice is solid and your questions are good and I will address them in turn. I am going to be using this at my place of employment so I can not have a 'foot print' as they would be rather aggitated by me hacking into their hardware. This box will not be long term integrated and must be able to be folded up and stored in my back pack. I understand that it would be better if I could wire in directly and it is unfortunate that I cannot. The joystick is a simple 4 way switch that sends signal to the plc to que up the stepper and move the workpiece it can also (in manual mode) turn the magnet on and off and bring the stepper motor forward or backward incrementally. In automatic mode it ignores all signal but the signal for 'out' and brings the magnet to a preset (programmable) point. After the workpiece has moved to a point in the track where it is clear of obstruction the plc sends a signal to a hydrolic ram that enguages a set of kickers that simultaniously remove one workpiece and que another. The lathe has its own pannel and the only part of the pannel I intend to automate is the 'start' button. This will all be done on strict timing with no sensors. I would like to integrate a set of breakbeams and an acceloromiter but I can't because I am limited by setup time and physical size.

That sounds doable.

My biggest concerns at this stage would be whether there were any safety implications from taking the human intervention out of the system, and whether it was sensible to make modifications to a production system without the owner's permission.

What happens if anything unusual happens to the system such as a jam or misfeed, or somebody knocks the timing adjuster and it starts trying to feed too quickly, or any part of your add-on fails and it starts doing things out of sequence?

PeterH:
That sounds doable.

My biggest concerns at this stage would be whether there were any safety implications from taking the human intervention out of the system, and whether it was sensible to make modifications to a production system without the owner's permission.

What happens if anything unusual happens to the system such as a jam or misfeed, or somebody knocks the timing adjuster and it starts trying to feed too quickly, or any part of your add-on fails and it starts doing things out of sequence?

I understand your concerns and trust me I am a rational hairless ape. It is not that this will be done without permission, as I have the green light from special projects and from my immediate so long as this does not interfere with current production practices. Also I will still be at my work station to hit the reset button should anything untoward happen. There is a minimal risk that a workpiece may not be worked when it is ejected or that it may be deformed and not meet our quality standards but there is no risk of injury stemming from making these two steps automated. Should this proof of concept be deemed viable it will be adopted. I also don't intend to bring the box up to work and use it until I have fully tested it. I could use it as it sits now with no display and no override but it would only preform its function at one speed. If it where variable it would be much more useful.

I tend to agree with PeterH. Even though, you are not attaching wires to the CNC, and instead using a servo to press a button or operate a joystick, make sure your boss is comfortable with your gadget before attaching that. To that end, it may make sense to make your project more finished looking, that your normal Arduino setup with wires running out. Otherwise it will look like a bomb or hacker tool like seen in too many bad movies. Depending on the equipment, there may be legal issues of putting anything on the machine.

Ok, assuming you can actually put your gizmo on the CNC machine, is it doable? From what I understand of what you want to do yes it is doable, but is it doable by somebody who is just starting out in a finite amount of time? Perhaps, perhaps not. If you've never done a big programming assignment before where you are creating a new program, rather than just taking an example program and modifying a simple variable, you will learn in this project, but it will take longer. After being a programmer for 34 years, I know how to go about creating the program, but honestly, I don't know how to teach somebody to think like a programmer. My experience is there are some people that grasp it quickly, and some take much, much longer, and often need somebody locally to guide them.

You have at least several steps, and I would recommend tackling each separately, rather than trying a big bang theory where everything must work at once.

The first step is to read a button press and rig up a servo to press a different button. Here, I would use a potentiometer or trim pot on an analog input pin, so that you can control the position to position the servo, rather than iterating, changing the value in the program, and downloading it. You want to use an actual button, connected to a self contained light setup (or a second arduino) rather than just blinking a light, since the point of the exercise is to actually press a button. It will make things simpler if you get a button similar to the button on the CNC machine. You likely will want to keep the variable control, so that you can adjust things when you get to the shop. Then if you need to press the button for a set period of time, do that here.

The second step is to operate the joystick. You probably need 2 different servos, one to operate in the x axis, and the other in the y axis. You really want to get a joystick like your cnc machine to use in your test setup. I tend to think a second arduino would be useful here, and that arduino reads the value of the joystick, and prints it out to the serial monitor. That way you can calibrate the movement of the two servos. Again, if you need to use timing controls, you would add it here.

The third step is doing the display. If you have a second Arduino, you could put the display on that Arduino for starters, to display the x/y axis, etc. You want to iterate on the display until you find something you are comfortable using. I suspect a graphic display is probably more useful than a text display, but the programming is harder. Note, I have discovered that servos on the Uno disable PWM on two pins (9 & 10), and some LCD shields want to use 9/10 to control the display. If you need to have the display, then you probably want to go with a display that is connected via i2c or spi, instead of using direct pins.

The fourth step is putting it together. One of the key things to think of is when you have multiple controls, you almost never want to use the delay function. Instead you want to study the blink without delay example, until you understand it. You will need to write the parts as a state machine, so that every step, you say is it time to do action X, Y, or Z?

If you are wanting to have several trimpots to control the degrees of freedom, you may find an Uno doesn't have enough pins. There are various ways to multiplex pins, etc, but it may be useful to think about going to a Mega which has more pins.

Be sure to back up your sketches, particularly when you come to a stopping point, it is useful to have backups. That way you can always go back to a know position.

MichaelMeissner:
I tend to agree with PeterH. Even though, you are not attaching wires to the CNC, and instead using a servo to press a button or operate a joystick, make sure your boss is comfortable with your gadget before attaching that. To that end, it may make sense to make your project more finished looking, that your normal Arduino setup with wires running out. Otherwise it will look like a bomb or hacker tool like seen in too many bad movies. Depending on the equipment, there may be legal issues of putting anything on the machine.

Ok, assuming you can actually put your gizmo on the CNC machine, is it doable? From what I understand of what you want to do yes it is doable, but is it doable by somebody who is just starting out in a finite amount of time? Perhaps, perhaps not. If you've never done a big programming assignment before where you are creating a new program, rather than just taking an example program and modifying a simple variable, you will learn in this project, but it will take longer. After being a programmer for 34 years, I know how to go about creating the program, but honestly, I don't know how to teach somebody to think like a programmer. My experience is there are some people that grasp it quickly, and some take much, much longer, and often need somebody locally to guide them.

You have at least several steps, and I would recommend tackling each separately, rather than trying a big bang theory where everything must work at once.

The first step is to read a button press and rig up a servo to press a different button. Here, I would use a potentiometer or trim pot on an analog input pin, so that you can control the position to position the servo, rather than iterating, changing the value in the program, and downloading it. You want to use an actual button, connected to a self contained light setup (or a second arduino) rather than just blinking a light, since the point of the exercise is to actually press a button. It will make things simpler if you get a button similar to the button on the CNC machine. You likely will want to keep the variable control, so that you can adjust things when you get to the shop. Then if you need to press the button for a set period of time, do that here.

The second step is to operate the joystick. You probably need 2 different servos, one to operate in the x axis, and the other in the y axis. You really want to get a joystick like your cnc machine to use in your test setup. I tend to think a second arduino would be useful here, and that arduino reads the value of the joystick, and prints it out to the serial monitor. That way you can calibrate the movement of the two servos. Again, if you need to use timing controls, you would add it here.

The third step is doing the display. If you have a second Arduino, you could put the display on that Arduino for starters, to display the x/y axis, etc. You want to iterate on the display until you find something you are comfortable using. I suspect a graphic display is probably more useful than a text display, but the programming is harder. Note, I have discovered that servos on the Uno disable PWM on two pins (9 & 10), and some LCD shields want to use 9/10 to control the display. If you need to have the display, then you probably want to go with a display that is connected via i2c or spi, instead of using direct pins.

The fourth step is putting it together. One of the key things to think of is when you have multiple controls, you almost never want to use the delay function. Instead you want to study the blink without delay example, until you understand it. You will need to write the parts as a state machine, so that every step, you say is it time to do action X, Y, or Z?

Thank you Michael,

You have given me some great ideas on how to simulate the environment at my workspace for testing and some nice solid advice on programming. Thank you. I have a display up and running and I have the servos operating intermittently. I still don't know how to get the display to show me the delay time and I don't know how to program the board to accept the information from the rheostats. I will get it it will just take some time. I was hoping that I could get a nudge in the right direction for what to read on implementation of menus, displays and analog sensors but alas I have not. I suppose I will bust out my shovel and get digging.

I am glad to see the level of concern for safety and the respect of property from this community. I assure you I would not endanger myself or others in any way to take a 'short cut'. I do have permission from our 'special projects' department and my immediate. It looks like I have a lot of digging to do so I am gonna take off. I will show you guys what I have got when I am done. Remember to rest easy, there is absolutely no way two servos are going to throw a 32' workpiece across the production line and injure anyone. It is doing exactly what I do the exact same way.

I see the timing and configuration as relatively simple and straightforward, which is why I'm focusing on safety first, and the hardware second. The software will be the simple part and I take it for granted that you can sort that out.

What sort of movements do you need to perform to operate the joystick and switch? Is it just one axis, or two? Does the joystick position need to be controlled accurately, or is it sufficient to just pull it against a stop? How much force and distance would be required to achieve that? Similarly for the button - how much force and distance will be required?

PeterH:
I see the timing and configuration as relatively simple and straightforward, which is why I'm focusing on safety first, and the hardware second. The software will be the simple part and I take it for granted that you can sort that out.

What sort of movements do you need to perform to operate the joystick and switch? Is it just one axis, or two? Does the joystick position need to be controlled accurately, or is it sufficient to just pull it against a stop? How much force and distance would be required to achieve that? Similarly for the button - how much force and distance will be required?

Well honestly not much. I was originally going to use in line solenoids instead of servos to conserve battery life but I scrapped that for the simplicity of the servo. I will be using a cam on the servo to power a push rod on the button and will be using an adjustable mount (a lot like a worm screw) to move the servo closer or further away as needed so absolute accuracy is not necessary. The process for the joystick will be virtually identical minus the push rod. I will use the cam directly to trigger the joystick. I will be laser cutting the mounts out of acrylic when I get the servos in next week. I have 'most' of the planning for the mounts done but it depends on the amount of space the servos take up. I have not measured the force to trigger either the joystick or the button but it is very minimal.

The joystick is a simple 4 way switch. When you close one of the points the signal goes to the plc (programmable logic controller) and gets distributed from there. When in automatic mode the only signal the plc will take is the signal called 'out' which will open the clamp rollers, engage the magnet and start the stepper motor. After the workpiece is clear from obstruction the magnet turns off and the ram hits the kicker. This indexes a new work piece and ejects the old one. When the kickers come to rest the magnet engages and the stepper brings the workpiece into the stop inside the cnc. As you can see there is a fair bit of automation already. The joy stick is not used as anything other than a switch and does not need a specific amount of pressure applied to it (short of the pressure required to close the switch and send the signal).

That all sounds very sensible.

I don't know how many timing parameters you want to be able to adjust on the fly, but for each parameter you could install a rotary potentiometer with a knob that is has a marker which can be referred against a scale to give a value in minutes, seconds, or however else you want to arrange it. It doesn't particularly matter what units you choose or how much travel that takes on the pot or anything like that, because you'll map the pot position to the time value in software. Round here there is plenty of choice of pots, knobs, dials and so on in hobby electronic shops and I expect there will be in your area too. Suggest you provide some sort of protection to make sure the timing doesn't get mucked up by somebody walking past - perhaps put the adjustment pots under a cover, or use smaller pots that have to be turned by screwdriver so they can't be moved by accident. But that is all just a matter of practicality, which only you can sort out.

So the consensus is yes, it is possible. I will be working on the software from here on out as I have already chosen the hardware. I will be using rheostats instead of pots because well, that is what I have. Getting components out here in the sticks is like pulling teeth. I have been entertaining the idea of starting an electronics club in my community and asking my local suppliers to carry more items but honestly there does not seem to be a lot of interest. I enjoy messing with this stuff but I seem to be the only person buying anything. I digress. Do you have any ideas where I can start looking for information on how to get started with my programming? Maybe some suggested reading? I have already read getting started with arduino and it did have quite a bit of information in it but it was quite light and was a bit too cookie cutter. I want to know how to code in general (a full list of commands and the like) not just how to blink a light.

On the hardware side I intend to use pins 10 and 11 for the signal for the servos, pins a0 and a1 for the rheostats and the tx pin (and gnd and a regulated 5v power source from a bread board [which will also power the servos]) for the display. I will be going through a couple of MOSFET transistors to power the servos and have already wired everything up on the bread board (I should learn how to fritz). I am wondering (among other things) if I should use pwm to control the servo rotation or if I should time the one steady pulse to save wear and tear on the transistors.

The display that I have is the TinkerKit! one and I may not even need the uno (as it is a Leonardo on its own) but I intend to use it anyway.

Thank you again for all the help so far and I look forward to knowing enough to be able to give something back.

You will need to power the servos with a source with the correct voltage for them, and capable of supplying their maximum current. That wouldn't normally involve MOSFETS, just a power supply of the appropriate voltage and current.

The path I'd suggest for you is start by connecting a servo and moving it through a hard-coded sequence of positions just like the servo example sketches, get used to the concepts in the 'blink without delay' example sketch and use that approach to move the servo through a timed sequence of positions without making the sketch stop and wait for each movement, then replace the fixed (constant) timing with timing controlled by variables - which will initially be left unchanged so they will behave the same as constants. Then connect up one of your pots and add code to read the position via analogRead, and map the analog value into your required timing delay. Finally update the servo timing variable with the value you have calculated so that the servo timing varies as you move the pot.

Once you have that working with one servo and one pot, it's "just" a small matter of using the same approach to implement your full multi-servo system with multiple control pots.

Make sure you keep copies of your working sketches as you go, so you can go back to a previous working solution if you find your code has gone in a bad direction.

PeterH:
You will need to power the servos with a source with the correct voltage for them, and capable of supplying their maximum current. That wouldn't normally involve MOSFETS, just a power supply of the appropriate voltage and current.

The path I'd suggest for you is start by connecting a servo and moving it through a hard-coded sequence of positions just like the servo example sketches, get used to the concepts in the 'blink without delay' example sketch and use that approach to move the servo through a timed sequence of positions without making the sketch stop and wait for each movement, then replace the fixed (constant) timing with timing controlled by variables - which will initially be left unchanged so they will behave the same as constants. Then connect up one of your pots and add code to read the position via analogRead, and map the analog value into your required timing delay. Finally update the servo timing variable with the value you have calculated so that the servo timing varies as you move the pot.

Once you have that working with one servo and one pot, it's "just" a small matter of using the same approach to implement your full multi-servo system with multiple control pots.

Make sure you keep copies of your working sketches as you go, so you can go back to a previous working solution if you find your code has gone in a bad direction.

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.

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!

//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);
}

1202067:
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.

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.

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.

//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);
}

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.