HOME position of a Stepper, with the AccelStepper library.

Hello,

Sorry for my english, I’m translating with google translate.

I would like to configure the HOME position of a Stepper when starting, with the library “AccelStepper”. Same as this project: “How to set the HOME position of a Stepper at Startup!”

I’m programming it by dmx and I can not get it to work.

I would appreciate any help.

A greeting.

#include <lib_dmx.h>  // comment/uncomment #define USE_UARTx in lib_dmx.h as needed
#include <AccelStepper.h>

#define    DMX512     (0)    // (250 kbaud - 2 to 512 channels) Standard USITT DMX-512

// Define a stepper and the pins it will use
AccelStepper stepper (AccelStepper::FULL4WIRE, 8, 9, 10, 11);

void setup()
{  
  ArduinoDmx0.set_control_pin(2);    // Arduino output pin for MAX485 input/output control (connect to MAX485 pins 2-3) 
  ArduinoDmx0.set_rx_address(1);      // set rx0 dmx start address
  ArduinoDmx0.set_rx_channels(3);     // number of rx channels
  ArduinoDmx0.init_rx(DMX512);        // starts universe 0 as rx, NEW Parameter DMX mode 
  
  stepper.setMaxSpeed(1000);
}

void loop()
{
  // Read new position
  int move1;
  move1 = map(ArduinoDmx0.RxBuffer[0], 0, 255, 0, 4000);
  stepper.moveTo(move1);

  int speed1;
  speed1 = map(ArduinoDmx0.RxBuffer[1], 0, 255, 0, 900);
  stepper.setSpeed(speed1);
  stepper.runSpeedToPosition();
}

To get a stepper motor to move to the HOME or ZERO position you need to move it one step at a time until it triggers the switch that identifies the HOME position. You would usually do that in the setup() function.

In the program you posted I don't see any code that is detecting the switch.

...R
Stepper Motor Basics
Simple Stepper Code

Thanks for answering.

I upload the code with the HOME position attempt.

#include <lib_dmx.h>  // comment/uncomment #define USE_UARTx in lib_dmx.h as needed
#include <AccelStepper.h>

#define    DMX512     (0)    // (250 kbaud - 2 to 512 channels) Standard USITT DMX-512

AccelStepper stepper (AccelStepper::FULL4WIRE, 8, 9, 10, 11);   // Definir stepper y los pines que utilizará.

const int home_switch = 7;
byte LBval;
byte buttonState;

void setup()
{  
  ArduinoDmx0.set_control_pin(2);      // Arduino output pin for MAX485 input/output control (connect to MAX485 pins 2-3)
  ArduinoDmx0.set_rx_address(1);       // set rx0 dmx start address
  ArduinoDmx0.set_rx_channels(3);    // number of rx channels
  ArduinoDmx0.init_rx(DMX512);       // starts universe 0 as rx, NEW Parameter DMX mode DMX512
  
  stepper.setMaxSpeed(1000);         

  pinMode(home_switch, INPUT_PULLUP);

  buttonState = digitalRead(home_switch);
  if (buttonState == LOW)
  {
  stepper.setSpeed(800);
  stepper.moveTo(-4000);
  stepper.runSpeed();
  LBval = digitalRead(home_switch);
  } while (LBval == HIGH);
  do
  {
  stepper.moveTo(0);
  stepper.run();
  } while (LBval == LOW);
  
}

void loop()
{
  unsigned int move1 = ArduinoDmx0.RxBuffer[0] << 8;
  move1 |= ArduinoDmx0.RxBuffer[1];
  move1 = map(move1, 0, 65535, 0, 4000);
  stepper.moveTo(move1);
  
  unsigned int speed1;
  speed1 = map(ArduinoDmx0.RxBuffer[2], 0, 255, 0, 900);
  stepper.setSpeed(speed1);
  stepper.runSpeedToPosition();
}

In this piece of code you never check the switch

  do
  {
  stepper.moveTo(0);
  stepper.run();
  } while (LBval == LOW);

try this

  do
  {
  stepper.moveTo(0);
  stepper.run();
  LBval = digitalRead(home_switch);
  } while (LBval == LOW);

...R

The motor only turns when left with some DMX value and the switch does not act when pressed.

rockmartinez:
The motor only turns when left with some DMX value and the switch does not act when pressed.

Why not put the DMX stuff to one side for a while and learn how to get the AccelStepper code working as you want it.

After that you can then add the DMX stuff and it will be easier to figure out problems. I know nothing about DMX.

...R

OK
I will try without DMX
Thanks Robin2