Code:
// Define Stepper motor connections and steps per revolution:
#define dirPin_VL 2
#define stepPin_VL 3
#define dirPin_HL 4
#define stepPin_HL 5
#define dirPin_VR 6
#define stepPin_VR 7
#define dirPin_HR 8
#define stepPin_HR 9
#define stepsPerRevolution 200
#define enbl_VL 40
#define enbl_HL 42
#define enbl_VR 41
#define enbl_HR 43
void setup()
{
// deklariere pins als output:
pinMode(dirPin_VL, OUTPUT);
pinMode(stepPin_VL, OUTPUT);
pinMode(dirPin_HL, OUTPUT);
pinMode(stepPin_HL, OUTPUT);
pinMode(dirPin_VR, OUTPUT);
pinMode(stepPin_VR, OUTPUT);
pinMode(dirPin_HR, OUTPUT);
pinMode(stepPin_HR, OUTPUT);
Serial.begin(115200);
// mache enaable pins stromlos:
digitalWrite(enbl_VL, HIGH);
digitalWrite(enbl_HL, HIGH);
digitalWrite(enbl_VR, HIGH);
digitalWrite(enbl_HR, HIGH);
Serial.print("code---- /home/georg/Arduino/outdoor_robo/stepper/test_vier_stepper/ohne_lib/vier_stepper_ohne_lib_basic_example_idx_enbl_1");
}
void loop()
{
// bestrome enable pins:
digitalWrite(enbl_VL, LOW);
digitalWrite(enbl_HL, LOW);
digitalWrite(enbl_VR, LOW);
digitalWrite(enbl_HR, LOW);
// drehe alle vier Stepper langsam vorwaerts einmal herum:
//set dir pinns vorwarts
digitalWrite(dirPin_VL, LOW);
digitalWrite(dirPin_HL, LOW);
digitalWrite(dirPin_VR, HIGH);
digitalWrite(dirPin_HR, HIGH);
for (int i = 0; i < stepsPerRevolution; i++)
{
// These four lines result in 1 step:
digitalWrite(stepPin_VL, HIGH);
digitalWrite(stepPin_HL, HIGH);
digitalWrite(stepPin_VR, HIGH);
digitalWrite(stepPin_HR, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin_VL, LOW);
digitalWrite(stepPin_HL, LOW);
digitalWrite(stepPin_VR, LOW);
digitalWrite(stepPin_HR, LOW);
delayMicroseconds(2000);
}
delay(1000);
// drehe alle vier Stepper schnell rueckwaerts einmal herum:
//set dir pinns rueckwaerts
digitalWrite(dirPin_VL, HIGH);
digitalWrite(dirPin_HL, HIGH);
digitalWrite(dirPin_VR, LOW);
digitalWrite(dirPin_HR, LOW);
for (int i = 0; i < stepsPerRevolution; i++)
{
// These four lines result in 1 step:
digitalWrite(stepPin_VL, HIGH);
digitalWrite(stepPin_HL, HIGH);
digitalWrite(stepPin_VR, HIGH);
digitalWrite(stepPin_HR, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin_VL, LOW);
digitalWrite(stepPin_HL, LOW);
digitalWrite(stepPin_VR, LOW);
digitalWrite(stepPin_HR, LOW);
delayMicroseconds(1000);
}
delay(1000);
// drehe alle vier Stepper langsam vorwaerts fünf mal herum:
//set dir pinns vorwarts
digitalWrite(dirPin_VL, LOW);
digitalWrite(dirPin_HL, LOW);
digitalWrite(dirPin_VR, HIGH);
digitalWrite(dirPin_HR, HIGH);
for (int i = 0; i < 5* stepsPerRevolution; i++)
{
// These four lines result in 1 step:
digitalWrite(stepPin_VL, HIGH);
digitalWrite(stepPin_HL, HIGH);
digitalWrite(stepPin_VR, HIGH);
digitalWrite(stepPin_HR, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin_VL, LOW);
digitalWrite(stepPin_HL, LOW);
digitalWrite(stepPin_VR, LOW);
digitalWrite(stepPin_HR, LOW);
delayMicroseconds(2000);
}
delay(1000);
// drehe alle vier Stepper schnell rueckwaerts fünf mal herum:
//set dir pinns rueckwaerts
digitalWrite(dirPin_VL, HIGH);
digitalWrite(dirPin_HL, HIGH);
digitalWrite(dirPin_VR, LOW);
digitalWrite(dirPin_HR, LOW);
for (int i = 0; i < 5* stepsPerRevolution; i++)
{
// These four lines result in 1 step:
digitalWrite(stepPin_VL, HIGH);
digitalWrite(stepPin_HL, HIGH);
digitalWrite(stepPin_VR, HIGH);
digitalWrite(stepPin_HR, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin_VL, LOW);
digitalWrite(stepPin_HL, LOW);
digitalWrite(stepPin_VR, LOW);
digitalWrite(stepPin_HR, LOW);
delayMicroseconds(500);
}
delay(1000);
}
der code funktioniert soweit, was mich noch ein bischen stört, sieht und hört man in dem video
Lesezeichen