Skip to content

Commit 988a959

Browse files
authored
Merge pull request #142 from Chr157i4n/dev
version 0.16.0
2 parents dd315b1 + 6ac89b3 commit 988a959

23 files changed

+908
-48
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## version 0.16.0
4+
5+
- added basic support for CircuitPython
6+
- added demo scripts for CircuitPython
7+
- added lazy import for FtdiWrapper, to fix pyfdti needing to be installed
8+
- added more unittests
9+
310
## version 0.15.0
411

512
- updated python-publish workflow
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
Demo file for basic movement
3+
"""
4+
5+
import board
6+
from tmc_driver import (
7+
Tmc2209,
8+
Loglevel,
9+
TmcEnableControlPin,
10+
TmcMotionControlStepDir,
11+
MovementAbsRel,
12+
)
13+
from tmc_driver.com import TmcComUartCircuitPython
14+
15+
16+
print("---")
17+
print("SCRIPT START")
18+
print("---")
19+
20+
# -----------------------------------------------------------------------
21+
# initiate the Tmc2240 class
22+
# use your pins for pin_en, pin_step, pin_dir here
23+
# -----------------------------------------------------------------------
24+
tmc = Tmc2209(
25+
TmcEnableControlPin(board.GP18),
26+
TmcMotionControlStepDir(board.GP17, board.GP16),
27+
TmcComUartCircuitPython(tx=board.GP4, rx=board.GP5),
28+
loglevel=Loglevel.DEBUG,
29+
)
30+
31+
32+
# -----------------------------------------------------------------------
33+
# set the loglevel of the libary (currently only printed)
34+
# set whether the movement should be relative or absolute
35+
# both optional
36+
# -----------------------------------------------------------------------
37+
tmc.tmc_logger.loglevel = Loglevel.DEBUG
38+
tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
39+
40+
41+
# -----------------------------------------------------------------------
42+
# these functions change settings in the TMC register
43+
# -----------------------------------------------------------------------
44+
tmc.set_direction_reg(False)
45+
tmc.set_current_rms(300)
46+
tmc.set_interpolation(True)
47+
tmc.set_spreadcycle(False)
48+
tmc.set_microstepping_resolution(2)
49+
tmc.set_internal_rsense(False)
50+
51+
52+
print("---\n---")
53+
54+
55+
# -----------------------------------------------------------------------
56+
# this function test whether the connection of the DIR, STEP and EN pin
57+
# between Raspberry Pi and TMC driver is working
58+
# -----------------------------------------------------------------------
59+
tmc.test_dir_step_en()
60+
61+
print("---\n---")
62+
63+
64+
# -----------------------------------------------------------------------
65+
# deactivate the motor current output
66+
# -----------------------------------------------------------------------
67+
tmc.set_motor_enabled(False)
68+
69+
print("---\n---")
70+
71+
72+
# -----------------------------------------------------------------------
73+
# deinitiate the Tmc2209 class
74+
# -----------------------------------------------------------------------
75+
del tmc
76+
77+
print("---")
78+
print("SCRIPT FINISHED")
79+
print("---")
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Demo file for testing the UART connection
3+
"""
4+
5+
import board
6+
from tmc_driver import Tmc2209, Loglevel, TmcEnableControlPin, TmcMotionControlStepDir
7+
from tmc_driver.com import TmcComUartCircuitPython
8+
9+
10+
print("---")
11+
print("SCRIPT START")
12+
print("---")
13+
14+
15+
# -----------------------------------------------------------------------
16+
# initiate the Tmc2209 class
17+
# use your pins for pin_en, pin_step, pin_dir here
18+
# -----------------------------------------------------------------------
19+
tmc = Tmc2209(
20+
TmcEnableControlPin(board.GP18),
21+
TmcMotionControlStepDir(board.GP17, board.GP16),
22+
TmcComUartCircuitPython(tx=board.GP4, rx=board.GP5),
23+
loglevel=Loglevel.DEBUG,
24+
)
25+
26+
27+
# -----------------------------------------------------------------------
28+
# these functions change settings in the TMC register
29+
# -----------------------------------------------------------------------
30+
tmc.set_direction_reg(False)
31+
tmc.set_current_rms(300)
32+
tmc.set_interpolation(True)
33+
tmc.set_spreadcycle(False)
34+
tmc.set_microstepping_resolution(2)
35+
tmc.set_internal_rsense(False)
36+
37+
38+
print("---\n---")
39+
40+
41+
# -----------------------------------------------------------------------
42+
# these functions read and print the current settings in the TMC register
43+
# -----------------------------------------------------------------------
44+
tmc.read_register("ioin")
45+
tmc.read_register("chopconf")
46+
tmc.read_register("drvstatus")
47+
tmc.read_register("gconf")
48+
49+
print("---\n---")
50+
51+
52+
# -----------------------------------------------------------------------
53+
# deinitiate the Tmc2209 class
54+
# -----------------------------------------------------------------------
55+
del tmc
56+
57+
print("---")
58+
print("SCRIPT FINISHED")
59+
print("---")
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
"""
2+
Demo file for basic movement
3+
"""
4+
5+
import board
6+
from tmc_driver import (
7+
Tmc2209,
8+
Loglevel,
9+
TmcEnableControlPin,
10+
TmcMotionControlStepDir,
11+
MovementAbsRel,
12+
)
13+
from tmc_driver.com import TmcComUartCircuitPython
14+
15+
16+
print("---")
17+
print("SCRIPT START")
18+
print("---")
19+
20+
# -----------------------------------------------------------------------
21+
# initiate the Tmc2240 class
22+
# use your pins for pin_en, pin_step, pin_dir here
23+
# -----------------------------------------------------------------------
24+
tmc = Tmc2209(
25+
TmcEnableControlPin(board.GP18),
26+
TmcMotionControlStepDir(board.GP17, board.GP16),
27+
TmcComUartCircuitPython(tx=board.GP4, rx=board.GP5),
28+
loglevel=Loglevel.DEBUG,
29+
)
30+
31+
32+
# -----------------------------------------------------------------------
33+
# set the loglevel of the libary (currently only printed)
34+
# set whether the movement should be relative or absolute
35+
# both optional
36+
# -----------------------------------------------------------------------
37+
tmc.tmc_logger.loglevel = Loglevel.DEBUG
38+
tmc.movement_abs_rel = MovementAbsRel.ABSOLUTE
39+
40+
41+
# -----------------------------------------------------------------------
42+
# these functions change settings in the TMC register
43+
# -----------------------------------------------------------------------
44+
tmc.set_direction_reg(False)
45+
tmc.set_current_rms(300)
46+
tmc.set_interpolation(True)
47+
tmc.set_spreadcycle(False)
48+
tmc.set_microstepping_resolution(2)
49+
tmc.set_internal_rsense(False)
50+
51+
52+
print("---\n---")
53+
54+
55+
# -----------------------------------------------------------------------
56+
# these functions read and print the current settings in the TMC register
57+
# -----------------------------------------------------------------------
58+
tmc.read_register("ioin")
59+
tmc.read_register("chopconf")
60+
tmc.read_register("drvstatus")
61+
tmc.read_register("gconf")
62+
63+
print("---\n---")
64+
65+
66+
# -----------------------------------------------------------------------
67+
# set the Acceleration and maximal Speed in fullsteps
68+
# -----------------------------------------------------------------------
69+
tmc.acceleration_fullstep = 1000
70+
tmc.max_speed_fullstep = 250
71+
72+
73+
# -----------------------------------------------------------------------
74+
# activate the motor current output
75+
# -----------------------------------------------------------------------
76+
tmc.set_motor_enabled(True)
77+
78+
79+
# -----------------------------------------------------------------------
80+
# move the motor 1 revolution
81+
# -----------------------------------------------------------------------
82+
tmc.run_to_position_fullsteps(200) # move to position 200 (fullsteps)
83+
tmc.run_to_position_fullsteps(0) # move to position 0
84+
85+
tmc.run_to_position_fullsteps(
86+
200, MovementAbsRel.RELATIVE
87+
) # move 200 fullsteps forward
88+
tmc.run_to_position_fullsteps(
89+
-200, MovementAbsRel.RELATIVE
90+
) # move 200 fullsteps backward
91+
92+
tmc.run_to_position_steps(400) # move to position 400 (µsteps)
93+
tmc.run_to_position_steps(0) # move to position 0
94+
95+
tmc.run_to_position_revolutions(1) # move 1 revolution forward
96+
tmc.run_to_position_revolutions(0) # move 1 revolution backward
97+
98+
99+
# -----------------------------------------------------------------------
100+
# deactivate the motor current output
101+
# -----------------------------------------------------------------------
102+
tmc.set_motor_enabled(False)
103+
print("---\n---")
104+
105+
106+
# -----------------------------------------------------------------------
107+
# deinitiate the Tmc2209 class
108+
# -----------------------------------------------------------------------
109+
del tmc
110+
111+
print("---")
112+
print("SCRIPT FINISHED")
113+
print("---")

micropython/lib/threading.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import _thread
1+
try:
2+
import _thread
3+
except ImportError:
4+
# Dummy _thread module for environments without threading support
5+
class _thread:
6+
@staticmethod
7+
def start_new_thread(func, args):
8+
func(*args)
29

310

411
class Thread:
@@ -11,4 +18,4 @@ def start(self):
1118
_thread.start_new_thread(self.run, ())
1219

1320
def run(self):
14-
self.target(*self.args, **self.kwargs)
21+
self.target(*self.args, **self.kwargs)

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "PyTmcStepper"
7-
version = "0.15.0"
7+
version = "0.16.0"
88
authors = [{ name = "Christian Köhlke", email = "christian@koehlke.de" }]
99
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"
1010
readme = "README.md"
1111
license = "GPL-3.0"
1212
requires-python = ">=3.10"
1313
classifiers = [
1414
"Programming Language :: Python :: 3",
15+
"Programming Language :: Python :: Implementation :: CPython",
16+
"Programming Language :: Python :: Implementation :: MicroPython",
1517
"Operating System :: POSIX :: Linux",
1618
"Development Status :: 4 - Beta",
1719
"Intended Audience :: Developers",

src/tmc_driver/com/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- TmcComSpi: Standard SPI communication (CPython with spidev)
77
- TmcComUartMicroPython: UART for MicroPython
88
- TmcComSpiMicroPython: SPI for MicroPython
9+
- TmcComUartCircuitPython: UART for CircuitPython
10+
- TmcComSpiCircuitPython: SPI for CircuitPython
911
- TmcComSpiFtdi: SPI via FTDI USB devices
1012
1113
Example:
@@ -25,12 +27,15 @@
2527
from ._tmc_com_spi import TmcComSpi
2628
from ._tmc_com_uart_micropython import TmcComUartMicroPython
2729
from ._tmc_com_spi_micropython import TmcComSpiMicroPython
30+
from ._tmc_com_uart_circuitpython import TmcComUartCircuitPython
31+
from ._tmc_com_spi_circuitpython import TmcComSpiCircuitPython
2832
from ._tmc_com_spi_ftdi import TmcComSpiFtdi
2933
except ImportError:
3034
pass
3135

3236

3337
def __getattr__(name):
38+
# pylint: disable=too-many-return-statements
3439
"""Lazy import of communication classes to avoid circular imports"""
3540
if name == "TmcComUart":
3641
from ._tmc_com_uart import TmcComUart
@@ -48,6 +53,14 @@ def __getattr__(name):
4853
from ._tmc_com_spi_micropython import TmcComSpiMicroPython
4954

5055
return TmcComSpiMicroPython
56+
if name == "TmcComUartCircuitPython":
57+
from ._tmc_com_uart_circuitpython import TmcComUartCircuitPython
58+
59+
return TmcComUartCircuitPython
60+
if name == "TmcComSpiCircuitPython":
61+
from ._tmc_com_spi_circuitpython import TmcComSpiCircuitPython
62+
63+
return TmcComSpiCircuitPython
5164
if name == "TmcComSpiFtdi":
5265
from ._tmc_com_spi_ftdi import TmcComSpiFtdi
5366

@@ -60,5 +73,7 @@ def __getattr__(name):
6073
"TmcComSpi",
6174
"TmcComUartMicroPython",
6275
"TmcComSpiMicroPython",
76+
"TmcComUartCircuitPython",
77+
"TmcComSpiCircuitPython",
6378
"TmcComSpiFtdi",
6479
]

0 commit comments

Comments
 (0)