Skip to content

Instantly share code, notes, and snippets.

@keesj
Last active January 18, 2023 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keesj/637e4e64006eab453d81cb97894fccf0 to your computer and use it in GitHub Desktop.
Save keesj/637e4e64006eab453d81cb97894fccf0 to your computer and use it in GitHub Desktop.
28BYJ-48 Stepper esp8266 (Pins D5,D6,D7,D8)
// 28BYJ-48 Stepper esp8266
// Steps for stepping and performing 1/2 steps
char steps[8] =
{
0x01,// 1
0x03,// 12
0x02,// 2
0x06,// 23
0x04,// 3
0x0c,// 34
0x08,// 4
0x09,// 41
};
// Full stepper mode using two phase for more torque
char steps_full[4] =
{
0x03,// 12
0x06,// 23
0x0c,// 34
0x09,// 41
};
int stepper_gpio[4] = {
14, // D5 | GPIO14
12, // D6 | GPIO12
13, // D7 | GPIO13
15, // D8 | GPIO15
};
int spos = 0 ;
void move(int up){
//find the next position. for up simply do a +1. for a step down
//add size -1 to the current pos (modulus substraction)
spos = ((up )?spos+ 1: spos + sizeof(steps) -1) % sizeof(steps);
for (int i =0 ; i < 4; i++){
digitalWrite(stepper_gpio[i], (steps[spos] >> i ) & 1);
}
}
void setup() {
for (int i =0 ; i < 4; i++){
pinMode(stepper_gpio[i], OUTPUT);
}
}
void loop() {
move(1);
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment