Last active
April 23, 2020 07:59
-
-
Save TakuroFukamizu/ac3548a224337581b853f78457c7b571 to your computer and use it in GitHub Desktop.
EasyDriver(A3967) / A4988 Sample https://bildr.org/2011/06/easydriver/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5Atom.h> | |
// M5AtomのGroveコネクタ | |
#define DIR_PIN 32 | |
#define STEP_PIN 26 | |
void setup() { | |
M5.begin(true, false, true); | |
// EasyStepper(A3967, A4988) の制御ピン | |
pinMode(DIR_PIN, OUTPUT); | |
pinMode(STEP_PIN, OUTPUT); | |
delay(50); | |
M5.dis.clear(); | |
M5.dis.drawpix(0, 0xf00000); | |
} | |
void loop(){ | |
if (M5.Btn.wasPressed()) { | |
rotateDeg(1, .5); //ボタン押したら1度を.5のスピードで回す | |
} | |
delay(100); | |
M5.update(); | |
} | |
/** ステップ数指定で回す処理 */ | |
void rotate(int steps, float speed){ | |
//rotate a specific number of microsteps (8 microsteps per step) – (negitive for reverse movement) | |
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger | |
int dir = (steps > 0)? HIGH:LOW; | |
steps = abs(steps); | |
digitalWrite(DIR_PIN,dir); | |
float usDelay = (1/speed) * 70; | |
// 制御用のパルスを作る | |
for (int i=0; i < steps; i++) { | |
digitalWrite(STEP_PIN, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(STEP_PIN, LOW); | |
delayMicroseconds(usDelay); | |
} | |
} | |
/** 角度指定で回す処理 */ | |
void rotateDeg(float deg, float speed){ | |
//rotate a specific number of degrees (negitive for reverse movement) | |
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger | |
int dir = (deg > 0)? HIGH:LOW; | |
digitalWrite(DIR_PIN,dir); | |
int steps = abs(deg)*(1/0.225); | |
float usDelay = (1/speed) * 70; | |
for (int i=0; i < steps; i++) { | |
digitalWrite(STEP_PIN, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(STEP_PIN, LOW); | |
delayMicroseconds(usDelay); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5StickC.h> | |
#define DIR_PIN 26 | |
#define STEP_PIN 0 | |
/* | |
for M5Stick-C | |
*/ | |
void setup() { | |
M5.begin(); | |
M5.Lcd.setRotation(1); | |
M5.Lcd.setTextSize(1); | |
M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.println("Stepper test"); | |
M5.Lcd.setCursor(0, 30, 2); | |
M5.Lcd.print("off"); | |
pinMode(DIR_PIN, OUTPUT); | |
pinMode(STEP_PIN, OUTPUT); | |
pinMode(M5_LED, OUTPUT); | |
digitalWrite(M5_LED, HIGH); | |
} | |
void loop(){ | |
int dig = 0; | |
if (M5.BtnA.read())) { | |
dig = 360; | |
Serial.println("360 forward"); | |
} else if (M5.BtnB.read()) { | |
dig = -360; | |
Serial.println("360 reverse"); | |
} | |
if (dig == 0) { | |
delay(100); | |
return; | |
} | |
M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.setCursor(0, 0); | |
M5.Lcd.println("Stepper test"); | |
M5.Lcd.setCursor(0, 30, 2); | |
M5.Lcd.printf("rotate : %02d\n", dig); | |
rotateDeg(dig, .1); | |
M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.setCursor(0, 0); | |
M5.Lcd.println("Stepper test"); | |
M5.Lcd.setCursor(0, 30, 2); | |
M5.Lcd.print("off"); | |
delay(100); | |
} | |
void rotate(int steps, float speed){ | |
digitalWrite(M5_LED, LOW); | |
//rotate a specific number of microsteps (8 microsteps per step) – (negitive for reverse movement) | |
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger | |
int dir = (steps > 0)? HIGH:LOW; | |
steps = abs(steps); | |
digitalWrite(DIR_PIN,dir); | |
float usDelay = (1/speed) * 70; | |
for(int i=0; i < steps; i++){ | |
digitalWrite(STEP_PIN, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(STEP_PIN, LOW); | |
delayMicroseconds(usDelay); | |
} | |
digitalWrite(M5_LED, HIGH); | |
} | |
void rotateDeg(float deg, float speed){ | |
digitalWrite(M5_LED, LOW); | |
//rotate a specific number of degrees (negitive for reverse movement) | |
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger | |
int dir = (deg > 0)? HIGH:LOW; | |
digitalWrite(DIR_PIN,dir); | |
int steps = abs(deg)*(1/0.225); | |
float usDelay = (1/speed) * 70; | |
for(int i=0; i < steps; i++){ | |
digitalWrite(STEP_PIN, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(STEP_PIN, LOW); | |
delayMicroseconds(usDelay); | |
} | |
digitalWrite(M5_LED, HIGH); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define DIR_PIN 2 | |
#define STEP_PIN 3 | |
/* | |
for Arduino Uno | |
*/ | |
void setup() { | |
pinMode(DIR_PIN, OUTPUT); | |
pinMode(STEP_PIN, OUTPUT); | |
} | |
void loop(){ | |
//rotate a specific number of degrees | |
rotateDeg(360, 1); | |
delay(1000); | |
rotateDeg(-360, .1); //reverse | |
delay(1000); | |
//rotate a specific number of microsteps (8 microsteps per step) | |
//a 200 step stepper would take 1600 micro steps for one full revolution | |
rotate(1600, .5); | |
delay(1000); | |
rotate(-1600, .25); //reverse | |
delay(1000); | |
} | |
void rotate(int steps, float speed){ | |
//rotate a specific number of microsteps (8 microsteps per step) – (negitive for reverse movement) | |
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger | |
int dir = (steps > 0)? HIGH:LOW; | |
steps = abs(steps); | |
digitalWrite(DIR_PIN,dir); | |
float usDelay = (1/speed) * 70; | |
for(int i=0; i < steps; i++){ | |
digitalWrite(STEP_PIN, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(STEP_PIN, LOW); | |
delayMicroseconds(usDelay); | |
} | |
} | |
void rotateDeg(float deg, float speed){ | |
//rotate a specific number of degrees (negitive for reverse movement) | |
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger | |
int dir = (deg > 0)? HIGH:LOW; | |
digitalWrite(DIR_PIN,dir); | |
int steps = abs(deg)*(1/0.225); | |
float usDelay = (1/speed) * 70; | |
for(int i=0; i < steps; i++){ | |
digitalWrite(STEP_PIN, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(STEP_PIN, LOW); | |
delayMicroseconds(usDelay); | |
} | |
} |
28HB30(CTM28-0601-50) 接続例
JP3 | Board PIN Assign | Moter PIN Assign | Wire Color |
---|---|---|---|
1 | OUT2A | A+ | RED |
2 | OUT2B | A- | BLUE |
3 | OUT1A | B+ | GREEN |
4 | OUT1B | B- | BLACK |
HANPOSE 17HS3401S 接続例
JP3 | Board PIN Assign | Moter PIN Assign | Wire Color |
---|---|---|---|
1 | OUT2A | A+ | RED(1) |
2 | OUT2B | A- | BLACK(3) |
3 | OUT1A | B+ | BLUE(4) |
4 | OUT1B | B- | GREEN(6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SM-42BYG011-25 接続例