Stepper Motor controllato da encoder rotativo


buongiorno tutti,
tempo fa cercavo uno sviluppatore ma non avendo trovato nessuno ho deciso di provarci da solo.....ma ho sinceramente bisogno di voi e del vostro prezioso aiuto.

vi spiego, ho uno stepper controllato da un modulo l298n e pilotato da un econder rotativo, fino qui funziona tutto nel senso che sono riuscito fargli fare ciò che volevo.
lo stepper serve per aprire una saracinesca del flusso dell'aria quindi ha un movimento massimo e minimo, qui ho bisogno di voi.
ho anche preso un circular led per sapere la posizione
http://wiki.seeedstudio.com/wiki/grove_-_circular_led

a questo punto vi chiedo come poter fare due cose:
1° impostare limiti dello stepper cioè al raggiungimento delle due posizioni min e max ad ogni movimento dell'encoder nella stessa direzione non succede nulla;

2° configurare led circolari per impostare la scala con il min e max dell ostepper e monitorare movimenti intermedi casomai con 5 step

vi sono molto grato, di seguito vi metto il codice attuale che dovrei integrare.
grazie tanto
claudio



questo è il codice che ora mi fa funzionare lo stepper con l'encoder rotativo

#include <stepper.h>
const int encoderpina = 2; // right
const int encoderpinb = 3; // left
const int encbutton = 0; // encoder push button
int encoderpos = 0; // counter
unsigned int lastreportedpos = 1; // change
static boolean rotating = false; // debounce
boolean a_set = false;
boolean b_set = false;
const int stepsperrevolution = 150;
stepper mystepper(stepsperrevolution, 4, 5, 6, 7); //h-bridge pins
void setup() {
mystepper.setspeed(50);
pinmode(encoderpina, input_pullup); //enabling pullups
pinmode(encoderpinb, input_pullup);
pinmode(encbutton, input_pullup);
attachinterrupt(0, doencodera, change); //pin 2
attachinterrupt(1, doencoderb, change); //pin 3
serial.begin(9600);
}
void loop() {
rotating = true; // reset debouncer
if (lastreportedpos != encoderpos) {
serial.println(encoderpos);
lastreportedpos = encoderpos;
if (digitalread(encbutton) == low )
{
encoderpos = (encoderpos * 50); //change 100 how many steps
} //you want stepper move when
mystepper.step(encoderpos); //the button pushed down
encoderpos = 0;
}
}
void doencodera() {
// debounce
if ( rotating ) delay (50); // wait little until bouncing done
// test transition
if ( digitalread(encoderpina) != a_set ) { // debounce once more
a_set = !a_set;
// adjust counter + if leads b
if ( a_set && !b_set )
encoderpos += 90; //change 1 steps take when encoder turned
rotating = false; // no more debouncing until loop() hits again
}
}
// interrupt on b changing state
void doencoderb() {
if ( rotating ) delay (1);
if ( digitalread(encoderpinb) != b_set ) {
b_set = !b_set;
// adjust counter - 1 if b leads a
if ( b_set && !a_set )
encoderpos -= 90; //change 1 steps take when encoder turned
rotating = false;
}
}

>driftking:  ti ricordo che in conformità al regolamento, punto 7, devi editare il tuo post (quindi non scrivendo un nuovo post, ma utilizzando il bottone more -> modify che si trova in basso destra del tuo post) e racchiudere il codice all'interno dei tag code (... sono quelli che in edit inserisce il bottone con icona fatta così: </>, tutto sinistra).

grazie,

guglielmo


Arduino Forum > International > Italiano > Generale (Moderator: leo72) > Stepper Motor controllato da encoder rotativo


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino DUE ADC to DAC Piezo 30 Khz-100Khz

Indesign and MathType fonts