Firstly, Thank you Adafruit for your wonderfull motor shield.
Sencondly, i would like to ask if it would be possible to link a manual controler ( like a rotary encoder) to the motor shield.
For now, I have the sofware part done, it handles my stepper like a charm. But I would like to add a manual mode to the project. And the most important thing : you should be able to switch between manual mode and computer mode as you like.
The first is part is to understand how to link the rotary encoder to the shield (or directly to the arduino board ? ) in order to make it able to control the stepper motor ( of course, rotation ratio "encoder/motor" should fixed in hardware, 20/1 should be nice) . Then, how to switch to normal computer control or back to the manual control.
Thank you for your help ( and your wondeful work , again) .
Motor shield with manual mode
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield with manual mode
The best way to interface the encoder would be via interrupts - probably pin-change interrupts to avoid conflict with pin 3 which is used by stepper #1. The interrupt handler could call the onestep() funtion in the library on each encoder interrupt.
As for switching between manual and computer control, it is hard to say what is the best way without knowing any of the use cases. The easiest way would be to simply have any manual input override any computer input. So if the knob was being turned, the motor would follow the knob. Another way would be to have a momentary contact button you would hold down to override the computer. Think about what makes the most sense for how you expect it to be used.
As for switching between manual and computer control, it is hard to say what is the best way without knowing any of the use cases. The easiest way would be to simply have any manual input override any computer input. So if the knob was being turned, the motor would follow the knob. Another way would be to have a momentary contact button you would hold down to override the computer. Think about what makes the most sense for how you expect it to be used.
-
- Posts: 6
- Joined: Wed Jun 22, 2011 6:10 pm
Re: Motor shield with manual mode
Actually, it would have few different use cases.
The stepper is used to control a focuser on a telescope. The main objective is to allow full automatic control of the focuser with a computer and perform autofocus . For this task, there is no real need of a manual mode as I can do his part with my software.
But there is two situation where i would like to use the manual mode:
1) Stop autofocus/computer control in case of eventual issue ( computer crash, nervous breakdown, etc...), switch to manual mode and enjoy an easy-to-use remote focus knob/encoder. Maybe return to computer use after that.
2)Enjoy just manual mode in stand alone, without computer link.
At first , I'd rather be able to register in the computer any position change performed in manual mode . But this seems a little hard ( except if the encoder can inform the computer or if i use a second encoder to read the position at any time).
I think that in all cases, i would have to press a switch to engage the encoder ( disengaging by going to ground, I think) .Plus, it would be nice to have a speed control: like a normal speed and a slow speed for precise adjustment.
So, correct me if I'm wrong, to perform successive call of onestep() with the encoder, i would have to connect it to pin 3, an unused pin like pin 2 and to ground with the third branch . But doesn't this means that i will have to upload to the arduino a specific code for manual control each time i want to use it ?
The stepper is used to control a focuser on a telescope. The main objective is to allow full automatic control of the focuser with a computer and perform autofocus . For this task, there is no real need of a manual mode as I can do his part with my software.
But there is two situation where i would like to use the manual mode:
1) Stop autofocus/computer control in case of eventual issue ( computer crash, nervous breakdown, etc...), switch to manual mode and enjoy an easy-to-use remote focus knob/encoder. Maybe return to computer use after that.
2)Enjoy just manual mode in stand alone, without computer link.
At first , I'd rather be able to register in the computer any position change performed in manual mode . But this seems a little hard ( except if the encoder can inform the computer or if i use a second encoder to read the position at any time).
I think that in all cases, i would have to press a switch to engage the encoder ( disengaging by going to ground, I think) .Plus, it would be nice to have a speed control: like a normal speed and a slow speed for precise adjustment.
So, correct me if I'm wrong, to perform successive call of onestep() with the encoder, i would have to connect it to pin 3, an unused pin like pin 2 and to ground with the third branch . But doesn't this means that i will have to upload to the arduino a specific code for manual control each time i want to use it ?
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield with manual mode
It sounds like you want mode switch of some sort to switch over between computer control and manual control. You would wire that to a free digital pin and monitor that in the software. When in manual mode, you would ignpore all computer commands and use the encoder.
The encoder sold in the shop uses 'quadrature encoding' with two digital outputs so that you can determine direction and speed by monitoring changes in phase of the two outputs. For this you will need two digital pins. You could use the interrupt handler to monitor the pulses and calculate speed and direction. You could modify that with your speed control (maybe a pot on an analog pin?) and figure out how many steps you need to move. Each time you need to take a step, you call the onestep() function in the library.
The encoder sold in the shop uses 'quadrature encoding' with two digital outputs so that you can determine direction and speed by monitoring changes in phase of the two outputs. For this you will need two digital pins. You could use the interrupt handler to monitor the pulses and calculate speed and direction. You could modify that with your speed control (maybe a pot on an analog pin?) and figure out how many steps you need to move. Each time you need to take a step, you call the onestep() function in the library.
-
- Posts: 6
- Joined: Wed Jun 22, 2011 6:10 pm
Re: Motor shield with manual mode
Hello
I made some progress since the last post ( and undestood some basic things...). For manual/PC switch and the speed switch, i'm using the analog pins. It's working perfectly fine.
Regarding the encoder, I tried using one on digital pins 2 and 3 ( with the common pin connected to ground and without using motors ). I put both of them in INPUT and HIGH states.If I can detect ( with an interrupt) the expected RISING and FALLING transitions on digital pin 2, digital pin 3 is always read at 0. So I decided to do some test. I disconnected everythting on the motor shield ( encoder, the switches on the analog pins and the motor ), leaving just the arduino board and the motor shield on top, I put every pins from 2 to 12 on INPUT and HIGH and then read the values. There is no motor in use, so thoses pins should all be free. And I see that digital pin 3 and 6 exibit the same problem, they keep reading 0 despite being set at HIGH. So is there any components connected to pins 3 and 6 that would pull the voltage below +5V ?
I made some progress since the last post ( and undestood some basic things...). For manual/PC switch and the speed switch, i'm using the analog pins. It's working perfectly fine.
Regarding the encoder, I tried using one on digital pins 2 and 3 ( with the common pin connected to ground and without using motors ). I put both of them in INPUT and HIGH states.If I can detect ( with an interrupt) the expected RISING and FALLING transitions on digital pin 2, digital pin 3 is always read at 0. So I decided to do some test. I disconnected everythting on the motor shield ( encoder, the switches on the analog pins and the motor ), leaving just the arduino board and the motor shield on top, I put every pins from 2 to 12 on INPUT and HIGH and then read the values. There is no motor in use, so thoses pins should all be free. And I see that digital pin 3 and 6 exibit the same problem, they keep reading 0 despite being set at HIGH. So is there any components connected to pins 3 and 6 that would pull the voltage below +5V ?
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield with manual mode
There shouldn't be anything on those pins if you have no motors in use. Can you post the code you were using?
-
- Posts: 6
- Joined: Wed Jun 22, 2011 6:10 pm
Re: Motor shield with manual mode
To do the check, I used this sketch:
Result on the serial monitor : 10110111111
I tested that on a spare motor shield that i have, same results.
I also double-checked the soldering and it seems fine ( I don't have any decent camera so i can't show a good enough photo here)
Code: Select all
void setup() {
for (int i=2; i<=12; i++){
pinMode (i,INPUT);
digitalWrite(i,HIGH);
}
Serial.begin (9600);
}
void loop() {
for (int j=2; j<=11; j++){
Serial.print(digitalRead(j));
}
Serial.println(digitalRead(12));
}
I tested that on a spare motor shield that i have, same results.
I also double-checked the soldering and it seems fine ( I don't have any decent camera so i can't show a good enough photo here)
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield with manual mode
Interesting. I ran your sketch here with the same configuration (motor shield - nothing connected) and got "11111111111".
What do you get if you remove the shield?
What do you get if you remove the shield?
-
- Posts: 6
- Joined: Wed Jun 22, 2011 6:10 pm
Re: Motor shield with manual mode
I also did the test without the motor shield, just the arduino board and I get the good result : 11111111111
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield with manual mode
What kind of Arduino are you using?
-
- Posts: 6
- Joined: Wed Jun 22, 2011 6:10 pm
Re: Motor shield with manual mode
It's an arduino uno SMD Edition
Edit : Ok i discovered where this behavior was coming from : the jumper was removed . Actually, I was used to always plug a 12V battery on the motor shield. I didn't even solder the jumper on my working shield because there was always my battery on the external power input. But to test the encoder i didn't bother with the battery and forgot that the jumper was needed. Now it's working normaly
Edit : Ok i discovered where this behavior was coming from : the jumper was removed . Actually, I was used to always plug a 12V battery on the motor shield. I didn't even solder the jumper on my working shield because there was always my battery on the external power input. But to test the encoder i didn't bother with the battery and forgot that the jumper was needed. Now it's working normaly
Please be positive and constructive with your questions and comments.