Ветка обсуждения проекта Наливатор.
Видео:
Делитесь своими вариантами изготовления, модификациями и улучшениями!
Видео:
Делитесь своими вариантами изготовления, модификациями и улучшениями!
Изменено:
/***************************************************
Copyright (c) 2017 Luis Llamas
(www.luisllamas.es)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License
****************************************************/
#include "AsyncStepperLib.h"
#include <Stepper.h>
const int motorPin1 = 8;
const int motorPin2 = 9;
const int motorPin3 = 10;
const int motorPin4 = 11;
const int numSteps = 8;
const int stepsLookup[8] = { B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001 };
int stepCounter = 0;
bool is_stop = false;
void clockwise()
{
stepCounter++;
if (stepCounter >= numSteps) stepCounter = 0;
setOutput(stepCounter);
}
void anticlockwise()
{
stepCounter--;
if (stepCounter < 0) stepCounter = numSteps - 1;
setOutput(stepCounter);
}
void setOutput(int step)
{
digitalWrite(motorPin1, bitRead(stepsLookup[step], 0));
digitalWrite(motorPin2, bitRead(stepsLookup[step], 1));
digitalWrite(motorPin3, bitRead(stepsLookup[step], 2));
digitalWrite(motorPin4, bitRead(stepsLookup[step], 3));
}
const int stepsPerRevolution = 4076;
AsyncStepper stepper1(stepsPerRevolution,
[]() {
clockwise();
},
[]() {
anticlockwise();
}
);
void rotateCW()
{
delay(1000);
stepper1.Rotate(30, AsyncStepper::CW, rotateCCW);
}
void rotateCCW()
{
delay(1000);
stepper1.Rotate(30, AsyncStepper::CCW, rotateCW);
}
void StopStepper()
{
if (is_stop) return;
stepper1.Stop();
is_stop = true;
detachInterrupt(0);
}
void setup()
{
Serial.begin(115200);
pinMode(2, INPUT_PULLUP);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
attachInterrupt(0, StopStepper, FALLING );
stepper1.SetSpeedRpm(12);
stepper1.RotateContinuos(AsyncStepper::CW);
while (!is_stop) {stepper1.Update();};
Serial.println("Stop");
Serial.println(stepper1.GetCurrentAngleMath());
stepper1.Rotate(2, AsyncStepper::CCW);
while (stepper1.GetGoalStep()>0) {
stepper1.Update();
};
stepper1.SetZerro();
Serial.print("Zerro="); Serial.println(stepper1.GetCurrentAngleMath());
stepper1.Write(90);
}
void loop()
{
if (stepper1.GetGoalStep()>0)
{
stepper1.Update();
}
else
{
delay(1000);
uint16_t new_ugol=random(0,270);
Serial.print("Go to ");Serial.println(new_ugol);
stepper1.Write(new_ugol);
}
}
void setup()
{
Serial.begin(115200);
opStepper, FALLING );
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
stepper1.SetSpeedRpm(12);
stepper1.RotateContinuos(AsyncStepper::CW);
pinMode(7, INPUT_PULLUP);
while (digitalRead(7)) {
stepper1.Update();
};
Serial.println("Stop");
Serial.println(stepper1.GetCurrentAngleMath());
stepper1.Rotate(2, AsyncStepper::CCW);
while (stepper1.GetGoalStep() > 0) {
stepper1.Update();
};
stepper1.SetZerro();
Serial.print("Zerro="); Serial.println(stepper1.GetCurrentAngleMath());
stepper1.Write(320);
}
#include "StepMot.h"
#define STEPS_PER_REVOLUTION 2037.88642 // 28BYJ-48 geared stepper motor
#define MICROSTEPS 1
#define STEP_PIN 16
#define DIR_PIN 10
#define EN_PIN 14
#define ENDSTOP_PIN 7 // концевик с активным низким уровнем
StepMot motor(STEPS_PER_REVOLUTION * MICROSTEPS, STEP_PIN, DIR_PIN, EN_PIN);
void setup() {
Serial.begin(9600);
pinMode(ENDSTOP_PIN, INPUT_PULLUP);
motor.enable(); // подача питания на мотор
motor.setRPM(5); // скорость в оборотах в минуту
motor.rotate(CCW); // двигаемся в сторону нулевой позиции
while(digitalRead(ENDSTOP_PIN) && motor.update)) {} // двигаемся до тех пор, пока не сработает концевик
motor.resetPos(); // сброс начальной позиции
motor.setMode(ABSOLUTE); // режим абсолютного позиционирования.
motor.setRPM(10);
}
void loop() {
if(!motor.update()) { // пришли к цели, отдохнули и задали новую
uint16_t angle = random(0,360);
motor.setAngle(angle);
Serial.print("Цель -> ");
Serial.println(angle);
delay(1000);
}
}
В STEP/DIR драйверах используется 3 сигнала:Притулите на ось шаговика переменной сопротивление, не сложно сделать, считывайте через аналоговый вход состояние и получите обратную связь, типа эмуляция серво.
Занялся бы, но времени сейчас нет(
И не забывайте с шаговика снимать напругу как только это можно. Под напругой он начинает жрать и греться.