A Python library for controlling the TMC2209 stepper motor driver
Project description
TMC2209 Python Library
A Python library to configure and communicate with the TMC2209 stepper motor driver via UART. This library enables reading and writing to the TMC2209 registers, configuring microstepping, and setting driver parameters.
Features
- Read and write registers of TMC2209
- Configure driver settings (e.g., current, voltage, microsteps)
- UART communication with TMC2209
- Register-level access and control
Installation
This library depends on pyserial for UART communication. Install the required dependencies using:
pip install pyserial
To install the library
pip install TMC2209_PY
Before usage
Please read the datasheet of TMC2209 to understand the registers and their bits
Usage
1. Initialize UART Communication
First, create a UART instance to establish serial communication.
from uart import UART
uart = UART(port="/dev/ttyS0") # Use appropriate port
2. Configure the TMC2209 Driver
Create an instance of TMC2209Configure to control the stepper motor.
from TMC2209 import TMC2209Configure
tmc = TMC2209Configure(uart=uart, MS1=17, MS2=27, EN=22, node_address=0x00)
3. Initialize and Configure the Driver
To set up the motor driver:
tmc.initialize()
You can use this function to make sure that the connections are correct
4. Reading and Writing Registers
1. Writing to a Register
To write to a register, follow these steps:
- Set or reset the desired bits.
- Send the updated register values.
Syntax:
tmcModel.<RegisterName>.<BitName> = <Value> # Set the bit in the register
tmcModel.write_<RegisterName>() # Write the updated register value
Example:
tmc.gconf.shaft = 1 # Setting the shaft bit in GCONF register to reverse the direction
tmc.write_GCONF() # Writes GCONF register settings
2. Reading a Register
To read the value of a register, follow these steps:
- Call the corresponding
read_<RegisterName>()function. - Store the returned value in a variable.
Syntax:
<variable_name> = tmc.read_<RegisterName>() # Read the register value
Example:
gstat_value = tmc.read_GSTAT()
print(f"GSTAT Register Value: {gstat_value}")
5. Closing the UART Connection
uart.close()
Full Example Code
Below is a complete example that:
- Initializes the UART connection.
- Configures the TMC2209 driver.
- Writes to the VACTUAL register to move the motor.
- Reads a register value.
- Closes the UART connection when done.
from uart import UART
from TMC2209 import TMC2209Configure
# Initialize UART communication
uart = UART(port="/dev/ttyS0")
# Configure the TMC2209 driver
tmc = TMC2209Configure(uart=uart, MS1=17, MS2=27, EN=22, node_address=0x00)
# Initialize the driver settings
tmc.initialize()
# Example: Writing 1000 to VACTUAL register in order to move the motor
tmc.vactual.VACTUAL = 1000
tmc.write_VACTUAL()
# Read a register value
gstat_value = tmc.read_GSTAT()
print(f"GSTAT Register Value: {gstat_value}")
# Close the UART connection when done
uart.close()
Note:
The MS1 and MS2 pins in the uart interface determine the node address of the TMC2209 driver.
If your node address is different from 0x00, ensure that you correctly set the digital values of MS1 and MS2.
Extending the Library
The library is designed to be hardware-agnostic so it works on multiple platforms like Jetson Nano, Raspberry Pi, and other SBCs.
You can extend it by subclassing TMC2209Configure to add your own methods for custom behavior.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tmc2209_py-0.1.4.tar.gz.
File metadata
- Download URL: tmc2209_py-0.1.4.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7de38c42414a6ed4d53bc19ddbbe9ec82344d1a701dfd5f8d0a744d791c055e5
|
|
| MD5 |
88d824e203d929a9de115031c5941810
|
|
| BLAKE2b-256 |
7dc36082a640f1aea17d2a5dc8a730e81483b2a579acdc679e00093ecabfe66e
|
File details
Details for the file tmc2209_py-0.1.4-py3-none-any.whl.
File metadata
- Download URL: tmc2209_py-0.1.4-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a48736f666f041f18f2bae37974dd684b3959377a7d8a8acccb4fad7b61bb6d
|
|
| MD5 |
8f938858543c85135de474db050d900f
|
|
| BLAKE2b-256 |
569201812a3484cdbc90afdadacd76b941316c17254f5bb837e0a868c4638b9e
|