From e6bab4ad0d6f7cef73b1067ed61b91f19b0e6f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Sat, 26 Oct 2024 13:04:28 +0100 Subject: [PATCH 1/5] changed the test_dir_step_en function to test each pin individually --- src/TMC_2209/_TMC_2209_test.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/TMC_2209/_TMC_2209_test.py b/src/TMC_2209/_TMC_2209_test.py index 8c89105..59262bb 100644 --- a/src/TMC_2209/_TMC_2209_test.py +++ b/src/TMC_2209/_TMC_2209_test.py @@ -24,8 +24,8 @@ def test_dir_step_en(self): """ pin_dir_ok = pin_step_ok = pin_en_ok = True - TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH) + TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH) time.sleep(0.1) ioin = self.read_ioin() @@ -36,30 +36,42 @@ def test_dir_step_en(self): if not ioin & tmc_reg.io_enn: pin_en_ok = False + TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH) TMC_gpio.gpio_output(self._pin_step, Gpio.LOW) - TMC_gpio.gpio_output(self._pin_dir, Gpio.LOW) - TMC_gpio.gpio_output(self._pin_en, Gpio.LOW) + TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH) time.sleep(0.1) ioin = self.read_ioin() - if ioin & tmc_reg.io_dir: + if not ioin & tmc_reg.io_dir: pin_dir_ok = False if ioin & tmc_reg.io_step: pin_step_ok = False - if ioin & tmc_reg.io_enn: + if not ioin & tmc_reg.io_enn: pin_en_ok = False + TMC_gpio.gpio_output(self._pin_dir, Gpio.LOW) TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) - TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH) TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH) time.sleep(0.1) ioin = self.read_ioin() - if not ioin & tmc_reg.io_dir: + if ioin & tmc_reg.io_dir: pin_dir_ok = False if not ioin & tmc_reg.io_step: pin_step_ok = False if not ioin & tmc_reg.io_enn: pin_en_ok = False + TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH) + TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) + TMC_gpio.gpio_output(self._pin_en, Gpio.LOW) + time.sleep(0.1) + ioin = self.read_ioin() + if not ioin & tmc_reg.io_dir: + pin_dir_ok = False + if not ioin & tmc_reg.io_step: + pin_step_ok = False + if ioin & tmc_reg.io_enn: + pin_en_ok = False + self.set_motor_enabled(False) self.tmc_logger.log("---") From 51f94f1d70a05d733688b8996ff79c41ee4676d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Sat, 26 Oct 2024 16:03:24 +0100 Subject: [PATCH 2/5] refactored test_dir_step_en function --- src/TMC_2209/TMC_2209_StepperDriver.py | 2 +- src/TMC_2209/_TMC_2209_test.py | 69 ++++++++++---------------- 2 files changed, 26 insertions(+), 45 deletions(-) diff --git a/src/TMC_2209/TMC_2209_StepperDriver.py b/src/TMC_2209/TMC_2209_StepperDriver.py index 3f29248..0d0798e 100644 --- a/src/TMC_2209/TMC_2209_StepperDriver.py +++ b/src/TMC_2209/TMC_2209_StepperDriver.py @@ -55,7 +55,7 @@ class TMC_2209: ) from ._TMC_2209_test import ( - test_dir_step_en, test_step, test_uart, test_stallguard_threshold + test_pin, test_dir_step_en, test_step, test_uart, test_stallguard_threshold ) BOARD = BOARD diff --git a/src/TMC_2209/_TMC_2209_test.py b/src/TMC_2209/_TMC_2209_test.py index 59262bb..ef1e159 100644 --- a/src/TMC_2209/_TMC_2209_test.py +++ b/src/TMC_2209/_TMC_2209_test.py @@ -16,61 +16,42 @@ -def test_dir_step_en(self): - """tests the EN, DIR and STEP pin +def test_pin(self, pin, ioin_reg): + """tests one pin - this sets the EN, DIR and STEP pin to HIGH, LOW and HIGH - and checks the IOIN Register of the TMC meanwhile + this function checks the connection to a pin + by toggling it and reading the IOIN register """ - pin_dir_ok = pin_step_ok = pin_en_ok = True + pin_ok = True TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH) TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH) - time.sleep(0.1) - ioin = self.read_ioin() - if not ioin & tmc_reg.io_dir: - pin_dir_ok = False - if not ioin & tmc_reg.io_step: - pin_step_ok = False - if not ioin & tmc_reg.io_enn: - pin_en_ok = False - TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH) - TMC_gpio.gpio_output(self._pin_step, Gpio.LOW) - TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH) - time.sleep(0.1) - ioin = self.read_ioin() - if not ioin & tmc_reg.io_dir: - pin_dir_ok = False - if ioin & tmc_reg.io_step: - pin_step_ok = False - if not ioin & tmc_reg.io_enn: - pin_en_ok = False - - TMC_gpio.gpio_output(self._pin_dir, Gpio.LOW) - TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) - TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH) - time.sleep(0.1) ioin = self.read_ioin() - if ioin & tmc_reg.io_dir: - pin_dir_ok = False - if not ioin & tmc_reg.io_step: - pin_step_ok = False - if not ioin & tmc_reg.io_enn: - pin_en_ok = False + if not ioin & ioin_reg: + pin_ok = False - TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH) - TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) - TMC_gpio.gpio_output(self._pin_en, Gpio.LOW) + TMC_gpio.gpio_output(pin, Gpio.LOW) time.sleep(0.1) + ioin = self.read_ioin() - if not ioin & tmc_reg.io_dir: - pin_dir_ok = False - if not ioin & tmc_reg.io_step: - pin_step_ok = False - if ioin & tmc_reg.io_enn: - pin_en_ok = False + if ioin & ioin_reg: + pin_ok = False + + return pin_ok + + + +def test_dir_step_en(self): + """tests the EN, DIR and STEP pin + + this sets the EN, DIR and STEP pin to HIGH, LOW and HIGH + and checks the IOIN Register of the TMC meanwhile + """ + pin_dir_ok = self.test_pin(self._pin_dir, tmc_reg.io_dir) + pin_step_ok = self.test_pin(self._pin_step, tmc_reg.io_step) + pin_en_ok = self.test_pin(self._pin_en, tmc_reg.io_enn) self.set_motor_enabled(False) From 2e08504d5a0784d3e74548aff748a27445be7219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Tue, 29 Oct 2024 19:05:23 +0100 Subject: [PATCH 3/5] switch from python 3.12 to 3.13 in github actions --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2bec327..1b2d85e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.7", "3.9", "3.12"] + python-version: ["3.7", "3.9", "3.13"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -42,7 +42,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.7", "3.9", "3.12"] + python-version: ["3.7", "3.9", "3.13"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} From 5e57e2c0fb265511c30c4863f9cef3877ce88553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Wed, 18 Dec 2024 22:07:08 +0100 Subject: [PATCH 4/5] fix: return status instead of hardcoded True in test_uart - fixes #85 --- src/TMC_2209/_TMC_2209_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TMC_2209/_TMC_2209_test.py b/src/TMC_2209/_TMC_2209_test.py index ef1e159..400cd8e 100644 --- a/src/TMC_2209/_TMC_2209_test.py +++ b/src/TMC_2209/_TMC_2209_test.py @@ -139,7 +139,7 @@ def test_uart(self): self.tmc_logger.log("UART connection: not OK", Loglevel.ERROR) self.tmc_logger.log("---") - return True + return status From badb658c02ef12151ced9d97dd6a93775ed191f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Thu, 19 Dec 2024 19:06:31 +0100 Subject: [PATCH 5/5] changed version to 0.5.6 - fixed typo --- CHANGELOG.md | 7 +++++++ README.md | 2 +- setup.cfg | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a915a2c..8e59cf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## version 0.5.6 + +- fixed return status instead of hardcoded True in test_uart +- refactored test_dir_step_en function +- fixed links in readme +- switched to python 3.13 in unittests + ## version 0.5.5 - changed Nvidia Jetson detection diff --git a/README.md b/README.md index 456469e..d19ae1d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ So if you move the motor with high speed using this library the motor will lose 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). It has a rSense of 110 mOhm and it uses one Pin (PDN_UART) for UART RX and TX. -So the PD_UART-Pin needs to be connected to the Raspberrry Pis RX-Pin directly and to the TX-Pin with an 1kOhm resistor. +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. You can read more about this in the datasheet from Trinamic. Because the TMC2209 uses one shared pin for transmit and receive in the UART communication line, the Raspberry Pi also receives what it sends. diff --git a/setup.cfg b/setup.cfg index 5858874..28db196 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = TMC_2209_Raspberry_Pi -version = 0.5.5 +version = 0.5.6 author = Christian Köhlke author_email = christian@koehlke.de description = this is a Python libary to drive a stepper motor with a Trinamic TMC2209 stepper driver and a Raspberry Pi