Hi guys
I'm new here and I have a question implied in the subject.
I'm using a Smartlynx Stepper Driver to control a Stepper motor but I'm not so experienced to make it work just yet.
Do any of you happen to have used this driver in any of your projects?
Could you provide me with some guidance to communicate with it properly using an Arduino Uno?
I hope you can answer my query
Thanks in advance
There seem to be full connection details and some code examples in the Manual. However I’m afraid I don’t know enough to short-circuit your need to study the manual.
If you have some specific questions I will try to help.
Hi again
After a while, I worked on a sketch which I attach but I can’t get the damn thing working
I download the code, the stepper doesn’t move and there’s no voltage in the coils of the stepper.
Do any of you guys see the problem?
Any kind of help will be greatly appreciated
Thanks in advance
#include <SPI.h>
//Direcciones de los registros de SmartLynx
#define SMARTLYNX_ABS_POS 0x01
#define SMARTLYNX_SPEED 0x04
#define SMARTLYNX_ACC 0x05
#define SMARTLYNX_DEC 0x06
#define SMARTLYNX_MAX_SPEED 0x07
#define SMARTLYX_MIN_SPEED 0x08
#define SMARTLYNX_FS_SPD 0x15
#define SMARTLYNX_STEP_MODE 0x16
#define SMARTLYNX_STATUS 0x19
//Comandos a enviar
#define SMARTLYNX_SET_PARAM 0x00
#define SMARTLYNX_GET_PARAM 0x20
#define SMARTLYNX_RUN 0x50
#define SMARTLYNX_MOVE 0x40
#define SMARTLYNX_SOFT_STOP 0xB0
#define SMARTLYNX_HARD_STOP 0xB8
#define SMARTLYNX_RESET_DEVICE 0xC0
#define SMARTLYNX_GET_STATUS 0xD0
//Selección de pasos para el motor
#define SMARTLYNX_STEP_FULL 0
#define SMARTLYNX_STEP_HALF 1
#define SMARTLYNX_STEP_QUARTER 2
#define SMARTLYNX_STEP_ONE_EIGTH 3
#define SMARTLYNX_STEP_ONE_16TH 4
#define SMARTLYNX_STEP_ONE_32ND 5
#define SMARTLYNX_STEP_ONE_64TH 6
#define SMARTLYNX_STEP_ONE_128TH 7
//Macros para los pines de SPI, Reset y paso
#define SPI_CS 10
#define SPI_MOSI 11
#define SPI_MISO 12
#define SPI_SCK 13
#define SMARTLYNX_RESET_PIN 6
#define STEP 7
//Función para delay
void delay_us(uint32_t delayUs){
delayMicroseconds(delayUs);
}
//Función para resetear pines
void gpioClear(uint32_t portPinVal){
digitalWrite(portPinVal, LOW);
}
//Función para setear pines
void gpioSet(uint32_t portPinVal){
digitalWrite(portPinVal, HIGH);
}
//Función para inicializar los pines de SPI
void gpioInit(void){
pinMode(SPI_CS, OUTPUT);
digitalWrite(SPI_CS, HIGH);
pinMode(SPI_MOSI, OUTPUT);
pinMode(SPI_MISO, INPUT);
pinMode(SMARTLYNX_RESET_PIN, OUTPUT);
pinMode(STEP, OUTPUT);
}
//Función para inicializar SPI
void spiInit(void){
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV8); //Esto se puede modificar por otro número
SPI.setDataMode(SPI_MODE3);
}
//Inicialización de la placa
void boardInit(void){
gpioInit();
spiInit();
}
//Función para mover los datos a los registros de memoria
uint32_t smartLynxDataTransfer (uint32_t data, uint8_t size){
uint8_t wrData = 0;
uint32_t rdData = 0;
switch (size){
case 3:
//Transmito el 3er byte de datos
wrData = data >> 16;
gpioClear(SPI_CS);//Voy a hablarle al esclavo
rdData = SPI.transfer(wrData);
gpioSet(SPI_CS);//Le dejo de hablar al esclavo
rdData = rdData << 8;
case 2:
//Transmito el 3er byte de datos
wrData = data >> 8;
gpioClear(SPI_CS);//Voy a hablarle al esclavo
rdData |= SPI.transfer(wrData);
gpioSet(SPI_CS);//Le dejo de hablar al esclavo
rdData = rdData << 8;
case 1:
//Transmito el 3er byte de datos
wrData = data;
gpioClear(SPI_CS);//Voy a hablarle al esclavo
rdData |= SPI.transfer(wrData);
gpioSet(SPI_CS);//Le dejo de hablar al esclavo
default:
break;
}
return rdData;
}
//Inicializo el driver
void smartLynxInit(void){
uint32_t dummy = 0;
uint32_t status;
//Reseteo Driver
gpioClear(SMARTLYNX_RESET_PIN);
delay_us(250);
//Pido estado al driver
smartLynxDataTransfer(SMARTLYNX_GET_STATUS, 1);
//Leo estado del driver
status = smartLynxDataTransfer(dummy, 2);
}
//Función para setear la velocidad máxima del motor
void smartLynxSetMaxSpeed(float maxSpeed){
uint32_t data;
//Convierto el dato para que lo interprete el driver
data = 0.065536 * maxSpeed;
//seteo velocidad máxima
smartLynxDataTransfer((SMARTLYNX_SET_PARAM | SMARTLYNX_MAX_SPEED), 1);
smartLynxDataTransfer(data, 2);
}
//Función para setear la velocidad mínima del motor
void smartLynxSetMinSpeed(float minSpeed){
uint32_t data;
//Convierto el dato para que lo interprete el driver
data = 4.1943*minSpeed;
//seteo velocidad máxima
smartLynxDataTransfer((SMARTLYNX_SET_PARAM | SMARTLYNX_MAX_SPEED), 1);
smartLynxDataTransfer(data, 2);
}
//Función para resetear smartLynx
void smartLynxResetDevice(void){
//Reseteo
smartLynxDataTransfer(SMARTLYNX_RESET_DEVICE, 1);
}
//Función para setear la velocidad de paso completo
void smartLynxSetFullStepSpeed(float speed){
uint32_t data;
//Convierto el dato para que el driver lo entienda
data = (0.0655*speed) - 0.5;
//seteo velocidad
smartLynxDataTransfer((SMARTLYNX_SET_PARAM | SMARTLYNX_FS_SPD), 1);
smartLynxDataTransfer(speed, 2);
}
//Función para setear el perfil de aceleración
void smartLynxSetAccelerationProfile (float acc, float dec){
uint32_t data;
//Convierto dato para que el driver lo entienda
data = 0.0687*acc;
//seteo aceleración
smartLynxDataTransfer((SMARTLYNX_SET_PARAM | SMARTLYNX_ACC), 1);
smartLynxDataTransfer(data, 2);
//Convierto dato para el driver
data = 0.0687*dec;
smartLynxDataTransfer((SMARTLYNX_SET_PARAM | SMARTLYNX_DEC), 1);
smartLynxDataTransfer(data, 2);
}
//Función para poner el motor en rotación continua
void smartLynxRun(uint8_t dir, float speed){
uint32_t data;
//Convierto dato
data = 67.1*speed;
//Corro comando
smartLynxDataTransfer((SMARTLYNX_RUN | dir), 1);
smartLynxDataTransfer(data, 3);
}
//Función para mover el motor una cantidad específica de pasos
void smartLynxMove(uint8_t dir, uint32_t stepCount){
//Muevo
smartLynxDataTransfer((SMARTLYNX_MOVE | dir), 1);
smartLynxDataTransfer(stepCount, 3);
}
//Función para mover motor un paso
void smartLynxSingleStep(void){
//Pulso salida
gpioClear(STEP);
delay_us(1);
gpioSet(STEP);
}
//Parada suave para el motor
void smartLynxSoftStop(void){
smartLynxDataTransfer(SMARTLYNX_SOFT_STOP, 1);
}
//Parada de emergencia
void smartLynxHardStop(void){
smartLynxDataTransfer(SMARTLYNX_HARD_STOP, 1);
}
void setup() {
// put your setup code here, to run once:
boardInit();
smartLynxInit();
}
void loop() {
// put your main code here, to run repeatedly:
//Muevo horario
smartLynxRun(0, 500);
delay_us(5000000);
smartLynxRun(1, 500);
delay_us(5000000);
}
//Función para delay
void delay_us(uint32_t delayUs){
delayMicroseconds(delayUs);
}
Why in heavens name did you need to, effectively, rename the delayMicroseconds() function?
//Función para resetear pines
void gpioClear(uint32_t portPinVal){
digitalWrite(portPinVal, LOW);
}
It does not make sense to create functions that call exactly one function.
delay_us(5000000);
Have you bothered to look at the range of values that delayMicroseconds() takes? That you have created a function to effectively rename delayMicroseconds() does not change the fact that that is an invalid value to pass to the function. delayMicroseconds() is NOT for creating 5 second delays.
uint32_t data;
//Convierto dato
data = 67.1*speed;
I really don't understand passing an int to a function that expects a float, and then storing the result of this calculation in an integer variable.