I have a wireless IP camera with Pan/Tilt capability. When you tell the camera to pan left or right the main board in the camera tells a small five wire stepper motor which way to move. I would like to get rid of the stepper motors and use the arduino to read the pins coming from the main board that would go to the stepper motors. Based on the state of the pins I want the arduino to react in a certain way. I understand that the simple answer is to do an analogRead() on the pins, but I don't completely understand the way a signal is sent to the stepper motor to determine the direction that it turns. Any information at all would be completely helpful, and any links will be appreciated. I can provide pictures of the stepper motors or the main board of the camera if at all helpful. Thank you so much in advanced for any information or advice
Sorry for the question seeming bizarre. I have built a complete arduino robot base and I am trying to accomplish the question that I asked so that when I press the forward button that would make the camera tilt up, I can have the arduino intercept the signal and move the whole robot base forward and vice versa. I want to accomplish the same with right and left. I guess what I am really trying to figure out is how a five wire stepper motor works. I have done a lot of research on trying to figure out how a stepper motor works and all I can come up with is people talking about the permanent and electromagnets on the inside. What I particularly wanna know is what wires are used to are made high or low to determine the motion of the stepper motor. I may be wrong but a lot of the diagrams I have seen lead me to the conclusion that to make the motor move all of the electromagnets inside are switched off and on very quickly and that all of this is done by the control board. If this is the case, how would the arduino be able to interpret these fast changing signals? Thanks in advance for any replies. All information is helpful.
If this is the case, how would the arduino be able to interpret these fast changing signals?
You write a program to do this.
To see how stepping motors work see:-
http://www.thebox.myzen.co.uk/Workshop/Motors_3.html
and
Grumpy. Can you give any advice as to what the program would look like? I just don't understand what combination of functions you would be able to use to interpret the time between when each of the wires goes high or low.
give any advice as to what the program would look like?
It would monitor the state of the signals on the coils using the digital read (not analogue).
Then it would wait until it changed. Then using a look up table it would compare the state it was to the state it is now, to see if it was a step clockwise or anti clockwise. You might use this to increment or decrement a running total which will indicate what degree of turn the motor has made. Your code would then do something with that information.
You would probably monitor the state of the lines using an interrupt service routine driven by the pin change interrupt.
It really isn't a beginners project.
You would probably monitor the state of the lines using an interrupt service routine driven by the pin change interrupt.
Could you please explain in noobie terms what this means? Thank You
Moderator edit: fixed the end quote tag.
To make it a beginners project, I would have you mechanically couple a pot to the existing stepper motor shaft or on the tilt or pan rotation axis and read the position as a analog input voltage with the pot wired as a voltage divider. A little calibration set-up and you would have a simple stepper motor monitor for the camera pan/tilt assembly, needing one pot for each motor.
Note that this simple method would not work for stepper motors applications where the motor turns multiple revolutions.
Lefty
I guess what I am really trying to figure out is how a five wire stepper motor works.... What I particularly wanna know is what wires are used to are made high or low to determine the motion of the stepper motor.
A stepper motor is not controlled by making certain wires high or low in a static manner as for DC motors. In simple terms a stepper motor is controlled by the sequence of patterns sent to its electromagnets. The specific pattern sequence determines the direction of rotation and the time between patterns in that sequence determine its speed.
With this information in mind go back and re-read reply #7.
Don
Okay, so it is a 5v stepper motor. I started by attaching the ground of the arduino to the common on the stepper motor. I then attached pin A0 on the arduino to one of the other wires of the stepper motor and left the stepper motor plugged in to the main board of the camera. I ran the example sketch AnalogReadSerial on the arduino and opened the serial monitor. I had to adjust the baud rate and the speed that the stepper motor would spin at when you told the camera to turn right, and basically what I got is a lot of data about how long the wire remains high or at 0 when you tell the camera to turn right. I need to monitor the state of another wire on the stepper motor at the same time so that I know which wire goes high first when it is spinning a certain direction. I am beginning to understand the concept of what I am going to have to do, but I still do not understand the programming side. Basically, I need the program to use a variable and when the red wire goes high then low, then the yellow wire goes high then low, then the brown wire goes high then low (the motor is turning right) to make val=0, if none of the wires are doing anything (the motor is not doing anything) to make val=1 and when the brown wire goes high then low, then the yellow wire goes high then low, then the red wire goes high then low (the motor is turning left) to make val=2. (I'm not sure if val is the correct function to use here, but I hope you understand the point that I am trying to make) And also do the same thing for the other stepper motor, using a different variable. I could then use the variable and say if val=0, digitalWrite (12, HIGH) (make the robot turn right). I really dont wanna ask anyone to do this for me, but if someone would like to, I'd be happy to send some money in compensation. Otherwise, I really need someone to teach me or at least point me in the direction of some similar code so that they could help me piece together some working code for this. I'm completely open to any new ideas about doing this, or any criticism that can be helpful. Thank you so much in advance for any help. I really appreciate it.
I started by attaching the ground of the arduino to the common on the stepper motor.
You are very lucky this did not damage your arduino because mostly the common line is at 5V and the coils pull low.
I then attached pin A0 on the arduino to one of the other wires of the stepper motor
So what bit about:-
It would monitor the state of the signals on the coils using the digital read (not analogue).
did you not understand?
I hesitate to tell you this because you are clearly many times out of your depth but here goes.
You need to get all four coil states into one variable, each coil state (high or low) should correspond to a separate binary bit in the variable. This can be done with either a direct read of a digital port (see port manipulation tutorial) or by shifting the pin states one at a time into a variable.
You will now have a number with a value from 0 to 15. This represents the state of the coils. Now given any number there are only two numbers for the next state depending on if the motor turned a step clockwise or anticlockwise. So you keep reading the bits into a variable until it changes and see if it has changed to the clockwise or anticlockwise number. If it has changes to another number it means you have missed a step and so you failed to track the motor.
Checking this number can be done in many ways, perhaps the simplest is using two arrays. The index of the array represents the number currently read, the contents of the array is for the next number. One array for clockwise and another for anticlockwise.
Please note that this IS the newbie explanation.
I guess this is where I should have started, but would you be willing to help me create a simpler project to help me understand this concept. Maybe instead of reading stepper motor pins, read the digital input from a button. Would you be willing to help provide some annotated code? Or maybe there is a project already like this with a tutorial somewhere? Im sorry I jumped in way over my head. The project seamed like a very simple one when I first began. Thanks to everyone for their patience. Thanks in advance.
As an easier example: If you have four buttons and each was labeled Button A, Button B, Button C, and Button D. And you had two LED's labeled LED 1 and LED 2. If you press the buttons in the order of ABCDABCD..., BCDABCD..., CDABCD..., or DABCDABCD..., as long as the buttons are being pressed in alphabetical order, no matter which letter you start at, LED 1 will be on. To explain more, you have to press the buttons in order from left to right until you get to button D then start back at A. As long as the pattern is happening, LED 1 will be on. as soon as the buttons stop being pressed in that pattern, the LED turns off.(The buttons would be HIGH when pressed and LOW when not pressed)
Additionally, If the buttons are pressed in the order of DCBADCBA..., CBADCBA..., BADCBA..., or ADCBADCBA..., as long as the buttons are pressed in reverse alphabetical order, not mattering which button you start at, LED 2 will be on. The same explanation goes for this one, where you have to press the buttons from right to left and as soon as you get to A you continue the pattern at D, then C, then B. As long as the pattern is continuing, the LED will be on. As soon as the pattern stops, the LED turns off.(The buttons would be HIGH when pressed and LOW when not pressed)
I think code that could make this work could help me with my original project, except that the states of the "Buttons" would change much more quickly. The states of the buttons in this example would be the states of the four poles on the stepper motor in my final project.
Thanks in advance again for any help. Sorry my horribly worded questions and my inadequate knowledge on the subject has been such a headache for anyone, but I really appreciate everyone pitching in and trying to help.
I made this video showing my robot and diagrams to try to explain my question better. Please watch it and give any help you can. Thank You.
Video Link : - YouTube
Should I post my video and question in the programming section? Sense I really only need help with programming now.
Can you explain what you mean by "is the motor pin greater than the previous pin? Or less?" ?
Oh, okay. That makes perfect sense. I'm sorry if this is a stupid question with a simple answer, but can you help me put that into code? Would I put the digital reads into variable or integers to be able to do what you are describing?
I too am interested in driving some stepper motors.
However I bought a starter kit http://www.oomlout.co.uk/starter-kit-for-arduino-ardx-p-183.html with which I am pleased.
This is simple to use, has circuits, code, a couple of tiny motors (not starter) and so on.
I am going to work my way up starting with just flashing LEDs.
Once I get to steppers I will probably buy a shield like this http://www.oomlout.co.uk/index.php?main_page=product_info&products_id=207. Then once I know what I am doing I can be a bit more adventurous.
That is a great question. I will find out shortly. But how do I do a digital read on 4 pins that have a common five volts and go LOW separately. Do I connect the five volts of the arduino to the five volts of the common five volt wire on the five wire stepper motor and then connect each of the four pins to a digital pin on the arduino? Would I need to connect the grounds too? Or would I just connect the grounds and not the five volts?
Do I connect the five volts of the arduino to the five volts of the common five volt wire on the five wire stepper motor
No you will damage something.
connect each of the four pins to a digital pin on the arduino
Yes
Would I need to connect the grounds
Yes
would I just connect the grounds and not the five volts?
Yes
Haha thanks. And a very effective way of answering the questions. Im going to use the DigitalRead print to serial to read and print the states of the four pins simultaneously and print out a value of like A=1 B=0 C=0 D=0 and then keep doing that.
If I get A=1 B=0 C=0 D=0 and then A=0 B=1 C=0 D=0 and then A= 0 B=0 C=1 D=0 and then A=0 B=0 C=0 D=1, would that meant that the pins are doing what the first graph that KE7GKP showed in reply #24