Stepper speed limitation

Hi there,

I am using esphome in order to drive a stepper motor that drives a worm gearbox. That for I need ~1000rpm. The hardware is easily capable of that speed. After power up of my esp32 I am able to drive the stepper at full speed for about 3-4 seconds. afterwards speed reduces tremendously and stays constant. I have the feeling, that as soon as the esphome connects to wifi, the processor is clocked with other tasks and cannot run the step pin at these high speeds any longer. Did anybody have the same problem or has a solution for that?

I am using a tmc2208 stepper driver which is wired as of TMC2208 ESPHOME quiet curtains - YouTube.

used board is: S2 mini — WEMOS documentation

the code works flawlessly and the stepper starts on first button click and ends on second button click. Only the speed is awful slow.

my code:

esphome:
  name: test-board
  friendly_name: test_board

esp32:
  board: lolin_s2_mini
  variant: esp32s2
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxx"

ota:
  password: "xxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test-Board Fallback Hotspot"
    password: "xxx"

captive_portal:
    
stepper:
  - platform: a4988
    id: my_stepper
    dir_pin:
      number: GPIO38
      inverted: True
    step_pin: GPIO36
    sleep_pin: 
      number: GPIO17
      inverted: True
    max_speed: 200000 steps/s # Set the speed of the motor for 1000 rpm
    acceleration: inf
    deceleration: inf

globals:
  - id: my_stepper_move 
    type: bool
    restore_value: True
    initial_value: '0'

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO21 
      mode: INPUT_PULLUP
      inverted: True
    name: Button
    id: Button_id
    internal: True
    on_click:
    - min_length: 50ms
      max_length: 500ms
      then:
        - if: 
            condition:
              - lambda: 'return id(my_stepper_move) == 0;'
            then: 
              - globals.set: 
                  id: my_stepper_move
                  value: '1'
              - script.execute: move_up
            else:
              - globals.set: 
                  id: my_stepper_move
                  value: '0'
              - script.execute: stop
              
script:
  - id: move_up
    then:
      - stepper.set_target: 
          id: my_stepper
          target: !lambda return id(my_stepper).current_position-200000;
  - id: stop
    then:
      - stepper.set_target: 
          id: my_stepper
          target: !lambda return id(my_stepper).current_position;
  

1 Like

Did you ever figure this out? I’m dealing with a similar issue now. I’ve had some motorized blinds working well on DRV8825’s for years. Decided to upgrade to TMC2208’s. I’ve got them working, but they’re very slow. It’s like they’ve microstepping enabled.

EDIT: I figured it out. I assumed that the stock state of the stepper would be its fastest speed and that messing with the MS pins would only slow it down. Not true. It looks like the stock state is 1/8 steps (Fystec TMC2208 Documentation, see the micro-stepping section). To make the TMC2208 the same speed as the A4988 / DRV8825, connect the MS1 pin to VIO and double the speed in the esphome yaml. MS1 sets the steps to 1/2.

1 Like