Automatic crank turning system for an automaton

Hello all,
I'm making a system to which I can temporarly attach my automata and turn the crank with a motor.
This will be only for exhibition, I don't want the motorisation to be definitive. You can have a look at my prototype on this post on my instagram. (The noise problem has been solved by using a TMC2209 driver.

Anyway this was just for context, I think I have pretty much sorted everything but as this is my first arduino (or even electronics) project I would like to know what you think about my setup and code, if there is anything I can optimise or if I made anymistake.
Basically, what I want is for people to:

  • see the LED ON, to let them know the machine is ready
  • press a button, LED OFF
  • launch the motor for a choosen number of rotations
  • wait 2 seconds
  • LED ON

Here is my schematic


Here is my code:

#include <ezButton.h>
#include <AccelStepper.h>

#define ENA_PIN 9     // Enable
#define STEP_PIN 3     // Step
#define DIR_PIN 2    // Direction

#define START_BUTTON_PIN 12 // Button to start the loop
#define READY_TO_START_LED_PIN 11 // LED, On when not running, OFF when running

// Motor parameters
const float MOTOR_STEP_ANGLE = 1.8;  // Step angle of stepper motor
const int MICRO_STEPS = 8;  // micro steps setting of driver
const float MAX_SPEED = 500;      
const float MAX_ACCELERATION = 200; 

// Set the movement of the automaton
const int ROTATION_NUMBER = 20; //number of rotations needed
const int ROTATION_DIRECTION = 1; //rotation direction, 1 = clockwise, -1 = anticlockwise

bool is_running= false; //state of the motor
int total_steps; //numbers of steps the motor will have to make to turn the number of times needed

// Initialize stepper motor
AccelStepper stepper = AccelStepper(stepper.DRIVER, STEP_PIN, DIR_PIN);

ezButton start_button(START_BUTTON_PIN);


void setup() {

  pinMode(ENA_PIN, OUTPUT);
  digitalWrite(ENA_PIN, LOW); 

   // setup the buttons or inputs
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  pinMode(READY_TO_START_LED_PIN, OUTPUT);
  digitalWrite(READY_TO_START_LED_PIN,HIGH);
  start_button.setDebounceTime(50);

   // Convert the number of turns needed in steps (not really working, e.g.: If ROTATION_NUMBER=100 motor goes backward for just a few rotations)
  total_steps = round(ROTATION_NUMBER*360 / MOTOR_STEP_ANGLE * MICRO_STEPS)*ROTATION_DIRECTION;

  // setup the stepper motor
  stepper.setMaxSpeed(MAX_SPEED);
  stepper.setAcceleration(MAX_ACCELERATION);
  
}

void loop() {
  start_button.loop();

  if (!is_running && start_button.isPressed()){
    is_running= true;
    digitalWrite(READY_TO_START_LED_PIN,LOW);
    stepper.moveTo(total_steps);
  }

  if(is_running){
    stepper.run();
    if(stepper.distanceToGo() == 0){
      is_running= false;
      stepper.setCurrentPosition(0);
      delay(2000);
      digitalWrite(READY_TO_START_LED_PIN,HIGH);
    }
  }

}

A few questions:

  1. According to my calculations (wich are probably wrong) the TMC driver is in 8 microsteps mode.
    What are the advantges/disadvantages of augmenting the microsteps ?

  2. should I connect the TMC to 5v or 3.3v ?

  3. I plan on soldering the final PCB on this: ELEGOO boards
    Do you have any advices on how to properly do it ?

  4. On my power supply, should I connect ground and -V ?

Thanks for you help.

Tell us if it works as you want it to. That is the only valid test. As for optimization, you need to actually tell us WHAT you are optimizing for!

Yes it does work as i want. I just want to make sur my wirring is secure and that my code doesn't create unknow problematic things. As for optimization, I was wondering if there is a more efficient way to write the code or even wiring the hardware. Does that make sense ?
Thanks for your ansewer

No sense at all. Your next project will allow you to try different ways, but don't mess up a working project.

Very nice project. Your swimming whale video was well worth a look.

What are the advantges/disadvantages of augmenting the microsteps ?

In your case none. Higher microsteps may be needed for precise positioning applications, but not for you rotations. Different microstep setting might have been helpful in reducing your noise, but you solved the problem with the 2209. Very good choice of drivers. The 2208/2209 drivers are very quiet.

should I connect the TMC to 5v or 3.3v ?

Since the logic levels from Nano Every are at 5v. I would run the 2209 at 5v as well. It's more important for reading from the driver or using the serial interface than in your case, but it doesn't hurt to be consistent.

On my power supply, should I connect ground and -V ?

Your wiring does not make sense to me. Typically on that type of power supply the +V will +5vdc and the -V will be -5vdc. Do you have details on the model? Perhaps it's a Fritzing error. All the grounds should be connected. Driver ground, Power supply ground, Nano Every ground.

Hello and thanks for your help.
My power supply is a basic no name and I there is no manual with it.
When I check the voltage between -V and +V it does give me 12v but between +V and Ground the reading is weird and changing all the time.
Do you have a link where I could learn more about all this ?

You should have the - terminal connected to the power supply ground!

If the power supply only has a two prong plug to AC then there may not be an earth ground on the supply.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.