Making a stepper motor move
Posted: Sat Sep 24, 2016 11:25 am
I am at the moment trying to make a stepper motor move with the help of wemos d1 mini.
The arduino interact with the motor through the motor driver. The driver only is given a 5v, step signal, enable signal and direction signal.
According to the datasheet shall these signal be timed as such.
The complete datasheet can be found http://www.sainsmart.com/zen/documents/20-019-201/ST330%20%20Stepper%20Motor%20Driver%20Board%20User%20Manual.pdf
I wrote some code which should comply with the timing which can be seen here
.cpp
.h
When i execute my program stalls the motor, but when i unplug enable signal begins the motor to spin in one direction, and when i unplug the direction signal spin it the other way. I can't codewise change the direction of the stepper motor, only by either pulling the pin on or off.
This problem seemed to weird to get a hold, which made me think whether it could be due to pin_mapping.h which i use to declare which pin I want to use.
The pin_mapping.h is the one available on github.
So my question is... is this pin_mapping.h fully compatible with Wemos d1 mini ?
The arduino interact with the motor through the motor driver. The driver only is given a 5v, step signal, enable signal and direction signal.
According to the datasheet shall these signal be timed as such.
The complete datasheet can be found http://www.sainsmart.com/zen/documents/20-019-201/ST330%20%20Stepper%20Motor%20Driver%20Board%20User%20Manual.pdf
I wrote some code which should comply with the timing which can be seen here
.cpp
Code: Select all
void stepper_motor::step_pwm()
{
digitalWrite(en_pin,HIGH);
delay(0.005);
digitalWrite(dir_pin,LOW);
delay(0.005);
while(1)
{
digitalWrite(step_pin,LOW);
delay(1);
digitalWrite(step_pin,HIGH);
delay(1);
}
}
.h
Code: Select all
/* Class: stepper_motor
* Info: contains the setup, and primary interface to control
* the stepper motor
*
* stepper_motor(): constructor - setup the connection to the control board
* void step_pwm(): Moves the tilt - uses the bool to determine the direction.
* bool alive_bool: Is either high (1) or low (0), used for the alive void.
*/
#ifndef stepper_motor_h
#define stepper_motor_h
#include "Arduino.h"
#include "pins_arduino.h"
#define step_pin D1
#define dir_pin D2
#define en_pin D3
#define max_step 200
class stepper_motor
{
public:
stepper_motor();
void alive();
void step_pwm();
private:
bool alive_bool;
bool position_bool;
int step_count;
};
#endif
When i execute my program stalls the motor, but when i unplug enable signal begins the motor to spin in one direction, and when i unplug the direction signal spin it the other way. I can't codewise change the direction of the stepper motor, only by either pulling the pin on or off.
This problem seemed to weird to get a hold, which made me think whether it could be due to pin_mapping.h which i use to declare which pin I want to use.
The pin_mapping.h is the one available on github.
Code: Select all
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2015.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include "../generic/common.h"
static const uint8_t SDA = 4;
static const uint8_t SCL = 5;
static const uint8_t LED_BUILTIN = 2;
static const uint8_t BUILTIN_LED = 2;
static const uint8_t D0 = 16;
static const uint8_t D1 = 5;
static const uint8_t D2 = 4;
static const uint8_t D3 = 0;
static const uint8_t D4 = 2;
static const uint8_t D5 = 14;
static const uint8_t D6 = 12;
static const uint8_t D7 = 13;
static const uint8_t D8 = 15;
static const uint8_t RX = 3;
static const uint8_t TX = 1;
#endif /* Pins_Arduino_h */
So my question is... is this pin_mapping.h fully compatible with Wemos d1 mini ?