Custom TMC5160 Motorized Rail and User Interface

A forum to ask questions, post setups, and generally discuss anything having to do with photomacrography and photomicroscopy.

Moderators: Pau, rjlittlefield, ChrisR, Chris S.

kaleun96
Posts: 195
Joined: Sat Oct 20, 2018 3:47 pm
Location: Stockholm, Sweden

Custom TMC5160 Motorized Rail and User Interface

Post by kaleun96 »

The Trinamic stepper motor drivers are all the rage and deservedly so. I've primarily been using the TMC2130 the past two years but the TMC5160 drivers from Watterott were updated to support a feature mawyatt had been raving about - Motion Controller mode. Instead of having an Arduino or RPi telling the driver to step the motor, how many times, and how frequently, the Motion Controller mode means you set a target and the driver takes care of the rest. Not only is it easier for the user to configure but it also frees up the Arduino to do other things while the stepper is moving!

So I overhauled my old controller and software for the third time to support this significant upgrade. While I was at it, I wanted to achieve a few other things:
  • Custom PCB
  • Better joystick
  • Custom library for implementing buttons and touch control
  • Faster screen refresh rate
This isn't going to be a guide or even an in-depth overview but I hope to add more to this thread overtime as my setup adapts. And since everyone here has their own wants and needs when it comes to a macro setup, I'm not here to say you should do this or that but rather just to share my approach and hopefully give back a little to this great community.

Custom PCB:
To start with, here's the custom PCB I designed. This was a first for me and surprisingly not as difficult as I expected once you get a handle of the software (Eagle). It was also relatively cheap, about 30 euro for three boards if I remember correctly. I could also order most of the components with the PCBs. You can see I had fun trying to fill in the empty space with some macro related images.
MacroStepper_v2.0_top.jpg
It has a Arduino Mega / Due / Grand Central M4 shield form factor so it can plug directly into the headers of those boards. This was key for me to keep the overall size of the electronics at a minimum and even when used in conjunction with a screen it's quite small and tidy.
Here is the progression (from right to left) of the boards I've created for my macro setup over the past two years. The custom PCB is smaller, neater, and fits more on the board. It also says TMC2130 but supports the TMC5160 board with no modifications.
20200119_144430 (1).jpg
Custom Arduino Library
This was another challenge and another first for me as I'm not a software developer and consider myself OK at Arduino things.

My previous touch-screen implementation worked well but the code was spaghetti - all the button placements and touch detection was hardcoded across dozens of parts of the program. If I moved a button, I had to update the dimensions and locations for that button and others across multiple files, as well as the co-ordinates that would trigger the button based on a touch input.

The new library aimed to solve that by having the user create the button once with several additional parameters and then taking care off drawing the button, detecting touch, changing button state, calling other functions, writing text, centering text, overwriting text etc via other simple functions. So far it works very well and supports all of my use cases such as shared buttons on multiple "screens", inter-dependent buttons, bitmaps as buttons, fast text replacement and refresh rate, toggle and momentary buttons, joystick navigation etc.

The library can be found on my github here. I'm not good at writing code for others but have included a fairly comprehensive example taken from my main program. If you're not a fan of touch screens, you can also use another input such as a joystick or arrow-key buttons to navigate through your screens, menus, buttons, and inputs. This is enabled in addition to touch in the example code but I don't use it myself for my main program.

Video of me demonstrating the user interface, joystick control, stallGuard homing, etc: https://www.youtube.com/watch?v=Nf2cB-ZaPhQ
I haven't finished configuring the stepper driver yet, it's still too noisy for my tastes at high velocities (for stepping it's dead quiet) but the current config is good enough for testing at the moment. There's also a few bugs left to squash and I hadn't connected the flash setup for this demo (hence the flash test and flash buttons having no effect).

Lastly, you can find the code for my current program and user interface here: https://github.com/camdey/MacroStepper
It's not quite finished but definitely in a working state with a few small bugs and improvements to be made. Once I finish the physical setup for my motorized rail, I'll probably post them as updates to this thread to keep it all in one place.

The files for the PCB can also be found at the above github repo - feel free to use or adapt (for non-commercial purposes) if you find them useful.
- Cam

lonepal
Posts: 321
Joined: Sat Jan 28, 2017 12:26 pm
Location: Turkey

Re: Custom TMC5160 Motorized Rail and User Interface

Post by lonepal »

Thank you for sharing!
Regards.
Omer

Post Reply Previous topicNext topic