Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stepper motor control w/ TMC2209 #69

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

mwood77
Copy link
Owner

@mwood77 mwood77 commented Oct 15, 2024

This is a WIP

Adds support for stepper motors, using TMC2209 derived boards.


  • Set -D OLED_ENABLED=false prior to merging.
  • Add documentation
  • Update BOM
  • Update wiring diagram(s)

@NickNerfLips
Copy link

Everything seemed to build correctly, however no luck with the TMC2209 + moving the stepper motor.

I will add that yesterday, I was able to confirm the TMC2209 works and drives the stepper motor (silently!) with some test code (Arduino IDE). This Arduino code relied on simply the Direction & Step pins. Therefore, I'm confident my A1,A2,B1,B2, motor power and TMC2209 board ground/power isn't an issue.

I can see that the motor driver isn't being requested to move since the LED on the TMC2209 board is not cycling or turning on at all. I did use the pins you suggested between the ESP32 & TMC2209 board.

From my brief investigations, it seemed many had issues getting the UART Tx/Rx to function properly between ESP32 and the TMC2009. Would it be easier to simply leverage the DIR & STEP pins for this application?

@mwood77
Copy link
Owner Author

mwood77 commented Oct 15, 2024

Regarding UART Tx/Rx, I noticed that too. Did you also connect the HARDWARE_ENABLE_PIN to GPIO4?

This is used at lines

stepper_driver.setHardwareEnablePin(HARDWARE_ENABLE_PIN);
and

Comment on lines +24 to 27
-D OLED_ENABLED=true
-D PWM_MOTOR_CONTROL=false
-D STEPPER_MOTOR_CONTROL=true
-D HOME_ASSISTANT_ENABLED=false
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set all to false before merging

@mwood77 mwood77 self-assigned this Oct 15, 2024
@NickNerfLips
Copy link

NickNerfLips commented Oct 15, 2024 via email

@NickNerfLips
Copy link

NickNerfLips commented Oct 15, 2024 via email

@mwood77
Copy link
Owner Author

mwood77 commented Oct 22, 2024

Any luck? If not, no worries. I'll have a motor and controller on hand to debug with by the end of the week.

@NickNerfLips
Copy link

I tried setting all 4 build flags to FALSE, saving, uploading & upload filesystem image.
Still no motor operation/movement at all. No TMC2209 board LED either (indicating motor movement output).

@mwood77
Copy link
Owner Author

mwood77 commented Oct 24, 2024

@NickNerfLips I've refactored to use the step/dir interface. I can definitely hear the stepper motor trying to work, but I don't think I'm giving it enough power (I'm supplying barely 5v). I'll track down a better power supply on my end now.

For the build flags, it should be able to ignore a bad config. Just make sure the stepper motor flag is set to true and the other motor one is false; the home assistant / oled ones won't matter whether they're enabled or not.

@NickNerfLips
Copy link

IMG_7354
My ESP32 does not have Pins 16 and 17. I ordered from your AliExpress link, but I did switch to the USB-C variant they offered. Image attached is my board.

I changed the code to map STEP = Pin 18 and DIR = Pin 19, which were open on my board. After upload & upload file system image, still no luck it seems.

I'm using a 12V 1A power supply, which worked with the other test code I mentioned I tried earlier with the same hardware set.

@NickNerfLips
Copy link

Anything progress or anything in particular you’d like to try?
I’m also more than happy to do a phone call or web meeting to help sort things.

@mwood77
Copy link
Owner Author

mwood77 commented Nov 4, 2024

Sorry mate, I've been crazy busy and haven't had time to work on it. I've got some spare time tomorrow, so I'll have at it again 👍

@mwood77
Copy link
Owner Author

mwood77 commented Nov 5, 2024

@NickNerfLips commit cd794ce has functional code for stepper motors controlled by a TMC2209. I've verified this on my test bench winderoo (USB-C ESP32 - identical to yours).

However, it isn't very refined. The motor steps and micro second interval still needs tweaking. Right now it's turning at around 100RPM, which is much faster than the target 40rpm. If you're feeling adventurous, you can adjust the value in this line to 937 or really anything between 900-ish to 950-ish.

uint64_t timerMicroSecondInterval = 400; // 937 microseconds for 40 RPM / 400 microseconds for 100 RPM

I couldn't reliably get my stepper motor to rotate in both directions at 900-ish, but it could be my power supply (3V line off an ESP32).

The pinout is still the same:

    const uint16_t EN_PIN   = 4; // Enable
    const uint16_t DIR_PIN  = 16; // Direction
    const uint16_t STEP_PIN = 17; // Step

Ignore the RX / TX pinouts, they aren't actually used. I still need to cleanup the code.

You might also experience a few hard-crashes here and there. Like I said, it's functional, but not ironed out yet.

@NickNerfLips
Copy link

You rock. I will plan to try it tomorrow and let you know.

@NickNerfLips
Copy link

OK, I tried the new code and some good news: it does now move my stepper motor.
I did have to change the pins (I don't have a PIN 16 and 17).
I used STEP = Pin 18 and DIR = Pin 19.

I tried changing microsecond interval, but after the stepper motor pauses more frequently.

Both directions seemed to work OK (albeit with the pauses, not continuous movement).

Issues I saw:

  • Frequent ESP32 resetting, like you mentioned
  • No continuous stepper motor movement...intermittent pauses
  • Stepper did seem to get very hot when micro steps were set to 400 (before I changed the microsecond interval)

Please let me know if you'd like me to try anything else.

@NickNerfLips
Copy link

Another thing I noticed when playing with microstep values, definitely some relationship between the motor smoothly rotating (at lower microstep value of 100-200, etc.).
Not sure if there's a correlation, but it also seems to take new values/directions better at lower microstep values.

Lastly, I'm seeing an inverse relationship between set rotation direction and actual stepper rotation direction.

@mwood77
Copy link
Owner Author

mwood77 commented Nov 6, 2024

@NickNerfLips OK, I'm going to update issue #68 with your feedback, as those are all actual issues.

Let's move our chat there so we can keep track of it a bit better; we're a bit all over the place between this PR, discussion #61 , and issue #68 .

Can you please reply to me in issue #68 with your microsecond, mA, and microstep values were?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants