• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Kierowanie silnikiem krokowym - brak reakcji na Arduino
#12
Okej! Teraz wszystko działa!

Póki co nie zagłębiałem się w bibliotekę - ona wiele zapewne ułatwi, ale najpierw chciałem zrozumieć co dokładnie robię nie tak w obecnym rozwiązaniu, skoro ono również powinno działać. Bez tej wiedzy, przeniósłbym moje błędy logiczne do etapu w którym korzystałbym z biblioteki i nadal do niczego bym nie doszedł. Teraz wszystko jest jasne i powoli zacznę zagłębiać się w Accelstepper! Ogromne dzięki!

Jeśli chodzi o start silnika - tutaj zastosowałem pin reset. Byłbym wdzięczny za sprostowanie, czy taka metoda faktycznie została przeze mnie sensownie zastosowana, czy w przyszłości się na mnie zemści. Rozłączyłem sleep z reset. Reset podłączyłem do Arduino i stan wysoki na reset rusza dopiero gdy Arduino wystartuje - do tego czasu silnik stoi przez co nie mam już problemu z niekontrolowanym obrotem w okresie pomiędzy podaniem zasilania, a startem Arduino.

Kod wygląda następująco:
Kod:
// Defines pins numbers
const int stepPin = 3;
const int dirPin = 2;
const int buttonPin = 8;
const int resetPin = 7;
const int ms1Pin = 4;
const int ms2Pin = 5;
const int ms3Pin = 6;
int customDelay,customDelayMapped; // Defines variables
int buttonState = 0;

void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode( buttonPin,INPUT_PULLUP);
  digitalWrite(resetPin, HIGH);
  digitalWrite(ms1Pin, LOW);
  digitalWrite(ms2Pin, HIGH);
  digitalWrite(ms3Pin, LOW);
 

  //digitalWrite(dirPin,LOW); //Enables the motor to move in a particular direction
}
void loop() {
 
 
  if (digitalRead(buttonPin) == HIGH) {
   digitalWrite(dirPin, HIGH); // spin counterclockwise
   }
   else {
    digitalWrite(dirPin, LOW); // spin clockwise button not pushed
   }
  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
 
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
 
}
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 6000,14000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom; 
}
 
Odpowiedź
  


Wiadomości w tym wątku
RE: Kierowanie silnikiem krokowym - brak reakcji na Arduino - przez krzysztof1594@gmail.com - 19-02-2022, 20:12

Skocz do:


Przeglądający: 1 gości