Page 1 sur 1

Home a stepper

Posté : jeu. 2 déc. 2021 13:33
par Adriaan
Hallo,


I'd like to home a stepper motor at startup. How would I do this? using the 4 stepper code.


Thanks,
Adriaan

Re: Home a stepper

Posté : jeu. 2 déc. 2021 21:53
par Jacques
Hello adriaan,
we already talk about that in this topic :https://forum.arpschuino.fr/viewtopic.php?t=17
Ok it's in french...
You need to use an end stop switch like this one for example : https://cdn03.plentymarkets.com/ioseuwg ... -23987.png
Attach it on a free I/O.

Code : Tout sélectionner

uint8_t zeroSwitch=Arp2;
initialise it in the setup :

Code : Tout sélectionner

pinMode(zeroSwitch, INPUT_PULLUP);
still in the setup, after initializing the stepper motor and before initializing DMX:

Code : Tout sélectionner

  stepper0.refresh(255, 30);//we define a direction of rotation (255, to go in the other direction : 0), and a speed (here 30 for a slow speed) 
  while (digitalRead(zeroSwitch))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior) 
  {
    stepper0.continuous();//turn !
  }
the stepper will turn until the switch is pressed, then it will stop at position 0;
Then it will listen to the DMX instructions.