Hello, someone could help me with a firmware to control a STEPPER MOTOR, is a bipolar STEPPER MOTOR, the driver is L298, I’m trying to control it using a function in a cloud, the idea is to send a command from the console:
“right” the STEPPER MOTOR turns to the right; ¨ “left” the STEPPER MOTOR turns to the left;
but I want the STEPPER MOTOR turns in a loop with any command, the console sent me an error and for a moment the LED of my photon turned red, I received an error message.
The code is:
// variables y pines BobinaA
#define ENA D0
#define IN1 D1
#define IN2 D2
// variables y pines Bobina B
#define IN3 D3
#define IN4 D4
#define ENB D5
// variables de entrada
int inti=0;
int i=0;
void setup() {
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
Particle.function("stepper",stepperToggle);
}
void loop() {
}
int stepperToggle(String command) {
if (command=="derecha" ) {
for(inti = 0; i<12; i++){
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
delay(300);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
delay(300);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
delay(300);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
delay(300);
}
return 1;
}
else if (command=="izquierda") {
for(int j = 0; j<12; j++){
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
delay(300);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
delay(300);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
delay(300);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
delay(300);
}
return 2;
}
return -1;
}