Skip to content

Commit

Permalink
Merge pull request #41 from Chr157i4n/dev
Browse files Browse the repository at this point in the history
version 0.4
  • Loading branch information
Chr157i4n authored Nov 16, 2023
2 parents 6c49e3b + 660877a commit 2f28f12
Show file tree
Hide file tree
Showing 25 changed files with 1,887 additions and 1,560 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pylint
pip install RPi.GPIO
pip install Mock.GPIO
pip install mock
pip install bitstring
pip install pyserial
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=C0103
pylint $(git ls-files '*.py') --disable=C0103 --extension-pkg-whitelist=RPi
27 changes: 27 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Unittest

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install RPi.GPIO
pip install Mock.GPIO
pip install mock
pip install bitstring
pip install pyserial
- name: Run unittests
run: |
python -m unittest
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## version 0.4
- split code into different files
- added logger class
- moved demo scripts into demo folder
- added unittest
- switched all string to f-strings

## version 0.3.4
- fixed do_homing()
- added minspeed to do_homing()
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ pip3 install TMC-2209-Raspberry-Pi
```
git clone https://github.com/Chr157i4n/TMC2209_Raspberry_Pi
```
- install the python module bitstring with
- install the required modules
```
pip3 install bitstring
pip3 install RPi.GPIO enum34 bitstring pyserial
```
- enable the serial port in
```
Expand All @@ -68,17 +68,17 @@ 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.


## Tests
You can run the test files from the main directory with
## Demo scripts
You can run the demo scripts files from the main directory with
```
python3 -m tests.test_script_01_uart_connection
python3 -m demo.demo_script_01_uart_connection
```

#### [test_script_01_uart_connection.py](tests/test_script_01_uart_connection.py)
#### [demo_script_01_uart_connection.py](demo/demo_script_01_uart_connection.py)
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.

#### [test_script_02_pin_connection.py](tests/test_script_02_pin_connection.py)
#### [demo_script_02_pin_connection.py](demo/demo_script_02_pin_connection.py)
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.
Expand All @@ -88,23 +88,23 @@ Pin STEP: OK
Pin EN: OK
if not, check the connection of the pin.

#### [test_script_03_basic_movement.py](tests/test_script_03_basic_movement.py)
#### [demo_script_03_basic_movement.py](demo/demo_script_03_basic_movement.py)
This script should move the motor 6 times, one revolution back and forth.

#### [test_script_04_stallguard.py](tests/test_script_04_stallguard.py)
#### [demo_script_04_stallguard.py](demo/demo_script_04_stallguard.py)
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```

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

#### [test_script_06_multiple_drivers.py](tests/test_script_06_multiple_drivers.py)
#### [demo_script_06_multiple_drivers.py](demo/demo_script_06_multiple_drivers.py)
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.

#### [test_script_07_threads.py](tests/test_script_07_threads.py)
#### [demo_script_07_threads.py](demo/demo_script_07_threads.py)
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.

\
Expand Down
1 change: 1 addition & 0 deletions demo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pylint: disable=invalid-name
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
tmc = TMC_2209(21, 16, 20, no_uart=True)
tmc = TMC_2209(21, 16, 20, skip_uart_init=True)



Expand All @@ -33,7 +33,7 @@
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.set_loglevel(Loglevel.DEBUG)
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.set_loglevel(Loglevel.DEBUG)
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)


Expand All @@ -60,10 +60,10 @@
#-----------------------------------------------------------------------
# these functions read and print the current settings in the TMC register
#-----------------------------------------------------------------------
tmc.readIOIN()
tmc.readCHOPCONF()
tmc.readDRVSTATUS()
tmc.readGCONF()
tmc.read_ioin()
tmc.read_chopconf()
tmc.read_drv_status()
tmc.read_gconf()

print("---\n---")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.set_loglevel(Loglevel.DEBUG)
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.set_loglevel(Loglevel.DEBUG)
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)


Expand All @@ -60,10 +60,10 @@
#-----------------------------------------------------------------------
# these functions read and print the current settings in the TMC register
#-----------------------------------------------------------------------
tmc.readIOIN()
tmc.readCHOPCONF()
tmc.readDRVSTATUS()
tmc.readGCONF()
tmc.read_ioin()
tmc.read_chopconf()
tmc.read_drv_status()
tmc.read_gconf()

print("---\n---")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.set_loglevel(Loglevel.DEBUG)
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)


Expand All @@ -60,10 +60,10 @@
#-----------------------------------------------------------------------
# these functions read and print the current settings in the TMC register
#-----------------------------------------------------------------------
tmc.readIOIN()
tmc.readCHOPCONF()
tmc.readDRVSTATUS()
tmc.readGCONF()
tmc.read_ioin()
tmc.read_chopconf()
tmc.read_drv_status()
tmc.read_gconf()

print("---\n---")

Expand Down Expand Up @@ -107,9 +107,8 @@
# 3. param: is the callback function (threaded)
# 4. param (optional): min speed threshold (in steptime measured in clock cycles)
#-----------------------------------------------------------------------
def my_callback(channel):
def my_callback():
"""StallGuard callback"""
del channel
print("StallGuard!")
tmc.stop()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.set_loglevel(Loglevel.DEBUG)
tmc.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)


Expand All @@ -60,10 +60,10 @@
#-----------------------------------------------------------------------
# these functions read and print the current settings in the TMC register
#-----------------------------------------------------------------------
tmc.readIOIN()
tmc.readCHOPCONF()
tmc.readDRVSTATUS()
tmc.readGCONF()
tmc.read_ioin()
tmc.read_chopconf()
tmc.read_drv_status()
tmc.read_gconf()

print("---\n---")

Expand All @@ -84,13 +84,13 @@
# move the motor for 1 second forward, stop for 1 second
# and then move backwards for 1 second
#-----------------------------------------------------------------------
#tmc.set_vactual(400)
#tmc.set_vactual_dur(400)
#time.sleep(1)
#tmc.set_vactual(0)
#tmc.set_vactual_dur(0)
#time.sleep(1)
#tmc.set_vactual(-400)
#tmc.set_vactual_dur(-400)
#time.sleep(1)
#tmc.set_vactual(0)
#tmc.set_vactual_dur(0)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc1.set_loglevel(Loglevel.DEBUG)
tmc1.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc1.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)

tmc2.set_loglevel(Loglevel.DEBUG)
tmc2.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc2.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)


Expand All @@ -49,15 +49,15 @@
print("---")
print("IOIN tmc1")
print("---")
tmc1.readIOIN()
tmc1.read_ioin()

print("---\n---")


print("---")
print("IOIN tmc2")
print("---")
tmc2.readIOIN()
tmc2.read_ioin()

print("---\n---")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc1.set_loglevel(Loglevel.DEBUG)
tmc1.tmc_logger.set_loglevel(Loglevel.DEBUG)
tmc1.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)


Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = TMC_2209_Raspberry_Pi
version = 0.3.4
version = 0.4
author = Christian Köhlke
author_email = [email protected]
description = this is a Python libary to drive a stepper motor with a Trinamic TMC2209 stepper driver and a Raspberry Pi
Expand All @@ -26,7 +26,6 @@ python_requires = >=3.0.0
install_requires =
RPi.GPIO
enum34
gpiozero
bitstring
pyserial

Expand Down
Loading

0 comments on commit 2f28f12

Please sign in to comment.