Skip to content

Getting started

Christian Köhlke edited this page Dec 16, 2024 · 8 revisions

Installation

Installation with PIP

pip3 install TMC-2209-Raspberry-Pi

Installation with GIT

clone this repo to your Raspberry Pi using

git clone https://github.com/Chr157i4n/TMC2209_Raspberry_Pi

install the python module bitstring with

pip3 install bitstring

Serial Port

If you use the Raspberry Pi OS you can enable the serial port in

sudo raspi-config
raspi-config

make sure that you disable the login shell over serial

Would you like a login shell to be accessible over serial?  --> No
Would you like the serial port hardware to be enabled? --> Yes

For other OS, you must check yourself how to activate the serial interface.

In Order to gain access to the serial port on the Raspberry Pi OS, you must add your user to the dialout group:

sudo usermod -a -G dialout <your-user>

You can check the permission on your serial port with

ls -lha /dev/serial0

This should show a symbolic link to your actual serial port /dev/serial0 -> ttyS0

ls -lha /dev/ttyS0

grafik

It should show, that the dialout group has read/write access to the file. Otherwise you need to change the permissions on that file with chmod.

Wiring

Pin TMC2209 connect to Function
TX or PDN_UART with 1kOhm TX of Raspberry Pi send data to TMC via UART
RX or PDN_UART directly RX of Raspberry Pi receive data from TMC via UART
VM 12V or 24V of power supply power for the motor
GND GND of power supply power for the motor
VDD 3,3V of Raspberry Pi optional, for more stable logic voltage
GND GND of Raspberry Pi GND for VDD and Signals
EN GPIO21 of Raspberry Pi enable the motor output
STEP GPIO16 of Raspberry Pi moves the motor one step per pulse
DIR GPIO20 of Raspberry Pi set the direction of the motor
DIAG GPIO26 of Raspberry Pi optional, for StallGuard

wiring diagram

The GPIO pins can be specific when initiating the class. If you test this on a breadboard, make sure to cut off the bottomside of the pins (Vref and DIAG) next to the EN pin, so that they are not shorted trough the breadboard.

Demo scripts

You can run the demo scripts files from the main directory with

python3 -m demo.demo_script_01_uart_connection

This only communicates with the TMC driver over UART. It should set some settings in the driver and then outputs the settings. When it outputs TMC2209: UART Communication Error, you need to check the UART-connection.

This script enables the raspberry GPIO output for the dir, en and step pin and then checks the TMC driver register, whether the driver sees them as HIGH or LOW. Because the enabled pin is activated for a short time, the motor current ouput will be also activated in this script for a short time. This script should output: Pin DIR: OK Pin STEP: OK Pin EN: OK if not, check the connection of the pin.

This script should move the motor 6 times, one revolution back and forth.

In this script the stallguard feature of the TMC2209 is beeing setup. A funtion will be called, if the driver detects a stall. The function stops the current movement. The motor will be moved 10 revolutions. If the movement is finished unhindered, the script outputs Movement finished successfully. If you block the motor with pliers or something similar, the the motor will stop and the script outputs StallGuard! and Movement was not completed

VACTUAL allows moving the motor by UART control. It gives the motor velocity in +-(2^23)-1 [μsteps / t]

Multiple drivers can be addressed via UART by setting different addresses with the MS1 and MS2 pins. Simultaneous movement of multiple motors can be done with threaded movement.

In this script, the movement of a stepper with threads is shown. This can be used to do other task while moving a motor, or to move several motors simultaneous.

This script shows how you can alter the formatting of the TMC2209 log messages and redirect the log output to a file called tmc2209_log_file.log that will be created in the current directory.



For me these baudrates worked fine: 19200, 38400, 57600, 115200, 230400, 460800, 576000.

If the TMC2209 driver is connected to the Vmotor, the internal voltage regulator will create the Vio for the chip. So you don't need to connect anything to the Vio pin of the driver.

Usage

from TMC_2209.TMC_2209_StepperDriver import *
tmc = TMC_2209(21, 16, 20)

tmc.set_direction_reg(False)
tmc.set_current(300)
tmc.set_interpolation(True)
tmc.set_spreadcycle(False)
tmc.set_microstepping_resolution(2)
tmc.set_internal_rsense(False)

tmc.set_acceleration(2000)
tmc.set_max_speed(500)

tmc.set_motor_enabled(True)

tmc.run_to_position_steps(400)
tmc.run_to_position_steps(0)

tmc.set_motor_enabled(False)

wiring photo