Hey everyone,
I'm Tommy and new with Arduino. I use an Arduino UNO. Now have my first question. Is someone of you using the DK Electronics motor shield for Arduino in combination with push buttons?
I want to control a stepper with pressing the push buttons. Every push should move the stepper x steps in cw or ccw direction. My goal is to use 4 buttons. One pair for fast moving and one for slow moving. On the board are free analog inputs. How do I have to integrate them - with motor shield v1.0 - into my script?
Best regards
Tommy
tommybe90:
How do I have to integrate them - with motor shield v1.0 - into my script?
You "integrate" them into your project by writing code.
Or you pay someone to do the project for you whereupon you can post that information in the Gigs forum.
.
Edit: with the Adafruit AF_stepper library I'm able to use the stepper with keyborad inputs in the "Serial Monitor" screen.
ieee488:
You "integrate" them into your project by writing code.
Or you pay someone to do the project for you whereupon you can post that information in the Gigs forum.
.
I tried to put them in my code but it didn't work. I can't use the analog inputs 
Here's my code:
#include <AFMotor.h>
// Motor with 200 steps/rot. (1.8 degree / step)
// Motor port 1 (M1 and M2)
AF_Stepper motor(200, 1);
void setup() {
pinMode(A0,INPUT); // button 1 (left => big step)
digitalWrite(A0,HIGH);
pinMode(A1,INPUT); // button 2 (right => small step)
//digitalWrite(A1,HIGH);
pinMode(A2,INPUT); // button 3 (left => big step)
//digitalWrite(A2,HIGH);
pinMode(A3,INPUT); // button 4 (right => small step)
//digitalWrite(A3,HIGH);
// button_1_status = digitalRead(A0);
Serial.begin(9600);
if (A0 == HIGH) motor.setSpeed(20); // 20 rpm
if (A1 == HIGH) motor.setSpeed(20); // 20 rpm
if (A2 == HIGH) motor.setSpeed(2); // 2 rpm
if (A3 == HIGH) motor.setSpeed(2); // 2 rpm
}
void loop() {
//int readButton(int pin) { // Taste einlesen
if ( taster_1_status == HIGH) {
steps = angle_1/1.8;
motor.step(steps, FORWARD, MICROSTEP);}
delay(1000);
if ( A1 == HIGH) {
steps = angle_1/1.8;
motor.step(steps, BACKWARD, MICROSTEP);}
if ( A2 == HIGH) {
steps = angle_2/1.8;
motor.step(steps, FORWARD, MICROSTEP);}
if ( A3 == HIGH) {
steps = angle_2/1.8;
motor.step(steps, BACKWARD, MICROSTEP);}
ieee488:
Using push button to control servo/motor - Motors, Mechanics, Power and CNC - Arduino Forum
.
Thanks for this link. But my problem is that I can't use the digital pins (like in the servo example). They are used by the motor shield. In my opinion the only chance to use buttons is to connect them with the analog inputs (A0-A5).
Is there a possibility to use the analog inputs as a digital one? Position 0 and 1023 or 0 and 127 ...
tommybe90:
Thanks for this link. But my problem is that I can't use the digital pins (like in the servo example). They are used by the motor shield. In my opinion the only chance to use buttons is to connect them with the analog inputs (A0-A5).
Is there a possibility to use the analog inputs as a digital one? Position 0 and 1023 or 0 and 127 ...
You can actually use the analog inputs exactly like digital ones if you'd like. Just set them as inputs using pinMode().
Hi BJHenry,
thanks for your answer. But I already did this. Could show me my mistake?
Thanks alot!
Here is my code:
AF_Stepper motor(200, 1);
void setup() {
pinMode(A0,INPUT); // Taster 1 (links => großer Schritt)
digitalWrite(A0,HIGH); // Internen Widerstand für Kanal A0 einschalten
// taster_1_status = analogRead(A0);
Serial.begin(9600);
}
void loop() {
taster_1_status = analogRead(A0);
//int readButton(int pin) { // Taste einlesen
if ( taster_1_status == HIGH) {
motor.setSpeed(20); // 20 rpm
steps = winkel_1/1.8;
motor.step(steps, FORWARD, MICROSTEP);}
}
tommybe90:
Thanks for this link. But my problem is that I can't use the digital pins (like in the servo example). They are used by the motor shield. In my opinion the only chance to use buttons is to connect them with the analog inputs (A0-A5).
Is there a possibility to use the analog inputs as a digital one? Position 0 and 1023 or 0 and 127 ...
tommybe90:
Hi BJHenry,
thanks for your answer. But I already did this. Could show me my mistake?
...
And so now we get another dribble of information.
Put everything in your first post, so that others do not waste time going over what you have already done. It is very rude of you to do this.
.
ieee488:
And so now we get another dribble of information.
Put everything in your first post, so that others do not waste time going over what you have already done. It is very rude of you to do this.
.
You're not wrong but I'm going to have to give a bit of a mea culpa here- he was trying to use A0-A3 as digital inputs in his original code and I completely missed it.
tommybe90:
Hi BJHenry,
thanks for your answer. But I already did this. Could show me my mistake?
Absolutely. First a bit of house keeping- it is helpful for us if you clean up your code before you post it. Particularly, remove any unneeded comments like this:
void setup() {
pinMode(A0,INPUT); // Taster 1 (links => großer Schritt)
digitalWrite(A0,HIGH); // Internen Widerstand für Kanal A0 einschalten
// taster_1_status = analogRead(A0); <-don't need this, take it out before putting the code on the forums.
Serial.begin(9600);
}
As for why the buttons aren't working- if you are using the analog pins as digital inputs then you configure them like normal in your setup:
pinMode(A0,INPUT_PULLUP); <-This is the updated way of setting pullups
and then when trying to read the inputs you use digitalRead instead of analogRead, since you are using them like digital pins.
BJHenry:
You're not wrong but I'm going to have to give a bit of a mea culpa here- he was trying to use A0-A3 as digital inputs in his original code and I completely missed it.
How is it your fault?
If the OP is doing anything non-standard it must be mentioned!
It was until his third post on this topic that he writes the true situation.
WASTE of time!
Thanks to all!
sorry for wasting your time. In future I will express myself in a clearer way. But thanks for your help anyway! With your help I managed my mistakes and now it works as it should.
Best regards Tommy