a4988 examples
Example code for the A4988 in CircuitPython and Arduino
This commit is contained in:
parent
4dd60a2ac0
commit
4a6ded436c
2 changed files with 63 additions and 0 deletions
31
A4988_Examples/Arduino_A4988/Arduino_A4988.ino
Normal file
31
A4988_Examples/Arduino_A4988/Arduino_A4988.ino
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
const int DIR = 5;
|
||||||
|
const int STEP = 6;
|
||||||
|
const int microMode = 16; // microstep mode, default is 1/16 so 16; ex: 1/4 would be 4
|
||||||
|
// full rotation * microstep divider
|
||||||
|
const int steps = 200 * microMode;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// setup step and dir pins as outputs
|
||||||
|
pinMode(STEP, OUTPUT);
|
||||||
|
pinMode(DIR, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// change direction every loop
|
||||||
|
digitalWrite(DIR, !digitalRead(DIR));
|
||||||
|
// toggle STEP to move
|
||||||
|
for(int x = 0; x < steps; x++)
|
||||||
|
{
|
||||||
|
digitalWrite(STEP, HIGH);
|
||||||
|
delay(2);
|
||||||
|
digitalWrite(STEP, LOW);
|
||||||
|
delay(2);
|
||||||
|
}
|
||||||
|
delay(1000); // 1 second delay
|
||||||
|
}
|
||||||
32
A4988_Examples/CircuitPython_A4988/code.py
Normal file
32
A4988_Examples/CircuitPython_A4988/code.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import time
|
||||||
|
import board
|
||||||
|
from digitalio import DigitalInOut, Direction
|
||||||
|
|
||||||
|
# direction and step pins as outputs
|
||||||
|
DIR = DigitalInOut(board.D5)
|
||||||
|
DIR.direction = Direction.OUTPUT
|
||||||
|
STEP = DigitalInOut(board.D6)
|
||||||
|
STEP.direction = Direction.OUTPUT
|
||||||
|
|
||||||
|
# microstep mode, default is 1/16 so 16
|
||||||
|
# another ex: 1/4 microstep would be 4
|
||||||
|
microMode = 16
|
||||||
|
# full rotation multiplied by the microstep divider
|
||||||
|
steps = 200 * microMode
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# change direction every loop
|
||||||
|
DIR.value = not DIR.value
|
||||||
|
# toggle STEP pin to move the motor
|
||||||
|
for i in range(steps):
|
||||||
|
STEP.value = True
|
||||||
|
time.sleep(0.001)
|
||||||
|
STEP.value = False
|
||||||
|
time.sleep(0.001)
|
||||||
|
print("rotated! now reverse")
|
||||||
|
# 1 second delay before starting again
|
||||||
|
time.sleep(1)
|
||||||
Loading…
Reference in a new issue