PyTmcStepper 0.10.0__tar.gz → 0.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/PKG-INFO +25 -17
  2. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/README.md +24 -16
  3. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/pyproject.toml +1 -1
  4. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/PyTmcStepper.egg-info/PKG-INFO +25 -17
  5. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/PyTmcStepper.egg-info/SOURCES.txt +9 -2
  6. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/_tmc_stallguard.py +89 -6
  7. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/_tmc_stepperdriver.py +77 -72
  8. pytmcstepper-0.12.0/src/tmc_driver/_tmc_xxxx.py +472 -0
  9. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/_tmc_com.py +5 -6
  10. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/_tmc_com_spi_base.py +2 -11
  11. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/_tmc_com_uart_base.py +3 -22
  12. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/_tmc_com_uart_micropython.py +0 -3
  13. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/enable_control/_tmc_ec.py +8 -6
  14. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/enable_control/_tmc_ec_pin.py +4 -4
  15. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/enable_control/_tmc_ec_toff.py +3 -5
  16. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/motion_control/_tmc_mc.py +13 -5
  17. pytmcstepper-0.12.0/src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py +194 -0
  18. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +26 -34
  19. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py +12 -4
  20. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +3 -5
  21. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +11 -25
  22. pytmcstepper-0.12.0/src/tmc_driver/platform_utils.py +13 -0
  23. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/reg/_tmc2209_reg.py +5 -5
  24. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/reg/_tmc220x_reg.py +18 -17
  25. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/reg/_tmc224x_reg.py +49 -39
  26. pytmcstepper-0.12.0/src/tmc_driver/reg/_tmc5160_reg.py +525 -0
  27. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/reg/_tmc_reg.py +39 -33
  28. pytmcstepper-0.12.0/src/tmc_driver/reg/_tmc_shared_regs.py +314 -0
  29. pytmcstepper-0.12.0/src/tmc_driver/tmc_2208.py +17 -0
  30. pytmcstepper-0.12.0/src/tmc_driver/tmc_2209.py +75 -0
  31. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_220x.py +397 -531
  32. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_2240.py +64 -270
  33. pytmcstepper-0.12.0/src/tmc_driver/tmc_5160.py +328 -0
  34. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_gpio/__init__.py +1 -1
  35. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_base.py +1 -1
  36. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py +3 -2
  37. pytmcstepper-0.12.0/src/tmc_driver/tmc_logger/__init__.py +15 -0
  38. pytmcstepper-0.12.0/src/tmc_driver/tmc_logger/_tmc_logger_base.py +111 -0
  39. pytmcstepper-0.12.0/src/tmc_driver/tmc_logger/_tmc_logger_cpython.py +155 -0
  40. pytmcstepper-0.12.0/src/tmc_driver/tmc_logger/_tmc_logger_micropython.py +50 -0
  41. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc_com_spi.py +1 -2
  42. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc_com_uart.py +1 -2
  43. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc_ec_pin.py +2 -3
  44. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc_modules.py +48 -2
  45. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc_set_current.py +35 -5
  46. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc_stallguard.py +26 -0
  47. pytmcstepper-0.10.0/src/tmc_driver/_tmc_logger.py +0 -219
  48. pytmcstepper-0.10.0/src/tmc_driver/reg/_tmc_shared_regs.py +0 -54
  49. pytmcstepper-0.10.0/src/tmc_driver/tmc_2208.py +0 -11
  50. pytmcstepper-0.10.0/src/tmc_driver/tmc_2209.py +0 -139
  51. pytmcstepper-0.10.0/src/tmc_driver/tmc_xxxx.py +0 -230
  52. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/LICENSE +0 -0
  53. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/setup.cfg +0 -0
  54. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  55. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  56. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  57. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/__init__.py +0 -0
  58. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/_tmc_exceptions.py +0 -0
  59. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/_tmc_math.py +0 -0
  60. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/_tmc_validation.py +0 -0
  61. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/__init__.py +0 -0
  62. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/_tmc_com_spi.py +0 -0
  63. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/_tmc_com_spi_ftdi.py +0 -0
  64. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/_tmc_com_spi_micropython.py +0 -0
  65. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/com/_tmc_com_uart.py +0 -0
  66. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/enable_control/__init__.py +0 -0
  67. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/motion_control/__init__.py +0 -0
  68. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/reg/__init__.py +0 -0
  69. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_ftdi.py +0 -0
  70. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py +0 -0
  71. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py +0 -0
  72. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py +0 -0
  73. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc2209.py +0 -0
  74. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc2240.py +0 -0
  75. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc_math.py +0 -0
  76. {pytmcstepper-0.10.0 → pytmcstepper-0.12.0}/tests/test_tmc_move.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.10.0
3
+ Version: 0.12.0
4
4
  Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
5
5
  Author-email: Christian Köhlke <christian@koehlke.de>
6
6
  License-Expression: GPL-3.0
@@ -37,9 +37,9 @@ Dynamic: license-file
37
37
 
38
38
  \
39
39
  \
40
- This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi.
40
+ This is a Python library to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi.
41
41
 
42
- This code is still experimental, so use it on your own risk.
42
+ This code is still experimental, so use it at your own risk.
43
43
 
44
44
  This library is programmed in pure Python. The performance of Python is not good enough to drive the motor with high speed.
45
45
  So if you move the motor with high speed using this library the motor will lose steps.
@@ -47,13 +47,13 @@ So if you move the motor with high speed using this library the motor will lose
47
47
  Tested on a [Bigtreetech TMC2209 V1.2](https://github.com/bigtreetech/BIGTREETECH-Stepper-Motor-Driver/tree/master/TMC2209/V1.2) and [Bigtreetech TMC2209 V1.3](https://github.com/bigtreetech/BIGTREETECH-Stepper-Motor-Driver/tree/master/TMC2209/V1.3).
48
48
 
49
49
  It has a rSense of 110 mOhm and it uses one Pin (PDN_UART) for UART RX and TX.
50
- So the PDN_UART-Pin needs to be connected to the Raspberrry Pis RX-Pin directly and to the TX-Pin with an 1kOhm resistor.
50
+ So the PDN_UART-Pin needs to be connected to the Raspberry Pis RX-Pin directly and to the TX-Pin with an 1kOhm resistor.
51
51
  You can read more about this in the datasheet from Trinamic.
52
52
 
53
53
  Because the TMC2209 uses one shared pin for transmit and receive in the UART communication line, the Raspberry Pi also receives what it sends.
54
54
  Well, the Pi receives 4 bytes from itself and 8 bytes from the driver. So the Pi receives a total of 12 bytes and only the last 8 are the reply, of which only 4 are data bytes.
55
55
 
56
- The Documentation of the TMC2209 can be found here:
56
+ The documentation of the TMC2209 can be found here:
57
57
  [TMC2209 - Datasheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
58
58
 
59
59
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
@@ -72,6 +72,13 @@ pip3 install PyTmcStepper
72
72
 
73
73
  ```shell
74
74
  git clone https://github.com/Chr157i4n/PyTmcStepper
75
+ cd PyTmcStepper
76
+ ```
77
+
78
+ - (optional) install the lib to get proper syntax highlighting and start the demo scripts from every path
79
+
80
+ ```shell
81
+ pip3 install -e .
75
82
  ```
76
83
 
77
84
  - install the required modules
@@ -88,20 +95,20 @@ pip3 install PyTmcStepper
88
95
 
89
96
  ### Board Support
90
97
 
91
- The following table shows the supported boards and which libraries for GPIO access is beeing used for that board.
98
+ The following table shows the supported boards and which libraries for GPIO access is being used for that board.
92
99
 
93
100
  Library | Installation Parameter | Boards
94
101
  ----------- | ------------------------- | -----------
95
102
  RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
96
103
  gpiozero | RASPBERRY_PI5 | Pi5
97
104
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
98
- pheriphery | LUCKFOX_PICO | Luckfox Pico
105
+ periphery | LUCKFOX_PICO | Luckfox Pico
99
106
  OPi.GPIO | ORANGE_PI | Orange Pi
100
107
  pyftdi | - | Windows/Linux
101
108
  machine | - | Pico, Pico2, ESP32, etc.
102
109
 
103
110
  Those libraries are needed for this library to work. You can either install the correct library yourself.
104
- You can also install the needed GPIO library by specifing the Installation Parameter while installing this library:
111
+ You can also install the needed GPIO library by specifying the Installation Parameter while installing this library:
105
112
 
106
113
  ```shell
107
114
  pip3 install PyTmcStepper[RASPBERRY_PI]
@@ -116,10 +123,11 @@ Driver | Interface
116
123
  TMC2208 | UART
117
124
  TMC2209 | UART
118
125
  TMC2240 | SPI/UART
126
+ TMC5160 | SPI/UART
119
127
 
120
128
  ## Submodules
121
129
 
122
- with V0.7 the code for enabling the motor current output and the code for controling the motion of the drivers
130
+ with V0.7 the code for enabling the motor current output and the code for controlling the motion of the drivers
123
131
  is split into their own classes to be able to support the diverse methods.
124
132
 
125
133
  ### EnableControl
@@ -135,16 +143,16 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
135
143
 
136
144
  The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
137
145
 
138
- MotionControl | Class | Driver | Notes
139
- -- | -- | -- | --
140
- STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
141
- STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
142
- VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
143
- STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
146
+ MotionControl | Class | Driver | Notes
147
+ -- | -- | -- | --
148
+ STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
149
+ STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
150
+ VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
151
+ STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
152
+ RAMP_GENERATOR | [TmcMotionControlIntRampGenerator](src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py) | TMC5160 | the SD_Mode Pin needs to be LOW for this to work. This is not possible on all TMC5160-Boards easily.
144
153
 
145
154
  Further methods of controlling the motion of a motor could be:
146
155
 
147
- - using the built in Motion Controller of the TMC5130
148
156
  - via a µC which controlls the Motor
149
157
  - highperformance Step/Dir Library written in a compiled language (C/C++)
150
158
 
@@ -158,7 +166,7 @@ SPI over FT232H | [TmcComSpiFtdi](src/tmc_driver/com/_tmc_com_spi_ftdi.py) | TM
158
166
 
159
167
  ## Wiring
160
168
 
161
- ![wiring diagram](docs/images/wiring_diagram.png)
169
+ ![wiring diagram](docs/images/wiring_tmc2209_rpi4.png)
162
170
 
163
171
  Pin TMC | Color | connect to | Function
164
172
  -- | -- | -- | --
@@ -7,9 +7,9 @@
7
7
 
8
8
  \
9
9
  \
10
- This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi.
10
+ This is a Python library to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi.
11
11
 
12
- This code is still experimental, so use it on your own risk.
12
+ This code is still experimental, so use it at your own risk.
13
13
 
14
14
  This library is programmed in pure Python. The performance of Python is not good enough to drive the motor with high speed.
15
15
  So if you move the motor with high speed using this library the motor will lose steps.
@@ -17,13 +17,13 @@ So if you move the motor with high speed using this library the motor will lose
17
17
  Tested on a [Bigtreetech TMC2209 V1.2](https://github.com/bigtreetech/BIGTREETECH-Stepper-Motor-Driver/tree/master/TMC2209/V1.2) and [Bigtreetech TMC2209 V1.3](https://github.com/bigtreetech/BIGTREETECH-Stepper-Motor-Driver/tree/master/TMC2209/V1.3).
18
18
 
19
19
  It has a rSense of 110 mOhm and it uses one Pin (PDN_UART) for UART RX and TX.
20
- So the PDN_UART-Pin needs to be connected to the Raspberrry Pis RX-Pin directly and to the TX-Pin with an 1kOhm resistor.
20
+ So the PDN_UART-Pin needs to be connected to the Raspberry Pis RX-Pin directly and to the TX-Pin with an 1kOhm resistor.
21
21
  You can read more about this in the datasheet from Trinamic.
22
22
 
23
23
  Because the TMC2209 uses one shared pin for transmit and receive in the UART communication line, the Raspberry Pi also receives what it sends.
24
24
  Well, the Pi receives 4 bytes from itself and 8 bytes from the driver. So the Pi receives a total of 12 bytes and only the last 8 are the reply, of which only 4 are data bytes.
25
25
 
26
- The Documentation of the TMC2209 can be found here:
26
+ The documentation of the TMC2209 can be found here:
27
27
  [TMC2209 - Datasheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
28
28
 
29
29
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
@@ -42,6 +42,13 @@ pip3 install PyTmcStepper
42
42
 
43
43
  ```shell
44
44
  git clone https://github.com/Chr157i4n/PyTmcStepper
45
+ cd PyTmcStepper
46
+ ```
47
+
48
+ - (optional) install the lib to get proper syntax highlighting and start the demo scripts from every path
49
+
50
+ ```shell
51
+ pip3 install -e .
45
52
  ```
46
53
 
47
54
  - install the required modules
@@ -58,20 +65,20 @@ pip3 install PyTmcStepper
58
65
 
59
66
  ### Board Support
60
67
 
61
- The following table shows the supported boards and which libraries for GPIO access is beeing used for that board.
68
+ The following table shows the supported boards and which libraries for GPIO access is being used for that board.
62
69
 
63
70
  Library | Installation Parameter | Boards
64
71
  ----------- | ------------------------- | -----------
65
72
  RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
66
73
  gpiozero | RASPBERRY_PI5 | Pi5
67
74
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
68
- pheriphery | LUCKFOX_PICO | Luckfox Pico
75
+ periphery | LUCKFOX_PICO | Luckfox Pico
69
76
  OPi.GPIO | ORANGE_PI | Orange Pi
70
77
  pyftdi | - | Windows/Linux
71
78
  machine | - | Pico, Pico2, ESP32, etc.
72
79
 
73
80
  Those libraries are needed for this library to work. You can either install the correct library yourself.
74
- You can also install the needed GPIO library by specifing the Installation Parameter while installing this library:
81
+ You can also install the needed GPIO library by specifying the Installation Parameter while installing this library:
75
82
 
76
83
  ```shell
77
84
  pip3 install PyTmcStepper[RASPBERRY_PI]
@@ -86,10 +93,11 @@ Driver | Interface
86
93
  TMC2208 | UART
87
94
  TMC2209 | UART
88
95
  TMC2240 | SPI/UART
96
+ TMC5160 | SPI/UART
89
97
 
90
98
  ## Submodules
91
99
 
92
- with V0.7 the code for enabling the motor current output and the code for controling the motion of the drivers
100
+ with V0.7 the code for enabling the motor current output and the code for controlling the motion of the drivers
93
101
  is split into their own classes to be able to support the diverse methods.
94
102
 
95
103
  ### EnableControl
@@ -105,16 +113,16 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
105
113
 
106
114
  The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
107
115
 
108
- MotionControl | Class | Driver | Notes
109
- -- | -- | -- | --
110
- STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
111
- STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
112
- VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
113
- STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
116
+ MotionControl | Class | Driver | Notes
117
+ -- | -- | -- | --
118
+ STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
119
+ STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
120
+ VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
121
+ STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
122
+ RAMP_GENERATOR | [TmcMotionControlIntRampGenerator](src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py) | TMC5160 | the SD_Mode Pin needs to be LOW for this to work. This is not possible on all TMC5160-Boards easily.
114
123
 
115
124
  Further methods of controlling the motion of a motor could be:
116
125
 
117
- - using the built in Motion Controller of the TMC5130
118
126
  - via a µC which controlls the Motor
119
127
  - highperformance Step/Dir Library written in a compiled language (C/C++)
120
128
 
@@ -128,7 +136,7 @@ SPI over FT232H | [TmcComSpiFtdi](src/tmc_driver/com/_tmc_com_spi_ftdi.py) | TM
128
136
 
129
137
  ## Wiring
130
138
 
131
- ![wiring diagram](docs/images/wiring_diagram.png)
139
+ ![wiring diagram](docs/images/wiring_tmc2209_rpi4.png)
132
140
 
133
141
  Pin TMC | Color | connect to | Function
134
142
  -- | -- | -- | --
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PyTmcStepper"
7
- version = "0.10.0"
7
+ version = "0.12.0"
8
8
  authors = [{ name = "Christian Köhlke", email = "christian@koehlke.de" }]
9
9
  description = "This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi"
10
10
  readme = "README.md"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTmcStepper
3
- Version: 0.10.0
3
+ Version: 0.12.0
4
4
  Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
5
5
  Author-email: Christian Köhlke <christian@koehlke.de>
6
6
  License-Expression: GPL-3.0
@@ -37,9 +37,9 @@ Dynamic: license-file
37
37
 
38
38
  \
39
39
  \
40
- This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi.
40
+ This is a Python library to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi.
41
41
 
42
- This code is still experimental, so use it on your own risk.
42
+ This code is still experimental, so use it at your own risk.
43
43
 
44
44
  This library is programmed in pure Python. The performance of Python is not good enough to drive the motor with high speed.
45
45
  So if you move the motor with high speed using this library the motor will lose steps.
@@ -47,13 +47,13 @@ So if you move the motor with high speed using this library the motor will lose
47
47
  Tested on a [Bigtreetech TMC2209 V1.2](https://github.com/bigtreetech/BIGTREETECH-Stepper-Motor-Driver/tree/master/TMC2209/V1.2) and [Bigtreetech TMC2209 V1.3](https://github.com/bigtreetech/BIGTREETECH-Stepper-Motor-Driver/tree/master/TMC2209/V1.3).
48
48
 
49
49
  It has a rSense of 110 mOhm and it uses one Pin (PDN_UART) for UART RX and TX.
50
- So the PDN_UART-Pin needs to be connected to the Raspberrry Pis RX-Pin directly and to the TX-Pin with an 1kOhm resistor.
50
+ So the PDN_UART-Pin needs to be connected to the Raspberry Pis RX-Pin directly and to the TX-Pin with an 1kOhm resistor.
51
51
  You can read more about this in the datasheet from Trinamic.
52
52
 
53
53
  Because the TMC2209 uses one shared pin for transmit and receive in the UART communication line, the Raspberry Pi also receives what it sends.
54
54
  Well, the Pi receives 4 bytes from itself and 8 bytes from the driver. So the Pi receives a total of 12 bytes and only the last 8 are the reply, of which only 4 are data bytes.
55
55
 
56
- The Documentation of the TMC2209 can be found here:
56
+ The documentation of the TMC2209 can be found here:
57
57
  [TMC2209 - Datasheet](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2209_datasheet_rev1.09.pdf)
58
58
 
59
59
  The code is also available on [PyPI](https://pypi.org/project/PyTmcStepper).
@@ -72,6 +72,13 @@ pip3 install PyTmcStepper
72
72
 
73
73
  ```shell
74
74
  git clone https://github.com/Chr157i4n/PyTmcStepper
75
+ cd PyTmcStepper
76
+ ```
77
+
78
+ - (optional) install the lib to get proper syntax highlighting and start the demo scripts from every path
79
+
80
+ ```shell
81
+ pip3 install -e .
75
82
  ```
76
83
 
77
84
  - install the required modules
@@ -88,20 +95,20 @@ pip3 install PyTmcStepper
88
95
 
89
96
  ### Board Support
90
97
 
91
- The following table shows the supported boards and which libraries for GPIO access is beeing used for that board.
98
+ The following table shows the supported boards and which libraries for GPIO access is being used for that board.
92
99
 
93
100
  Library | Installation Parameter | Boards
94
101
  ----------- | ------------------------- | -----------
95
102
  RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
96
103
  gpiozero | RASPBERRY_PI5 | Pi5
97
104
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
98
- pheriphery | LUCKFOX_PICO | Luckfox Pico
105
+ periphery | LUCKFOX_PICO | Luckfox Pico
99
106
  OPi.GPIO | ORANGE_PI | Orange Pi
100
107
  pyftdi | - | Windows/Linux
101
108
  machine | - | Pico, Pico2, ESP32, etc.
102
109
 
103
110
  Those libraries are needed for this library to work. You can either install the correct library yourself.
104
- You can also install the needed GPIO library by specifing the Installation Parameter while installing this library:
111
+ You can also install the needed GPIO library by specifying the Installation Parameter while installing this library:
105
112
 
106
113
  ```shell
107
114
  pip3 install PyTmcStepper[RASPBERRY_PI]
@@ -116,10 +123,11 @@ Driver | Interface
116
123
  TMC2208 | UART
117
124
  TMC2209 | UART
118
125
  TMC2240 | SPI/UART
126
+ TMC5160 | SPI/UART
119
127
 
120
128
  ## Submodules
121
129
 
122
- with V0.7 the code for enabling the motor current output and the code for controling the motion of the drivers
130
+ with V0.7 the code for enabling the motor current output and the code for controlling the motion of the drivers
123
131
  is split into their own classes to be able to support the diverse methods.
124
132
 
125
133
  ### EnableControl
@@ -135,16 +143,16 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
135
143
 
136
144
  The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
137
145
 
138
- MotionControl | Class | Driver | Notes
139
- -- | -- | -- | --
140
- STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
141
- STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
142
- VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
143
- STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
146
+ MotionControl | Class | Driver | Notes
147
+ -- | -- | -- | --
148
+ STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
149
+ STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
150
+ VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
151
+ STEP_PWM/DIR | [TmcMotionControlStepPwmDir](src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py) | all | In contrast to STEP/DIR, the step pin is controlled by PWM. This reduces the load on the CPU, but does not allow precise positioning (similar to the VACTUAL).<br />STEP must be connected to a PWM-capable pin for this purpose
152
+ RAMP_GENERATOR | [TmcMotionControlIntRampGenerator](src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py) | TMC5160 | the SD_Mode Pin needs to be LOW for this to work. This is not possible on all TMC5160-Boards easily.
144
153
 
145
154
  Further methods of controlling the motion of a motor could be:
146
155
 
147
- - using the built in Motion Controller of the TMC5130
148
156
  - via a µC which controlls the Motor
149
157
  - highperformance Step/Dir Library written in a compiled language (C/C++)
150
158
 
@@ -158,7 +166,7 @@ SPI over FT232H | [TmcComSpiFtdi](src/tmc_driver/com/_tmc_com_spi_ftdi.py) | TM
158
166
 
159
167
  ## Wiring
160
168
 
161
- ![wiring diagram](docs/images/wiring_diagram.png)
169
+ ![wiring diagram](docs/images/wiring_tmc2209_rpi4.png)
162
170
 
163
171
  Pin TMC | Color | connect to | Function
164
172
  -- | -- | -- | --
@@ -8,16 +8,17 @@ src/PyTmcStepper.egg-info/requires.txt
8
8
  src/PyTmcStepper.egg-info/top_level.txt
9
9
  src/tmc_driver/__init__.py
10
10
  src/tmc_driver/_tmc_exceptions.py
11
- src/tmc_driver/_tmc_logger.py
12
11
  src/tmc_driver/_tmc_math.py
13
12
  src/tmc_driver/_tmc_stallguard.py
14
13
  src/tmc_driver/_tmc_stepperdriver.py
15
14
  src/tmc_driver/_tmc_validation.py
15
+ src/tmc_driver/_tmc_xxxx.py
16
+ src/tmc_driver/platform_utils.py
16
17
  src/tmc_driver/tmc_2208.py
17
18
  src/tmc_driver/tmc_2209.py
18
19
  src/tmc_driver/tmc_220x.py
19
20
  src/tmc_driver/tmc_2240.py
20
- src/tmc_driver/tmc_xxxx.py
21
+ src/tmc_driver/tmc_5160.py
21
22
  src/tmc_driver/com/__init__.py
22
23
  src/tmc_driver/com/_tmc_com.py
23
24
  src/tmc_driver/com/_tmc_com_spi.py
@@ -33,6 +34,7 @@ src/tmc_driver/enable_control/_tmc_ec_pin.py
33
34
  src/tmc_driver/enable_control/_tmc_ec_toff.py
34
35
  src/tmc_driver/motion_control/__init__.py
35
36
  src/tmc_driver/motion_control/_tmc_mc.py
37
+ src/tmc_driver/motion_control/_tmc_mc_int_ramp_generator.py
36
38
  src/tmc_driver/motion_control/_tmc_mc_step_dir.py
37
39
  src/tmc_driver/motion_control/_tmc_mc_step_pwm_dir.py
38
40
  src/tmc_driver/motion_control/_tmc_mc_step_reg.py
@@ -41,6 +43,7 @@ src/tmc_driver/reg/__init__.py
41
43
  src/tmc_driver/reg/_tmc2209_reg.py
42
44
  src/tmc_driver/reg/_tmc220x_reg.py
43
45
  src/tmc_driver/reg/_tmc224x_reg.py
46
+ src/tmc_driver/reg/_tmc5160_reg.py
44
47
  src/tmc_driver/reg/_tmc_reg.py
45
48
  src/tmc_driver/reg/_tmc_shared_regs.py
46
49
  src/tmc_driver/tmc_gpio/__init__.py
@@ -50,6 +53,10 @@ src/tmc_driver/tmc_gpio/_tmc_gpio_board_gpiozero.py
50
53
  src/tmc_driver/tmc_gpio/_tmc_gpio_board_micropython.py
51
54
  src/tmc_driver/tmc_gpio/_tmc_gpio_board_periphery.py
52
55
  src/tmc_driver/tmc_gpio/_tmc_gpio_board_rpi_gpio.py
56
+ src/tmc_driver/tmc_logger/__init__.py
57
+ src/tmc_driver/tmc_logger/_tmc_logger_base.py
58
+ src/tmc_driver/tmc_logger/_tmc_logger_cpython.py
59
+ src/tmc_driver/tmc_logger/_tmc_logger_micropython.py
53
60
  tests/test_tmc2209.py
54
61
  tests/test_tmc2240.py
55
62
  tests/test_tmc_com_spi.py
@@ -15,7 +15,7 @@ from ._tmc_stepperdriver import *
15
15
  from .com._tmc_com import TmcCom
16
16
  from .tmc_gpio import GpioPUD, GpioMode
17
17
  from . import tmc_gpio
18
- from ._tmc_logger import Loglevel
18
+ from .tmc_logger import Loglevel
19
19
  from .reg import _tmc_shared_regs as tmc_shared_regs
20
20
  from . import _tmc_math as tmc_math
21
21
  from ._tmc_exceptions import (
@@ -39,9 +39,21 @@ class StallGuard:
39
39
  tmc_mc: TmcMotionControl
40
40
 
41
41
  coolconf: tmc_shared_regs.CoolConf
42
- sgthrs: tmc_shared_regs.SGThrs
43
- sgresult: tmc_shared_regs.SGResult
42
+ sgthrs: tmc_shared_regs.SgThrs
43
+ sgresult: tmc_shared_regs.SgResult
44
44
  tcoolthrs: tmc_shared_regs.TCoolThrs
45
+ drvstatus: tmc_shared_regs.DrvStatus
46
+
47
+ # Stub methods - implemented by the driver class (Tmc2209, Tmc2240, Tmc5160)
48
+ def set_spreadcycle(self, en: bool) -> None:
49
+ """Set spreadcycle mode. Implemented by driver class."""
50
+ raise NotImplementedError("set_spreadcycle must be implemented by driver class")
51
+
52
+ def get_microstepping_resolution(self) -> int:
53
+ """Get microstepping resolution. Implemented by driver class."""
54
+ raise NotImplementedError(
55
+ "get_microstepping_resolution must be implemented by driver class"
56
+ )
45
57
 
46
58
  @property
47
59
  def sg_callback(self):
@@ -221,7 +233,7 @@ class StallGuard:
221
233
  self.tmc_logger.log("---", Loglevel.INFO)
222
234
  self.tmc_logger.log("homing", Loglevel.INFO)
223
235
 
224
- self.set_spreadcycle(0)
236
+ self.set_spreadcycle(False)
225
237
 
226
238
  self.set_stallguard_callback(
227
239
  diag_pin,
@@ -238,11 +250,82 @@ class StallGuard:
238
250
 
239
251
  if homing_succeeded:
240
252
  self.tmc_logger.log("homing successful", Loglevel.INFO)
241
- if cb_success is not None:
253
+ if cb_success is not None and callable(cb_success):
242
254
  cb_success()
243
255
  else:
244
256
  self.tmc_logger.log("homing failed", Loglevel.INFO)
245
- if cb_failure is not None:
257
+ if cb_failure is not None and callable(cb_failure):
246
258
  cb_failure()
247
259
 
248
260
  return homing_succeeded
261
+
262
+ def test_stallguard_threshold(self, steps):
263
+ """test method for tuning stallguard threshold
264
+
265
+ run this function with your motor settings and your motor load
266
+ the function will determine the minimum stallguard results for each movement phase
267
+
268
+ Args:
269
+ steps (int):
270
+ """
271
+ if not isinstance(self.tmc_mc, TmcMotionControlStepDir):
272
+ raise TmcMotionControlException(
273
+ "tmc_mc is not of type TmcMotionControlStepDir; cannot test stallguard threshold"
274
+ )
275
+
276
+ self.tmc_logger.log("---", Loglevel.INFO)
277
+ self.tmc_logger.log("test_stallguard_threshold", Loglevel.INFO)
278
+
279
+ self.set_spreadcycle(False)
280
+
281
+ min_stallguard_result_accel = 512
282
+ min_stallguard_result_maxspeed = 512
283
+ min_stallguard_result_decel = 512
284
+
285
+ self.tmc_mc.run_to_position_steps_threaded(steps, MovementAbsRel.RELATIVE)
286
+
287
+ while self.tmc_mc.movement_phase != MovementPhase.STANDSTILL:
288
+ self.drvstatus.read()
289
+ stallguard_result = getattr(self.drvstatus, "sgresult", None)
290
+ if stallguard_result is None:
291
+ stallguard_result = self.get_stallguard_result()
292
+ stallguard_triggered = getattr(self.drvstatus, "stallguard", None)
293
+ cs_actual = getattr(self.drvstatus, "cs_actual", None)
294
+
295
+ self.tmc_logger.log(
296
+ f"{self.tmc_mc.movement_phase} | {stallguard_result} | {stallguard_triggered} | {cs_actual}",
297
+ Loglevel.INFO,
298
+ )
299
+
300
+ if (
301
+ self.tmc_mc.movement_phase == MovementPhase.ACCELERATING
302
+ and stallguard_result < min_stallguard_result_accel
303
+ ):
304
+ min_stallguard_result_accel = stallguard_result
305
+ if (
306
+ self.tmc_mc.movement_phase == MovementPhase.MAXSPEED
307
+ and stallguard_result < min_stallguard_result_maxspeed
308
+ ):
309
+ min_stallguard_result_maxspeed = stallguard_result
310
+ if (
311
+ self.tmc_mc.movement_phase == MovementPhase.DECELERATING
312
+ and stallguard_result < min_stallguard_result_decel
313
+ ):
314
+ min_stallguard_result_decel = stallguard_result
315
+
316
+ self.tmc_mc.wait_for_movement_finished_threaded()
317
+
318
+ self.tmc_logger.log("---", Loglevel.INFO)
319
+ self.tmc_logger.log(
320
+ f"min StallGuard result during accel: {min_stallguard_result_accel}",
321
+ Loglevel.INFO,
322
+ )
323
+ self.tmc_logger.log(
324
+ f"min StallGuard result during maxspeed: {min_stallguard_result_maxspeed}",
325
+ Loglevel.INFO,
326
+ )
327
+ self.tmc_logger.log(
328
+ f"min StallGuard result during decel: {min_stallguard_result_decel}",
329
+ Loglevel.INFO,
330
+ )
331
+ self.tmc_logger.log("---", Loglevel.INFO)