From 1b0c98cd0e82abf79027377a76e1e0a69c1c9c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Sat, 18 May 2024 11:07:25 +0100 Subject: [PATCH 01/17] TMC_gpio class - added TMC_gpio class - moved GPIO code into TMC_gpio class - added GPIO enums - switched BOARD global var to enum --- demo/debug_script_01_uart_connection.py | 6 +- demo/demo_script_01_uart_connection.py | 6 +- demo/demo_script_02_pin_connection.py | 6 +- demo/demo_script_03_basic_movement.py | 6 +- demo/demo_script_04_stallguard.py | 4 +- demo/demo_script_05_vactual.py | 6 +- demo/demo_script_06_multiple_drivers.py | 6 +- demo/demo_script_07_threads.py | 6 +- demo/demo_script_08_log_to_file.py | 6 +- src/TMC_2209/TMC_2209_StepperDriver.py | 38 +++++----- src/TMC_2209/_TMC_2209_GPIO_board.py | 92 +++++++++++++++++++++++-- src/TMC_2209/_TMC_2209_move.py | 8 +-- src/TMC_2209/_TMC_2209_test.py | 24 +++---- 13 files changed, 156 insertions(+), 58 deletions(-) diff --git a/demo/debug_script_01_uart_connection.py b/demo/debug_script_01_uart_connection.py index 9a767d3..4a285f8 100644 --- a/demo/debug_script_01_uart_connection.py +++ b/demo/debug_script_01_uart_connection.py @@ -9,8 +9,10 @@ import time try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board print("---") @@ -25,9 +27,9 @@ # initiate the TMC_2209 class # use your pins for pin_en, pin_step, pin_dir here #----------------------------------------------------------------------- -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, skip_uart_init=True) -elif BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True) else: # just in case diff --git a/demo/demo_script_01_uart_connection.py b/demo/demo_script_01_uart_connection.py index 1d48b0a..7788fec 100644 --- a/demo/demo_script_01_uart_connection.py +++ b/demo/demo_script_01_uart_connection.py @@ -9,8 +9,10 @@ import time try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board print("---") @@ -25,9 +27,9 @@ # initiate the TMC_2209 class # use your pins for pin_en, pin_step, pin_dir here #----------------------------------------------------------------------- -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) -elif BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: # just in case diff --git a/demo/demo_script_02_pin_connection.py b/demo/demo_script_02_pin_connection.py index 238c0c1..2ef5cbb 100644 --- a/demo/demo_script_02_pin_connection.py +++ b/demo/demo_script_02_pin_connection.py @@ -9,8 +9,10 @@ import time try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board print("---") @@ -25,9 +27,9 @@ # initiate the TMC_2209 class # use your pins for pin_en, pin_step, pin_dir here #----------------------------------------------------------------------- -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) -elif BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: # just in case diff --git a/demo/demo_script_03_basic_movement.py b/demo/demo_script_03_basic_movement.py index 92fdcf7..3615b5d 100644 --- a/demo/demo_script_03_basic_movement.py +++ b/demo/demo_script_03_basic_movement.py @@ -9,8 +9,10 @@ import time try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board print("---") @@ -25,9 +27,9 @@ # initiate the TMC_2209 class # use your pins for pin_en, pin_step, pin_dir here #----------------------------------------------------------------------- -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, loglevel=Loglevel.DEBUG) -elif BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", loglevel=Loglevel.DEBUG) else: # just in case diff --git a/demo/demo_script_04_stallguard.py b/demo/demo_script_04_stallguard.py index 679a0e9..5b7e2aa 100644 --- a/demo/demo_script_04_stallguard.py +++ b/demo/demo_script_04_stallguard.py @@ -9,8 +9,10 @@ import time try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board print("---") @@ -30,7 +32,7 @@ Not implemented. Needs refinement.\nNvidia Jetson has nuances with the parameter pull_up_down for pin_stallguard: https://github.com/NVIDIA/jetson-gpio/issues/5''') -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) else: # just in case diff --git a/demo/demo_script_05_vactual.py b/demo/demo_script_05_vactual.py index dfedb41..57c01ad 100644 --- a/demo/demo_script_05_vactual.py +++ b/demo/demo_script_05_vactual.py @@ -9,8 +9,10 @@ import time try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board print("---") @@ -25,9 +27,9 @@ # initiate the TMC_2209 class # use your pin for pin_en here #----------------------------------------------------------------------- -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) -elif BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: # just in case diff --git a/demo/demo_script_06_multiple_drivers.py b/demo/demo_script_06_multiple_drivers.py index b8ac508..da0f253 100644 --- a/demo/demo_script_06_multiple_drivers.py +++ b/demo/demo_script_06_multiple_drivers.py @@ -10,8 +10,10 @@ import time try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board print("---") @@ -27,10 +29,10 @@ # use your pins for pin_en, pin_step, pin_dir here #----------------------------------------------------------------------- # Multiple driver not tested -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc1 = TMC_2209(21, 16, 20, driver_address=0) tmc2 = TMC_2209(26, 13, 19, driver_address=1) -elif BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: # tmc1 = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", driver_address=0) raise Exception("Not tested for Nvidia Jetson, use with caution") else: diff --git a/demo/demo_script_07_threads.py b/demo/demo_script_07_threads.py index 38bd599..a8d3ee8 100644 --- a/demo/demo_script_07_threads.py +++ b/demo/demo_script_07_threads.py @@ -9,8 +9,10 @@ import time try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board print("---") print("SCRIPT START") @@ -23,9 +25,9 @@ # initiate the TMC_2209 class # use your pins for pin_en, pin_step, pin_dir here #----------------------------------------------------------------------- -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc1 = TMC_2209(21, 16, 20) -elif BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: tmc1 = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: # just in case diff --git a/demo/demo_script_08_log_to_file.py b/demo/demo_script_08_log_to_file.py index 8eff813..f6b607a 100644 --- a/demo/demo_script_08_log_to_file.py +++ b/demo/demo_script_08_log_to_file.py @@ -9,8 +9,10 @@ import logging try: from src.TMC_2209.TMC_2209_StepperDriver import * + from src.TMC_2209._TMC_2209_GPIO_board import Board except ModuleNotFoundError: from TMC_2209.TMC_2209_StepperDriver import * + from TMC_2209._TMC_2209_GPIO_board import Board @@ -36,10 +38,10 @@ # initiate the TMC_2209 class # use your pins for pin_en, pin_step, pin_dir here #----------------------------------------------------------------------- -if BOARD == "RASPBERRY_PI": +if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, skip_uart_init=True, loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter) -elif BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True, loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter) else: diff --git a/src/TMC_2209/TMC_2209_StepperDriver.py b/src/TMC_2209/TMC_2209_StepperDriver.py index e452ecc..3fff45d 100644 --- a/src/TMC_2209/TMC_2209_StepperDriver.py +++ b/src/TMC_2209/TMC_2209_StepperDriver.py @@ -16,7 +16,7 @@ import time import statistics import logging -from ._TMC_2209_GPIO_board import GPIO, BOARD +from ._TMC_2209_GPIO_board import TMC_gpio, Gpio, GpioMode, GpioPUD, BOARD from ._TMC_2209_uart import TMC_UART as tmc_uart from ._TMC_2209_logger import TMC_logger, Loglevel from ._TMC_2209_move import MovementAbsRel, MovementPhase, StopMode @@ -101,7 +101,7 @@ class TMC_2209: def __init__(self, pin_en, pin_step=-1, pin_dir=-1, baudrate=115200, serialport="/dev/serial0", - driver_address=0, gpio_mode=GPIO.BCM, loglevel=None, logprefix=None, + driver_address=0, gpio_mode=None, loglevel=None, logprefix=None, log_handlers: list = None, log_formatter : logging.Formatter = None, skip_uart_init: bool = False): """constructor @@ -113,7 +113,7 @@ def __init__(self, pin_en, pin_step=-1, pin_dir=-1, baudrate=115200, serialport= baudrate (int, optional): baudrate. Defaults to 115200. serialport (str, optional): serialport path. Defaults to "/dev/serial0". driver_address (int, optional): driver address [0-3]. Defaults to 0. - gpio_mode (enum, optional): gpio mode. Defaults to GPIO.BCM. + gpio_mode (enum, optional): gpio mode. Defaults to None. loglevel (enum, optional): loglevel. Defaults to None. logprefix (str, optional): log prefix (name of the logger). Defaults to None (standard TMC prefix). @@ -131,22 +131,21 @@ def __init__(self, pin_en, pin_step=-1, pin_dir=-1, baudrate=115200, serialport= self.tmc_logger.log("Init", Loglevel.INFO) - GPIO.setwarnings(False) - GPIO.setmode(gpio_mode) + TMC_gpio.init(gpio_mode) self.tmc_logger.log(f"EN Pin: {pin_en}", Loglevel.DEBUG) self._pin_en = pin_en - GPIO.setup(self._pin_en, GPIO.OUT, initial=GPIO.HIGH) + TMC_gpio.gpio_setup(self._pin_en, GpioMode.OUT, initial=Gpio.HIGH) self.tmc_logger.log(f"STEP Pin: {pin_step}", Loglevel.DEBUG) if pin_step != -1: self._pin_step = pin_step - GPIO.setup(self._pin_step, GPIO.OUT, initial=GPIO.LOW) + TMC_gpio.gpio_setup(self._pin_step, GpioMode.OUT, initial=Gpio.LOW) self.tmc_logger.log(f"DIR Pin: {pin_dir}", Loglevel.DEBUG) if pin_dir != -1: self._pin_dir = pin_dir - GPIO.setup(self._pin_dir, GPIO.OUT, initial=self._direction) + TMC_gpio.gpio_setup(self._pin_dir, GpioMode.OUT, initial=self._direction) self.tmc_logger.log("GPIO Init finished", Loglevel.INFO) @@ -171,14 +170,14 @@ def __del__(self): self.tmc_logger.log("GPIO cleanup", Loglevel.INFO) if self._pin_step != -1: - GPIO.cleanup(self._pin_step) + TMC_gpio.gpio_cleanup(self._pin_step) if self._pin_dir != -1: - GPIO.cleanup(self._pin_dir) + TMC_gpio.gpio_cleanup(self._pin_dir) if self._pin_en != -1: - GPIO.cleanup(self._pin_en) + TMC_gpio.gpio_cleanup(self._pin_en) if self._pin_stallguard != -1: - GPIO.remove_event_detect(self._pin_stallguard) - GPIO.cleanup(self._pin_stallguard) + TMC_gpio.gpio_remove_event_detect(self._pin_stallguard) + TMC_gpio.gpio_cleanup(self._pin_stallguard) self.tmc_logger.log("Deinit finished", Loglevel.INFO) self._deinit_finished= True @@ -201,7 +200,7 @@ def set_motor_enabled(self, en): Args: en (bool): whether the motor current output should be enabled """ - GPIO.output(self._pin_en, not en) + TMC_gpio.gpio_output(self._pin_en, not en) self.tmc_logger.log(f"Motor output active: {en}", Loglevel.INFO) @@ -316,7 +315,7 @@ def do_homing2(self, revolutions, threshold=None): def reverse_direction_pin(self): """reverses the motor shaft direction""" self._direction = not self._direction - GPIO.output(self._pin_dir, self._direction) + TMC_gpio.gpio_output(self._pin_dir, self._direction) @@ -327,7 +326,7 @@ def set_direction_pin(self, direction): direction (bool): motor shaft direction: False = CCW; True = CW """ self._direction = direction - GPIO.output(self._pin_dir, direction) + TMC_gpio.gpio_output(self._pin_dir, direction) @@ -487,11 +486,10 @@ def set_stallguard_callback(self, pin_stallguard, threshold, callback, self._sg_callback = callback self._pin_stallguard = pin_stallguard - GPIO.setup(self._pin_stallguard, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) + TMC_gpio.gpio_setup(self._pin_stallguard, GpioMode.IN, pull_up_down=GpioPUD.PUD_DOWN) # first remove existing events - GPIO.remove_event_detect(self._pin_stallguard) - GPIO.add_event_detect(self._pin_stallguard, GPIO.RISING, callback=self.stallguard_callback, - bouncetime=300) + TMC_gpio.gpio_remove_event_detect(self._pin_stallguard) + TMC_gpio.gpio_add_event_detect(self._pin_stallguard, self.stallguard_callback) diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index a268c2e..ebd7116 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -11,9 +11,37 @@ """ from os.path import exists +from enum import Enum, IntEnum from ._TMC_2209_logger import TMC_logger, Loglevel -BOARD = "UNKNOWN" +class Board(Enum): + """board""" + UNKNOWN = 0 + RASPBERRY_PI = 1 # all except Pi 5 + RASPBERRY_PI5 = 2 + NVIDIA_JETSON = 3 + +class Gpio(IntEnum): + """GPIO value""" + LOW = 0 + HIGH = 1 + +class GpioMode(IntEnum): + """GPIO mode""" + OUT = 0 + IN = 1 + +class GpioPUD(IntEnum): + """Pull up Down""" + PUD_OFF = 20 + PUD_UP = 22 + PUD_DOWN = 21 + + + + + +BOARD = Board.UNKNOWN dependencies_logger = TMC_logger(Loglevel.DEBUG, "DEPENDENCIES") if not exists('/proc/device-tree/model'): @@ -21,10 +49,32 @@ else: with open('/proc/device-tree/model', encoding="utf-8") as f: model = f.readline().lower() - if "raspberry" in model: + if "raspberry pi 5" in model: + try: + from RPi import GPIO # TODO use gpiozero or a different lib for Pi5 + BOARD = Board.RASPBERRY_PI5 + except ModuleNotFoundError as err: + dependencies_logger.log( + (f"ModuleNotFoundError: {err}\n" # TODO change text + "Board is Raspberry PI 5 but module RPi.GPIO isn`t installed.\n" + "Follow the installation instructions in the link below to resolve the issue:\n" + "https://sourceforge.net/p/raspberry-gpio-python/wiki/install/\n" + "Exiting..."), + Loglevel.ERROR) + raise + except ImportError as err: + dependencies_logger.log( + (f"ImportError: {err}\n" + "Board is Raspberry PI 5 but module RPi.GPIO isn`t installed.\n" # TODO change text + "Follow the installation instructions in the link below to resolve the issue:\n" + "https://sourceforge.net/p/raspberry-gpio-python/wiki/install/\n" + "Exiting..."), + Loglevel.ERROR) + raise + elif "raspberry" in model: try: from RPi import GPIO - BOARD = "RASPBERRY_PI" + BOARD = Board.RASPBERRY_PI except ModuleNotFoundError as err: dependencies_logger.log( (f"ModuleNotFoundError: {err}\n" @@ -46,7 +96,7 @@ elif "nvidia jetson" in model: try: from Jetson import GPIO - BOARD = "NVIDIA_JETSON" + BOARD = Board.NVIDIA_JETSON except ModuleNotFoundError as err: dependencies_logger.log( (f"ModuleNotFoundError: {err}\n" @@ -70,8 +120,40 @@ dependencies_logger.log( "The board is not recognized. Trying import default RPi.GPIO module...", Loglevel.INFO) - BOARD = "UNKNOWN" + BOARD = Board.UNKNOWN try: from RPi import GPIO except ImportError: from Mock import GPIO + +class TMC_gpio: + + def init(gpio_mode=GPIO.BCM): + GPIO.setwarnings(False) + if gpio_mode == None: + gpio_mode = GPIO.BCM + GPIO.setmode(gpio_mode) + + def deinit(): + pass + + def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): + GPIO.setup(pin, int(mode), initial=int(initial), pull_up_down=int(pull_up_down)) + + def gpio_cleanup(pin): + GPIO.cleanup(pin) + + def gpio_input(pin): + return 0 + + def gpio_output(pin, value): + """function to switch a gpio output + """ + GPIO.output(pin, value) + + def gpio_remove_event_detect(pin): + GPIO.remove_event_detect(pin) + + def gpio_add_event_detect(pin, callback): + GPIO.add_event_detect(pin, GPIO.RISING, callback=callback, + bouncetime=300) diff --git a/src/TMC_2209/_TMC_2209_move.py b/src/TMC_2209/_TMC_2209_move.py index fc596b7..82e5140 100644 --- a/src/TMC_2209/_TMC_2209_move.py +++ b/src/TMC_2209/_TMC_2209_move.py @@ -12,7 +12,7 @@ from enum import Enum import math import threading -from ._TMC_2209_GPIO_board import GPIO +from ._TMC_2209_GPIO_board import TMC_gpio, Gpio from ._TMC_2209_logger import Loglevel @@ -350,7 +350,7 @@ def compute_new_speed(self): if self._n == 0: # First step from stopped self._cn = self._c0 - GPIO.output(self._pin_step, GPIO.LOW) + TMC_gpio.gpio_output(self._pin_step, Gpio.LOW) if distance_to > 0: self.set_direction_pin(1) self.tmc_logger.log("going CW", Loglevel.MOVEMENT) @@ -399,9 +399,9 @@ def make_a_step(self): for the TMC2209 there needs to be a signal duration of minimum 100 ns """ - GPIO.output(self._pin_step, GPIO.HIGH) + TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) time.sleep(1/1000/1000) - GPIO.output(self._pin_step, GPIO.LOW) + TMC_gpio.gpio_output(self._pin_step, Gpio.LOW) time.sleep(1/1000/1000) self.tmc_logger.log("one step", Loglevel.MOVEMENT) diff --git a/src/TMC_2209/_TMC_2209_test.py b/src/TMC_2209/_TMC_2209_test.py index 745a9f4..8c89105 100644 --- a/src/TMC_2209/_TMC_2209_test.py +++ b/src/TMC_2209/_TMC_2209_test.py @@ -9,7 +9,7 @@ """ import time -from ._TMC_2209_GPIO_board import GPIO +from ._TMC_2209_GPIO_board import TMC_gpio, Gpio from ._TMC_2209_logger import Loglevel from ._TMC_2209_move import MovementAbsRel, MovementPhase from . import _TMC_2209_reg as tmc_reg @@ -24,9 +24,9 @@ def test_dir_step_en(self): """ pin_dir_ok = pin_step_ok = pin_en_ok = True - GPIO.output(self._pin_step, GPIO.HIGH) - GPIO.output(self._pin_dir, GPIO.HIGH) - GPIO.output(self._pin_en, GPIO.HIGH) + 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: @@ -36,9 +36,9 @@ def test_dir_step_en(self): if not ioin & tmc_reg.io_enn: pin_en_ok = False - GPIO.output(self._pin_step, GPIO.LOW) - GPIO.output(self._pin_dir, GPIO.LOW) - GPIO.output(self._pin_en, GPIO.LOW) + 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) time.sleep(0.1) ioin = self.read_ioin() if ioin & tmc_reg.io_dir: @@ -48,9 +48,9 @@ def test_dir_step_en(self): if ioin & tmc_reg.io_enn: pin_en_ok = False - GPIO.output(self._pin_step, GPIO.HIGH) - GPIO.output(self._pin_dir, GPIO.HIGH) - GPIO.output(self._pin_en, GPIO.HIGH) + 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: @@ -85,9 +85,9 @@ def test_step(self): for _ in range(100): self._current_pos += 1 - GPIO.output(self._pin_step, GPIO.HIGH) + TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH) time.sleep(0.001) - GPIO.output(self._pin_step, GPIO.LOW) + TMC_gpio.gpio_output(self._pin_step, Gpio.LOW) time.sleep(0.01) From 6cd08e30eb97aaa6c0ab48e36faa66c6a03a180f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Sat, 18 May 2024 12:23:04 +0100 Subject: [PATCH 02/17] fix for pylint --- .github/workflows/pylint.yml | 2 +- demo/debug_script_01_uart_connection.py | 2 +- demo/demo_script_01_uart_connection.py | 2 +- demo/demo_script_02_pin_connection.py | 2 +- demo/demo_script_03_basic_movement.py | 2 +- demo/demo_script_05_vactual.py | 2 +- demo/demo_script_06_multiple_drivers.py | 3 +- demo/demo_script_07_threads.py | 2 +- demo/demo_script_08_log_to_file.py | 2 +- src/TMC_2209/TMC_2209_StepperDriver.py | 1 + src/TMC_2209/_TMC_2209_GPIO_board.py | 43 +++++++++++++++++++------ 11 files changed, 45 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index bc7ee3b..718ec94 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -24,4 +24,4 @@ jobs: pip install pyserial - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') --disable=C0103 --extension-pkg-whitelist=RPi + pylint $(git ls-files '*.py') --disable=C0103 --disable=W0511 --extension-pkg-whitelist=RPi diff --git a/demo/debug_script_01_uart_connection.py b/demo/debug_script_01_uart_connection.py index 4a285f8..d1ec128 100644 --- a/demo/debug_script_01_uart_connection.py +++ b/demo/debug_script_01_uart_connection.py @@ -29,7 +29,7 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, skip_uart_init=True) -if BOARD == Board.NVIDIA_JETSON: +elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True) else: # just in case diff --git a/demo/demo_script_01_uart_connection.py b/demo/demo_script_01_uart_connection.py index 7788fec..2643953 100644 --- a/demo/demo_script_01_uart_connection.py +++ b/demo/demo_script_01_uart_connection.py @@ -29,7 +29,7 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) -if BOARD == Board.NVIDIA_JETSON: +elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: # just in case diff --git a/demo/demo_script_02_pin_connection.py b/demo/demo_script_02_pin_connection.py index 2ef5cbb..e098123 100644 --- a/demo/demo_script_02_pin_connection.py +++ b/demo/demo_script_02_pin_connection.py @@ -29,7 +29,7 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) -if BOARD == Board.NVIDIA_JETSON: +elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: # just in case diff --git a/demo/demo_script_03_basic_movement.py b/demo/demo_script_03_basic_movement.py index 3615b5d..08517af 100644 --- a/demo/demo_script_03_basic_movement.py +++ b/demo/demo_script_03_basic_movement.py @@ -29,7 +29,7 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, loglevel=Loglevel.DEBUG) -if BOARD == Board.NVIDIA_JETSON: +elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", loglevel=Loglevel.DEBUG) else: # just in case diff --git a/demo/demo_script_05_vactual.py b/demo/demo_script_05_vactual.py index 57c01ad..f3ad93a 100644 --- a/demo/demo_script_05_vactual.py +++ b/demo/demo_script_05_vactual.py @@ -29,7 +29,7 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) -if BOARD == Board.NVIDIA_JETSON: +elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: # just in case diff --git a/demo/demo_script_06_multiple_drivers.py b/demo/demo_script_06_multiple_drivers.py index da0f253..5bd704e 100644 --- a/demo/demo_script_06_multiple_drivers.py +++ b/demo/demo_script_06_multiple_drivers.py @@ -3,6 +3,7 @@ #pylint: disable=unused-import #pylint: disable=duplicate-code #pylint: disable=broad-exception-raised +#pylint: disable=no-else-raise """ test file for testing multiple drivers via one UART connection """ @@ -32,7 +33,7 @@ if BOARD == Board.RASPBERRY_PI: tmc1 = TMC_2209(21, 16, 20, driver_address=0) tmc2 = TMC_2209(26, 13, 19, driver_address=1) -if BOARD == Board.NVIDIA_JETSON: +elif BOARD == Board.NVIDIA_JETSON: # tmc1 = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", driver_address=0) raise Exception("Not tested for Nvidia Jetson, use with caution") else: diff --git a/demo/demo_script_07_threads.py b/demo/demo_script_07_threads.py index a8d3ee8..71a8a58 100644 --- a/demo/demo_script_07_threads.py +++ b/demo/demo_script_07_threads.py @@ -27,7 +27,7 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc1 = TMC_2209(21, 16, 20) -if BOARD == Board.NVIDIA_JETSON: +elif BOARD == Board.NVIDIA_JETSON: tmc1 = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: # just in case diff --git a/demo/demo_script_08_log_to_file.py b/demo/demo_script_08_log_to_file.py index f6b607a..911aafb 100644 --- a/demo/demo_script_08_log_to_file.py +++ b/demo/demo_script_08_log_to_file.py @@ -41,7 +41,7 @@ if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, skip_uart_init=True, loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter) -if BOARD == Board.NVIDIA_JETSON: +elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True, loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter) else: diff --git a/src/TMC_2209/TMC_2209_StepperDriver.py b/src/TMC_2209/TMC_2209_StepperDriver.py index 3fff45d..d805f0e 100644 --- a/src/TMC_2209/TMC_2209_StepperDriver.py +++ b/src/TMC_2209/TMC_2209_StepperDriver.py @@ -374,6 +374,7 @@ def set_vactual_dur(self, vactual, duration=0, acceleration=0, self._stop = StopMode.NO current_vactual = 0 sleeptime = 0.05 + time_to_stop = 0 if vactual<0: acceleration = -acceleration diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index ebd7116..0a0fde1 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -1,5 +1,7 @@ #pylint: disable=unused-import #pylint: disable=ungrouped-imports +#pylint: disable=unknown-option-value +#pylint: disable=possibly-used-before-assignment """ Many boards have RaspberryPI-compatible PinOut, but require to import special GPIO module instead RPI.GPIO @@ -38,7 +40,7 @@ class GpioPUD(IntEnum): PUD_DOWN = 21 - + BOARD = Board.UNKNOWN @@ -64,8 +66,8 @@ class GpioPUD(IntEnum): raise except ImportError as err: dependencies_logger.log( - (f"ImportError: {err}\n" - "Board is Raspberry PI 5 but module RPi.GPIO isn`t installed.\n" # TODO change text + (f"ImportError: {err}\n" # TODO change text + "Board is Raspberry PI 5 but module RPi.GPIO isn`t installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://sourceforge.net/p/raspberry-gpio-python/wiki/install/\n" "Exiting..."), @@ -126,34 +128,57 @@ class GpioPUD(IntEnum): except ImportError: from Mock import GPIO -class TMC_gpio: + +class TMC_gpio: + """TMC_gpio class""" + + @staticmethod def init(gpio_mode=GPIO.BCM): + """init""" GPIO.setwarnings(False) - if gpio_mode == None: + if gpio_mode is None: gpio_mode = GPIO.BCM GPIO.setmode(gpio_mode) + @staticmethod def deinit(): - pass + """deinit""" + @staticmethod def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): - GPIO.setup(pin, int(mode), initial=int(initial), pull_up_down=int(pull_up_down)) + """setup gpio pin""" + print("TEST") + initial = int(initial) + pull_up_down = int(pull_up_down) + mode = int(mode) + + GPIO.setup(pin, mode, initial=initial, pull_up_down=pull_up_down) + @staticmethod def gpio_cleanup(pin): + """cleanup gpio pin""" + print("TEST") GPIO.cleanup(pin) + @staticmethod def gpio_input(pin): + """get input value of gpio pin""" + del pin return 0 + @staticmethod def gpio_output(pin, value): - """function to switch a gpio output - """ + """set output value of gpio pin""" GPIO.output(pin, value) + @staticmethod def gpio_remove_event_detect(pin): + """remove event dectect""" GPIO.remove_event_detect(pin) + @staticmethod def gpio_add_event_detect(pin, callback): + """add event detect""" GPIO.add_event_detect(pin, GPIO.RISING, callback=callback, bouncetime=300) From 3479247de5799c15bee3136da6fe9dab7fbc8627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Sat, 18 May 2024 13:21:06 +0100 Subject: [PATCH 03/17] first implementation of gpiozero for RPi5 --- src/TMC_2209/_TMC_2209_GPIO_board.py | 73 ++++++++++++++++++---------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index 0a0fde1..d56ac8e 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -53,23 +53,23 @@ class GpioPUD(IntEnum): model = f.readline().lower() if "raspberry pi 5" in model: try: - from RPi import GPIO # TODO use gpiozero or a different lib for Pi5 + from gpiozero import LED, Button BOARD = Board.RASPBERRY_PI5 except ModuleNotFoundError as err: dependencies_logger.log( - (f"ModuleNotFoundError: {err}\n" # TODO change text - "Board is Raspberry PI 5 but module RPi.GPIO isn`t installed.\n" + (f"ModuleNotFoundError: {err}\n" + "Board is Raspberry PI 5 but module gpiozero isn`t installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" - "https://sourceforge.net/p/raspberry-gpio-python/wiki/install/\n" + "https://gpiozero.readthedocs.io/en/stable/installing.html\n" "Exiting..."), Loglevel.ERROR) raise except ImportError as err: dependencies_logger.log( - (f"ImportError: {err}\n" # TODO change text - "Board is Raspberry PI 5 but module RPi.GPIO isn`t installed.\n" + (f"ImportError: {err}\n" + "Board is Raspberry PI 5 but module gpiozero isn`t installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" - "https://sourceforge.net/p/raspberry-gpio-python/wiki/install/\n" + "https://gpiozero.readthedocs.io/en/stable/installing.html\n" "Exiting..."), Loglevel.ERROR) raise @@ -82,7 +82,7 @@ class GpioPUD(IntEnum): (f"ModuleNotFoundError: {err}\n" "Board is Raspberry PI but module RPi.GPIO isn`t installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" - "https://sourceforge.net/p/raspberry-gpio-python/wiki/install/\n" + "https://sourceforge.net/p/raspberry-gpio-python/wiki/install\n" "Exiting..."), Loglevel.ERROR) raise @@ -91,7 +91,7 @@ class GpioPUD(IntEnum): (f"ImportError: {err}\n" "Board is Raspberry PI but module RPi.GPIO isn`t installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" - "https://sourceforge.net/p/raspberry-gpio-python/wiki/install/\n" + "https://sourceforge.net/p/raspberry-gpio-python/wiki/install\n" "Exiting..."), Loglevel.ERROR) raise @@ -133,33 +133,47 @@ class GpioPUD(IntEnum): class TMC_gpio: """TMC_gpio class""" + _gpiozero_leds = [None] * 40 + _gpiozero_buttons = [None] * 40 + @staticmethod - def init(gpio_mode=GPIO.BCM): + def init(gpio_mode=None): """init""" - GPIO.setwarnings(False) - if gpio_mode is None: - gpio_mode = GPIO.BCM - GPIO.setmode(gpio_mode) + if BOARD == Board.RASPBERRY_PI5: + pass + else: + GPIO.setwarnings(False) + if gpio_mode is None: + gpio_mode = GPIO.BCM + GPIO.setmode(gpio_mode) @staticmethod def deinit(): """deinit""" + if BOARD == Board.RASPBERRY_PI5: + pass + else: + pass @staticmethod def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): """setup gpio pin""" - print("TEST") - initial = int(initial) - pull_up_down = int(pull_up_down) - mode = int(mode) + if BOARD == Board.RASPBERRY_PI5: + TMC_gpio._gpiozero_leds[pin] = LED(pin) + else: + initial = int(initial) + pull_up_down = int(pull_up_down) + mode = int(mode) - GPIO.setup(pin, mode, initial=initial, pull_up_down=pull_up_down) + GPIO.setup(pin, mode, initial=initial, pull_up_down=pull_up_down) @staticmethod def gpio_cleanup(pin): """cleanup gpio pin""" - print("TEST") - GPIO.cleanup(pin) + if BOARD == Board.RASPBERRY_PI5: + pass + else: + GPIO.cleanup(pin) @staticmethod def gpio_input(pin): @@ -170,15 +184,24 @@ def gpio_input(pin): @staticmethod def gpio_output(pin, value): """set output value of gpio pin""" - GPIO.output(pin, value) + if BOARD == Board.RASPBERRY_PI5: + TMC_gpio._gpiozero_leds[pin].value = value + else: + GPIO.output(pin, value) @staticmethod def gpio_remove_event_detect(pin): """remove event dectect""" - GPIO.remove_event_detect(pin) + if BOARD == Board.RASPBERRY_PI5: + pass + else: + GPIO.remove_event_detect(pin) @staticmethod def gpio_add_event_detect(pin, callback): """add event detect""" - GPIO.add_event_detect(pin, GPIO.RISING, callback=callback, - bouncetime=300) + if BOARD == Board.RASPBERRY_PI5: + pass + else: + GPIO.add_event_detect(pin, GPIO.RISING, callback=callback, + bouncetime=300) From d9d594ea07cb31260e46e857f4e12f82a966ae08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Sat, 18 May 2024 13:23:36 +0100 Subject: [PATCH 04/17] added gpiozero to workflows --- .github/workflows/pylint.yml | 1 + .github/workflows/unittest.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 718ec94..96e7eb3 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -18,6 +18,7 @@ jobs: run: | python -m pip install --upgrade pip pip install pylint + pip install gpiozero pip install RPi.GPIO pip install Mock.GPIO pip install mock diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index aa0cdd2..6a058dd 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -17,6 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install gpiozero pip install RPi.GPIO pip install Mock.GPIO pip install pyserial From 9f43c083e6bfadeffe13fea8a569ddea4d1fcd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Sat, 18 May 2024 13:25:40 +0100 Subject: [PATCH 05/17] fix for pylint --- src/TMC_2209/_TMC_2209_GPIO_board.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index d56ac8e..1b9242f 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -2,6 +2,7 @@ #pylint: disable=ungrouped-imports #pylint: disable=unknown-option-value #pylint: disable=possibly-used-before-assignment +#pylint: disable=used-before-assignment """ Many boards have RaspberryPI-compatible PinOut, but require to import special GPIO module instead RPI.GPIO From 58f7c7c813e4235b11859dd4c2939129ae4faa7c Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sun, 19 May 2024 16:41:33 +0200 Subject: [PATCH 06/17] Change serial port for RPi 5 --- demo/debug_script_01_uart_connection.py | 2 ++ demo/demo_script_01_uart_connection.py | 2 ++ demo/demo_script_02_pin_connection.py | 2 ++ demo/demo_script_03_basic_movement.py | 2 ++ demo/demo_script_04_stallguard.py | 2 ++ demo/demo_script_05_vactual.py | 2 ++ demo/demo_script_06_multiple_drivers.py | 3 +++ demo/demo_script_07_threads.py | 2 ++ demo/demo_script_08_log_to_file.py | 3 +++ 9 files changed, 20 insertions(+) diff --git a/demo/debug_script_01_uart_connection.py b/demo/debug_script_01_uart_connection.py index d1ec128..dd9e185 100644 --- a/demo/debug_script_01_uart_connection.py +++ b/demo/debug_script_01_uart_connection.py @@ -29,6 +29,8 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, skip_uart_init=True) +elif BOARD == Board.RASPBERRY_PI5: + tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0", skip_uart_init=True) elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True) else: diff --git a/demo/demo_script_01_uart_connection.py b/demo/demo_script_01_uart_connection.py index 2643953..03a73b4 100644 --- a/demo/demo_script_01_uart_connection.py +++ b/demo/demo_script_01_uart_connection.py @@ -29,6 +29,8 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) +elif BOARD == Board.RASPBERRY_PI5: + tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0") elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: diff --git a/demo/demo_script_02_pin_connection.py b/demo/demo_script_02_pin_connection.py index e098123..2cfeb0a 100644 --- a/demo/demo_script_02_pin_connection.py +++ b/demo/demo_script_02_pin_connection.py @@ -29,6 +29,8 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) +elif BOARD == Board.RASPBERRY_PI5: + tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0") elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: diff --git a/demo/demo_script_03_basic_movement.py b/demo/demo_script_03_basic_movement.py index 08517af..c9a75a7 100644 --- a/demo/demo_script_03_basic_movement.py +++ b/demo/demo_script_03_basic_movement.py @@ -29,6 +29,8 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, loglevel=Loglevel.DEBUG) +elif BOARD == Board.RASPBERRY_PI5: + tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0", loglevel=Loglevel.DEBUG) elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", loglevel=Loglevel.DEBUG) else: diff --git a/demo/demo_script_04_stallguard.py b/demo/demo_script_04_stallguard.py index 5b7e2aa..9ad479f 100644 --- a/demo/demo_script_04_stallguard.py +++ b/demo/demo_script_04_stallguard.py @@ -34,6 +34,8 @@ if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) +elif BOARD == Board.RASPBERRY_PI5: + tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0") else: # just in case tmc = TMC_2209(21, 16, 20) diff --git a/demo/demo_script_05_vactual.py b/demo/demo_script_05_vactual.py index f3ad93a..19fc980 100644 --- a/demo/demo_script_05_vactual.py +++ b/demo/demo_script_05_vactual.py @@ -29,6 +29,8 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) +elif BOARD == Board.RASPBERRY_PI5: + tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0") elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: diff --git a/demo/demo_script_06_multiple_drivers.py b/demo/demo_script_06_multiple_drivers.py index 5bd704e..bf781dd 100644 --- a/demo/demo_script_06_multiple_drivers.py +++ b/demo/demo_script_06_multiple_drivers.py @@ -33,6 +33,9 @@ if BOARD == Board.RASPBERRY_PI: tmc1 = TMC_2209(21, 16, 20, driver_address=0) tmc2 = TMC_2209(26, 13, 19, driver_address=1) +elif BOARD == Board.RASPBERRY_PI5: + tmc1 = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0", driver_address=0) + tmc2 = TMC_2209(26, 13, 19, serialport="/dev/ttyAMA0", driver_address=1) elif BOARD == Board.NVIDIA_JETSON: # tmc1 = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", driver_address=0) raise Exception("Not tested for Nvidia Jetson, use with caution") diff --git a/demo/demo_script_07_threads.py b/demo/demo_script_07_threads.py index 71a8a58..1b38158 100644 --- a/demo/demo_script_07_threads.py +++ b/demo/demo_script_07_threads.py @@ -27,6 +27,8 @@ #----------------------------------------------------------------------- if BOARD == Board.RASPBERRY_PI: tmc1 = TMC_2209(21, 16, 20) +elif BOARD == Board.RASPBERRY_PI5: + tmc1 = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0") elif BOARD == Board.NVIDIA_JETSON: tmc1 = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1") else: diff --git a/demo/demo_script_08_log_to_file.py b/demo/demo_script_08_log_to_file.py index 911aafb..42cb80b 100644 --- a/demo/demo_script_08_log_to_file.py +++ b/demo/demo_script_08_log_to_file.py @@ -41,6 +41,9 @@ if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20, skip_uart_init=True, loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter) +elif BOARD == Board.RASPBERRY_PI5: + tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0", skip_uart_init=True, + loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter) elif BOARD == Board.NVIDIA_JETSON: tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True, loglevel=loglevel, log_handlers=[logging_handler], log_formatter=logformatter) From e0be16b799f149146e0742f5673b852579c08006 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sun, 19 May 2024 16:44:58 +0200 Subject: [PATCH 07/17] Use more generic DigitalOutputDevice instead of LED --- src/TMC_2209/_TMC_2209_GPIO_board.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index 1b9242f..ea17e65 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -54,7 +54,7 @@ class GpioPUD(IntEnum): model = f.readline().lower() if "raspberry pi 5" in model: try: - from gpiozero import LED, Button + from gpiozero import DigitalOutputDevice BOARD = Board.RASPBERRY_PI5 except ModuleNotFoundError as err: dependencies_logger.log( @@ -134,8 +134,7 @@ class GpioPUD(IntEnum): class TMC_gpio: """TMC_gpio class""" - _gpiozero_leds = [None] * 40 - _gpiozero_buttons = [None] * 40 + _gpiozero_dos = [None] * 40 @staticmethod def init(gpio_mode=None): @@ -160,7 +159,7 @@ def deinit(): def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): """setup gpio pin""" if BOARD == Board.RASPBERRY_PI5: - TMC_gpio._gpiozero_leds[pin] = LED(pin) + TMC_gpio._gpiozero_dos[pin] = DigitalOutputDevice(pin) else: initial = int(initial) pull_up_down = int(pull_up_down) @@ -186,7 +185,7 @@ def gpio_input(pin): def gpio_output(pin, value): """set output value of gpio pin""" if BOARD == Board.RASPBERRY_PI5: - TMC_gpio._gpiozero_leds[pin].value = value + TMC_gpio._gpiozero_dos[pin].value = value else: GPIO.output(pin, value) From 5e54ce3d39192617a678b7ac694134225ddc43a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Tue, 21 May 2024 18:16:18 +0100 Subject: [PATCH 08/17] initial support for the luckfox pico resolves #66 --- src/TMC_2209/_TMC_2209_GPIO_board.py | 50 ++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index ea17e65..2abd68b 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -23,6 +23,7 @@ class Board(Enum): RASPBERRY_PI = 1 # all except Pi 5 RASPBERRY_PI5 = 2 NVIDIA_JETSON = 3 + LUCKFOX_PICO = 4 class Gpio(IntEnum): """GPIO value""" @@ -118,6 +119,28 @@ class GpioPUD(IntEnum): "Exiting..."), Loglevel.ERROR) raise + elif "luckfox pico" in model: + try: + from periphery import GPIO + BOARD = Board.LUCKFOX_PICO + except ModuleNotFoundError as err: + dependencies_logger.log( + (f"ModuleNotFoundError: {err}\n" + "Board is Luckfox Pico but module periphery isn`t installed.\n" + "Follow the installation instructions in the link below to resolve the issue:\n" + "https://github.com/vsergeev/python-periphery\n" + "Exiting..."), + Loglevel.ERROR) + raise + except ImportError as err: + dependencies_logger.log( + (f"ImportError: {err}\n" + "Board is Luckfox Pico but module periphery isn`t installed.\n" + "Follow the installation instructions in the link below to resolve the issue:\n" + "https://github.com/vsergeev/python-periphery\n" + "Exiting..."), + Loglevel.ERROR) + raise else: # just in case dependencies_logger.log( @@ -134,13 +157,15 @@ class GpioPUD(IntEnum): class TMC_gpio: """TMC_gpio class""" - _gpiozero_dos = [None] * 40 + _gpios = [None] * 40 @staticmethod def init(gpio_mode=None): """init""" if BOARD == Board.RASPBERRY_PI5: pass + elif BOARD == Board.LUCKFOX_PICO: + pass else: GPIO.setwarnings(False) if gpio_mode is None: @@ -159,7 +184,10 @@ def deinit(): def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): """setup gpio pin""" if BOARD == Board.RASPBERRY_PI5: - TMC_gpio._gpiozero_dos[pin] = DigitalOutputDevice(pin) + TMC_gpio._gpios[pin] = DigitalOutputDevice(pin) + elif BOARD == Board.LUCKFOX_PICO: + mode = 'out' if (mode == GpioMode.OUT) else 'in' + TMC_gpio._gpios[pin] = GPIO(pin, mode) else: initial = int(initial) pull_up_down = int(pull_up_down) @@ -171,7 +199,9 @@ def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): def gpio_cleanup(pin): """cleanup gpio pin""" if BOARD == Board.RASPBERRY_PI5: - pass + TMC_gpio._gpios[pin].close() + elif BOARD == Board.LUCKFOX_PICO: + TMC_gpio._gpios[pin].close() else: GPIO.cleanup(pin) @@ -179,13 +209,15 @@ def gpio_cleanup(pin): def gpio_input(pin): """get input value of gpio pin""" del pin - return 0 + return 0 # TODO: implement @staticmethod def gpio_output(pin, value): """set output value of gpio pin""" if BOARD == Board.RASPBERRY_PI5: - TMC_gpio._gpiozero_dos[pin].value = value + TMC_gpio._gpios[pin].value = value + elif BOARD == Board.LUCKFOX_PICO: + TMC_gpio._gpios[pin].write(bool(value)) else: GPIO.output(pin, value) @@ -193,7 +225,9 @@ def gpio_output(pin, value): def gpio_remove_event_detect(pin): """remove event dectect""" if BOARD == Board.RASPBERRY_PI5: - pass + pass # TODO: implement for stallguard + elif BOARD == Board.LUCKFOX_PICO: + pass # TODO: implement for stallguard else: GPIO.remove_event_detect(pin) @@ -201,7 +235,9 @@ def gpio_remove_event_detect(pin): def gpio_add_event_detect(pin, callback): """add event detect""" if BOARD == Board.RASPBERRY_PI5: - pass + pass # TODO: implement for stallguard + elif BOARD == Board.LUCKFOX_PICO: + pass # TODO: implement for stallguard else: GPIO.add_event_detect(pin, GPIO.RISING, callback=callback, bouncetime=300) From 86dbdc501af7e74d1f25b9fbebafc0449843d475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Tue, 21 May 2024 21:41:42 +0100 Subject: [PATCH 09/17] implemented StallGuard (Interrupt Callback) for Raspberry Pi5 --- demo/demo_script_04_stallguard.py | 10 +++++----- src/TMC_2209/_TMC_2209_GPIO_board.py | 30 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/demo/demo_script_04_stallguard.py b/demo/demo_script_04_stallguard.py index 9ad479f..475c900 100644 --- a/demo/demo_script_04_stallguard.py +++ b/demo/demo_script_04_stallguard.py @@ -27,12 +27,12 @@ # initiate the TMC_2209 class # use your pins for pin_en, pin_step, pin_dir here #----------------------------------------------------------------------- -if BOARD == "NVIDIA_JETSON": +if BOARD == Board.NVIDIA_JETSON: raise NotImplementedError(''' -Not implemented. Needs refinement.\nNvidia Jetson has nuances with the parameter pull_up_down for pin_stallguard: -https://github.com/NVIDIA/jetson-gpio/issues/5''') - -if BOARD == Board.RASPBERRY_PI: + Not implemented. Needs refinement.\n + Nvidia Jetson has nuances with the parameter pull_up_down for pin_stallguard: + https://github.com/NVIDIA/jetson-gpio/issues/5''') +elif BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) elif BOARD == Board.RASPBERRY_PI5: tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0") diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index 2abd68b..08d388d 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -55,7 +55,7 @@ class GpioPUD(IntEnum): model = f.readline().lower() if "raspberry pi 5" in model: try: - from gpiozero import DigitalOutputDevice + from gpiozero import DigitalOutputDevice, DigitalInputDevice BOARD = Board.RASPBERRY_PI5 except ModuleNotFoundError as err: dependencies_logger.log( @@ -183,8 +183,12 @@ def deinit(): @staticmethod def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): """setup gpio pin""" + #print(f"{BOARD}, {pin}, {mode}") if BOARD == Board.RASPBERRY_PI5: - TMC_gpio._gpios[pin] = DigitalOutputDevice(pin) + if mode == GpioMode.OUT: + TMC_gpio._gpios[pin] = DigitalOutputDevice(pin) + else: + TMC_gpio._gpios[pin] = DigitalInputDevice(pin) elif BOARD == Board.LUCKFOX_PICO: mode = 'out' if (mode == GpioMode.OUT) else 'in' TMC_gpio._gpios[pin] = GPIO(pin, mode) @@ -192,7 +196,6 @@ def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): initial = int(initial) pull_up_down = int(pull_up_down) mode = int(mode) - GPIO.setup(pin, mode, initial=initial, pull_up_down=pull_up_down) @staticmethod @@ -222,22 +225,23 @@ def gpio_output(pin, value): GPIO.output(pin, value) @staticmethod - def gpio_remove_event_detect(pin): - """remove event dectect""" + def gpio_add_event_detect(pin, callback): + """add event detect""" if BOARD == Board.RASPBERRY_PI5: - pass # TODO: implement for stallguard + TMC_gpio._gpios[pin].when_activated = callback elif BOARD == Board.LUCKFOX_PICO: pass # TODO: implement for stallguard else: - GPIO.remove_event_detect(pin) - + GPIO.add_event_detect(pin, GPIO.RISING, callback=callback, + bouncetime=300) + @staticmethod - def gpio_add_event_detect(pin, callback): - """add event detect""" + def gpio_remove_event_detect(pin): + """remove event dectect""" if BOARD == Board.RASPBERRY_PI5: - pass # TODO: implement for stallguard + if TMC_gpio._gpios[pin].when_activated is not None: + TMC_gpio._gpios[pin].when_activated = None elif BOARD == Board.LUCKFOX_PICO: pass # TODO: implement for stallguard else: - GPIO.add_event_detect(pin, GPIO.RISING, callback=callback, - bouncetime=300) + GPIO.remove_event_detect(pin) From a9d480ac67fd2097f848690892af4dad0461f065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Tue, 21 May 2024 21:45:16 +0100 Subject: [PATCH 10/17] small fix for when using StallGuard with RPi.GPIO --- src/TMC_2209/_TMC_2209_GPIO_board.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index 08d388d..e092f85 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -196,7 +196,10 @@ def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): initial = int(initial) pull_up_down = int(pull_up_down) mode = int(mode) - GPIO.setup(pin, mode, initial=initial, pull_up_down=pull_up_down) + if mode == GpioMode.OUT: + GPIO.setup(pin, mode, initial=initial) + else: + GPIO.setup(pin, mode, pull_up_down=pull_up_down) @staticmethod def gpio_cleanup(pin): From de845f58333c029497e48d6af901b0be23f45243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Tue, 21 May 2024 21:47:52 +0100 Subject: [PATCH 11/17] small fix for when using StallGuard with RPi.GPIO --- demo/demo_script_04_stallguard.py | 2 +- src/TMC_2209/_TMC_2209_GPIO_board.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/demo_script_04_stallguard.py b/demo/demo_script_04_stallguard.py index 475c900..71b1ef3 100644 --- a/demo/demo_script_04_stallguard.py +++ b/demo/demo_script_04_stallguard.py @@ -32,7 +32,7 @@ Not implemented. Needs refinement.\n Nvidia Jetson has nuances with the parameter pull_up_down for pin_stallguard: https://github.com/NVIDIA/jetson-gpio/issues/5''') -elif BOARD == Board.RASPBERRY_PI: +if BOARD == Board.RASPBERRY_PI: tmc = TMC_2209(21, 16, 20) elif BOARD == Board.RASPBERRY_PI5: tmc = TMC_2209(21, 16, 20, serialport="/dev/ttyAMA0") diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index e092f85..5bd2870 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -237,7 +237,7 @@ def gpio_add_event_detect(pin, callback): else: GPIO.add_event_detect(pin, GPIO.RISING, callback=callback, bouncetime=300) - + @staticmethod def gpio_remove_event_detect(pin): """remove event dectect""" From 015ac1f3d7f817a27917eff2f3c181763dbce9b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Tue, 21 May 2024 21:54:38 +0100 Subject: [PATCH 12/17] added new board request issue template --- .github/ISSUE_TEMPLATE/new_board_request.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/new_board_request.md diff --git a/.github/ISSUE_TEMPLATE/new_board_request.md b/.github/ISSUE_TEMPLATE/new_board_request.md new file mode 100644 index 0000000..7d080fd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/new_board_request.md @@ -0,0 +1,18 @@ +--- +name: New Board Request +about: Create a Request if you want a new board supported +title: '' +labels: '' +assignees: '' + +--- + +**Info about your board** + +- the name and a link to you board +- a library that can be used to control the gpios of your board +- a info to the serial port of your board + +**Board Identification** +A method to recognize the new board programmatically. ideally with the output of +`cat /proc/device-tree/model` From 2cac84d399ddd9fea8f912b1a4c63def6da44569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Wed, 22 May 2024 18:22:06 +0100 Subject: [PATCH 13/17] doc --- src/TMC_2209/_TMC_2209_GPIO_board.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index 5bd2870..139c73c 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -17,6 +17,15 @@ from enum import Enum, IntEnum from ._TMC_2209_logger import TMC_logger, Loglevel +# ------------------------------ +# LIB | BOARD +# ------------------------------ +# RPi.GPIO | Pi4, Pi3 etc. +# Jetson.GPIO | Nvidia Jetson +# gpiozero | Pi5 +# pheriphery | Luckfox Pico +# ------------------------------ + class Board(Enum): """board""" UNKNOWN = 0 @@ -161,7 +170,7 @@ class TMC_gpio: @staticmethod def init(gpio_mode=None): - """init""" + """init gpio library""" if BOARD == Board.RASPBERRY_PI5: pass elif BOARD == Board.LUCKFOX_PICO: @@ -174,7 +183,7 @@ def init(gpio_mode=None): @staticmethod def deinit(): - """deinit""" + """deinit gpio library""" if BOARD == Board.RASPBERRY_PI5: pass else: @@ -196,7 +205,7 @@ def gpio_setup(pin, mode, initial = Gpio.LOW, pull_up_down = GpioPUD.PUD_OFF): initial = int(initial) pull_up_down = int(pull_up_down) mode = int(mode) - if mode == GpioMode.OUT: + if mode == GpioMode.OUT: # TODO: better way to pass different params GPIO.setup(pin, mode, initial=initial) else: GPIO.setup(pin, mode, pull_up_down=pull_up_down) From bf59d50d340855b213b20e4c2ad2dbbd19641544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Thu, 23 May 2024 18:18:40 +0100 Subject: [PATCH 14/17] change amount of GPIO pins to 200 luckfox pico pin numbering is weird and spans from 4 until 145 --- src/TMC_2209/_TMC_2209_GPIO_board.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index 139c73c..f8d081e 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -166,7 +166,7 @@ class GpioPUD(IntEnum): class TMC_gpio: """TMC_gpio class""" - _gpios = [None] * 40 + _gpios = [None] * 200 @staticmethod def init(gpio_mode=None): From aa5bdc127c956ff97fdfba51de8132e8260fe895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Thu, 23 May 2024 18:37:53 +0100 Subject: [PATCH 15/17] removed RPi.GPIO as required dependency - added RPi.GPIO as optional dependency - added gpiozero as optional dependency - added Jetson.GPIO as optional dependency - added python-periphery as optional dependency --- setup.cfg | 13 +++++++++++-- src/TMC_2209/_TMC_2209_GPIO_board.py | 16 ++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/setup.cfg b/setup.cfg index d8eab63..ab15713 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,8 +24,17 @@ package_dir = packages = find: python_requires = >=3.7 install_requires = - RPi.GPIO pyserial [options.packages.find] -where = src \ No newline at end of file +where = src + +[options.extras_require] +RASPBERRY_PI = + RPi.GPIO +RASPBERRY_PI5 = + gpiozero +NVIDIA_JETSON = + Jetson.GPIO +LUCKFOX_PICO = + python-periphery \ No newline at end of file diff --git a/src/TMC_2209/_TMC_2209_GPIO_board.py b/src/TMC_2209/_TMC_2209_GPIO_board.py index f8d081e..1e6a20e 100644 --- a/src/TMC_2209/_TMC_2209_GPIO_board.py +++ b/src/TMC_2209/_TMC_2209_GPIO_board.py @@ -69,7 +69,7 @@ class GpioPUD(IntEnum): except ModuleNotFoundError as err: dependencies_logger.log( (f"ModuleNotFoundError: {err}\n" - "Board is Raspberry PI 5 but module gpiozero isn`t installed.\n" + "Board is Raspberry PI 5 but module gpiozero isn't installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://gpiozero.readthedocs.io/en/stable/installing.html\n" "Exiting..."), @@ -78,7 +78,7 @@ class GpioPUD(IntEnum): except ImportError as err: dependencies_logger.log( (f"ImportError: {err}\n" - "Board is Raspberry PI 5 but module gpiozero isn`t installed.\n" + "Board is Raspberry PI 5 but module gpiozero isn't installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://gpiozero.readthedocs.io/en/stable/installing.html\n" "Exiting..."), @@ -91,7 +91,7 @@ class GpioPUD(IntEnum): except ModuleNotFoundError as err: dependencies_logger.log( (f"ModuleNotFoundError: {err}\n" - "Board is Raspberry PI but module RPi.GPIO isn`t installed.\n" + "Board is Raspberry PI but module RPi.GPIO isn't installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://sourceforge.net/p/raspberry-gpio-python/wiki/install\n" "Exiting..."), @@ -100,7 +100,7 @@ class GpioPUD(IntEnum): except ImportError as err: dependencies_logger.log( (f"ImportError: {err}\n" - "Board is Raspberry PI but module RPi.GPIO isn`t installed.\n" + "Board is Raspberry PI but module RPi.GPIO isn't installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://sourceforge.net/p/raspberry-gpio-python/wiki/install\n" "Exiting..."), @@ -113,7 +113,7 @@ class GpioPUD(IntEnum): except ModuleNotFoundError as err: dependencies_logger.log( (f"ModuleNotFoundError: {err}\n" - "Board is Nvidia Jetson but module jetson-gpio isn`t installed.\n" + "Board is Nvidia Jetson but module jetson-gpio isn't installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://github.com/NVIDIA/jetson-gpio\n" "Exiting..."), @@ -122,7 +122,7 @@ class GpioPUD(IntEnum): except ImportError as err: dependencies_logger.log( (f"ImportError: {err}\n" - "Board is Nvidia Jetson but module jetson-gpio isn`t installed.\n" + "Board is Nvidia Jetson but module jetson-gpio isn't installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://github.com/NVIDIA/jetson-gpio\n" "Exiting..."), @@ -135,7 +135,7 @@ class GpioPUD(IntEnum): except ModuleNotFoundError as err: dependencies_logger.log( (f"ModuleNotFoundError: {err}\n" - "Board is Luckfox Pico but module periphery isn`t installed.\n" + "Board is Luckfox Pico but module periphery isn't installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://github.com/vsergeev/python-periphery\n" "Exiting..."), @@ -144,7 +144,7 @@ class GpioPUD(IntEnum): except ImportError as err: dependencies_logger.log( (f"ImportError: {err}\n" - "Board is Luckfox Pico but module periphery isn`t installed.\n" + "Board is Luckfox Pico but module periphery isn't installed.\n" "Follow the installation instructions in the link below to resolve the issue:\n" "https://github.com/vsergeev/python-periphery\n" "Exiting..."), From f56ccffb8db794aac906fdc496e2db3797fbc9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Thu, 23 May 2024 19:00:02 +0100 Subject: [PATCH 16/17] added Board Support information to README --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index c4ab2f4..baf2f72 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,24 @@ pip3 install TMC-2209-Raspberry-Pi sudo raspi-config ``` +### Board Support + +The following table shows the supported boards and which libraries for GPIO access is beeing used for that board. + +Library | Installation Parameter | Boards +-- | -- | -- +RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc. +gpiozero | RASPBERRY_PI5 | Pi5 +Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson +pheriphery | LUCKFOX_PICO | Luckfox Pico + +Those libraries are needed for this library to work. You can either install the correct library yourself. +You can also install the needed GPIO library by specifing the Installation Parameter while installing this library: + +```shell +pip3 install TMC-2209-Raspberry-Pi[RASPBERRY_PI] +``` + ## Wiring Pin TMC2209 | connect to | Function From f1a9bf6a506791eaa1db0227db7f04d8f67a9a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6hlke?= Date: Sun, 26 May 2024 11:21:57 +0100 Subject: [PATCH 17/17] changed version to 0.5 --- CHANGELOG.md | 6 ++++++ setup.cfg | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 297c7c6..85940e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## version 0.5 + +- decoupled gpio access from gpio library +- added support for Raspberry Pi5 (gpiozero) +- added support for Luckfox Pico (python-periphery) + ## version 0.4.5 - enhancement of logging module diff --git a/setup.cfg b/setup.cfg index ab15713..833213a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = TMC_2209_Raspberry_Pi -version = 0.4.5 +version = 0.5 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