Skip to content

Commit

Permalink
Merge pull request #48 from Chr157i4n/dev
Browse files Browse the repository at this point in the history
version 0.4.2
  • Loading branch information
Chr157i4n authored Jan 15, 2024
2 parents 12e549a + 6c6e47a commit 94bea92
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 50 deletions.
34 changes: 34 additions & 0 deletions .github/ISSUE_TEMPLATE/uart_problem_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: UART connection problem report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.
Please check out the [Troubleshoot section](https://github.com/Chr157i4n/TMC2209_Raspberry_Pi#troubleshoot) first.

```
Include the output of the [demo/debug_script_01_uart_connection.py](https://github.com/Chr157i4n/TMC2209_Raspberry_Pi/blob/main/demo/debug_script_01_uart_connection.py) script in your issure report here using [Markdown Code-Blocks](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks).
```

**To Reproduce**
Steps to reproduce the behavior:
1. installed the library with pip
2. ran the function '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Versions**
- Raspberry Pi Version
- OS Version
- Version of this library
- TMC2209 version and manufacturer

**Additional context**
Add any other context about the problem here.
6 changes: 3 additions & 3 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Pylint

on: [push]
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.7", "3.9", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Unittest

on: [push]
on: [push, pull_request]

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

## version 0.4.2

- added support for Nvidia Jetson
- added seperate file for GPIO board imports
- changed min python version to 3.7

## version 0.4.1

- removed dependency enum34
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![PyPI python version TMC-2209-Raspberry-Pi](https://badgen.net/pypi/python/TMC-2209-Raspberry-Pi)](https://pypi.org/project/TMC-2209-Raspberry-Pi)
[![PyPI version TMC-2209-Raspberry-Pi](https://badgen.net/pypi/v/TMC-2209-Raspberry-Pi)](https://pypi.org/project/TMC-2209-Raspberry-Pi)
[![PyPI downloads TMC-2209-Raspberry-Pi](https://img.shields.io/pypi/dm/TMC-2209-Raspberry-Pi)](https://pypi.org/project/TMC-2209-Raspberry-Pi)
[![GitHub issues](https://img.shields.io/github/issues/Chr157i4n/TMC2209_Raspberry_Pi.svg)](https://GitHub.com/Chr157i4n/TMC2209_Raspberry_Pi/issues/)

\
\
Expand Down Expand Up @@ -61,10 +62,10 @@ Pin TMC2209 | connect to | Function
-- | -- | --
TX or PDN_UART with 1kOhm | TX of Raspberry Pi | send data to TMC via UART
RX or PDN_UART directly | RX of Raspberry Pi | receive data from TMC via UART
VDD | 3,3V of Raspberry Pi | optional, for more stable logic voltage
GND | GND of Raspberry Pi | GND for VDD and Signals
VM | 12V or 24V of power supply | power for the motor
GND | GND of power supply | power for the motor
VDD | 3,3V of Raspberry Pi | optional, for more stable logic voltage
GND2 | GND of Raspberry Pi | GND for VDD and Signals
EN | GPIO21 of Raspberry Pi | enable the motor output
STEP | GPIO16 of Raspberry Pi | moves the motor one step per pulse
DIR | GPIO20 of Raspberry Pi | set the direction of the motor
Expand Down
9 changes: 7 additions & 2 deletions demo/debug_script_01_uart_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
tmc = TMC_2209(21, 16, 20, skip_uart_init=True)

if BOARD == "RASPBERRY_PI":
tmc = TMC_2209(21, 16, 20, skip_uart_init=True)
elif BOARD == "NVIDIA_JETSON":
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", skip_uart_init=True)
else:
# just in case
tmc = TMC_2209(21, 16, 20, skip_uart_init=True)



Expand Down
11 changes: 7 additions & 4 deletions demo/demo_script_01_uart_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
tmc = TMC_2209(21, 16, 20)



if BOARD == "RASPBERRY_PI":
tmc = TMC_2209(21, 16, 20)
elif BOARD == "NVIDIA_JETSON":
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1")
else:
# just in case
tmc = TMC_2209(21, 16, 20)


#-----------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion demo/demo_script_02_pin_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
tmc = TMC_2209(21, 16, 20)
if BOARD == "RASPBERRY_PI":
tmc = TMC_2209(21, 16, 20)
elif BOARD == "NVIDIA_JETSON":
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1")
else:
# just in case
tmc = TMC_2209(21, 16, 20)






Expand Down
9 changes: 8 additions & 1 deletion demo/demo_script_03_basic_movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
tmc = TMC_2209(21, 16, 20, loglevel=Loglevel.DEBUG)
if BOARD == "RASPBERRY_PI":
tmc = TMC_2209(21, 16, 20, loglevel=Loglevel.DEBUG)
elif BOARD == "NVIDIA_JETSON":
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", loglevel=Loglevel.DEBUG)
else:
# just in case
tmc = TMC_2209(21, 16, 20, loglevel=Loglevel.DEBUG)




Expand Down
11 changes: 10 additions & 1 deletion demo/demo_script_04_stallguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
tmc = TMC_2209(21, 16, 20)
if 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 == "RASPBERRY_PI":
tmc = TMC_2209(21, 16, 20)
else:
# just in case
tmc = TMC_2209(21, 16, 20)



Expand Down
9 changes: 7 additions & 2 deletions demo/demo_script_05_vactual.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
# initiate the TMC_2209 class
# use your pin for pin_en here
#-----------------------------------------------------------------------
tmc = TMC_2209(21)

if BOARD == "RASPBERRY_PI":
tmc = TMC_2209(21, 16, 20)
elif BOARD == "NVIDIA_JETSON":
tmc = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1")
else:
# just in case
tmc = TMC_2209(21, 16, 20)



Expand Down
17 changes: 15 additions & 2 deletions demo/demo_script_06_multiple_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pylint: disable=unused-wildcard-import
#pylint: disable=unused-import
#pylint: disable=duplicate-code
#pylint: disable=broad-exception-raised
"""
test file for testing multiple drivers via one UART connection
"""
Expand All @@ -22,8 +23,20 @@
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
tmc1 = TMC_2209(21, 16, 20, driver_address=0)
tmc2 = TMC_2209(26, 13, 19, driver_address=1)
# Multiple driver not tested
if 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":
# tmc1 = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1", driver_address=0)
raise Exception("Not tested for Nvidia Jetson, use with caution")
else:
# just in case
tmc1 = TMC_2209(21, 16, 20, driver_address=0)
tmc2 = TMC_2209(26, 13, 19, driver_address=1)






Expand Down
8 changes: 7 additions & 1 deletion demo/demo_script_07_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
# initiate the TMC_2209 class
# use your pins for pin_en, pin_step, pin_dir here
#-----------------------------------------------------------------------
tmc1 = TMC_2209(21, 16, 20, driver_address=0)
if BOARD == "RASPBERRY_PI":
tmc1 = TMC_2209(21, 16, 20)
elif BOARD == "NVIDIA_JETSON":
tmc1 = TMC_2209(13, 6, 5, serialport="/dev/ttyTHS1")
else:
# just in case
tmc1 = TMC_2209(21, 16, 20)

tmc_driverlist = [tmc1]

Expand Down
4 changes: 2 additions & 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.4.1
version = 0.4.2
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 @@ -22,7 +22,7 @@ classifiers =
package_dir =
= src
packages = find:
python_requires = >=3.6
python_requires = >=3.7
install_requires =
RPi.GPIO
pyserial
Expand Down
12 changes: 5 additions & 7 deletions src/TMC_2209/TMC_2209_StepperDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

import time
import statistics
try:
from RPi import GPIO
except:
from Mock import GPIO
from ._TMC_2209_GPIO_board import GPIO, 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
Expand Down Expand Up @@ -59,6 +56,7 @@ class TMC_2209:
test_dir_step_en, test_step, test_uart, test_stallguard_threshold
)

BOARD = BOARD
tmc_uart = None
tmc_logger = None
_pin_step = -1
Expand Down Expand Up @@ -124,16 +122,16 @@ def __init__(self, pin_en, pin_step=-1, pin_dir=-1, baudrate=115200, serialport=
GPIO.setwarnings(False)
GPIO.setmode(gpio_mode)

self.tmc_logger.log("EN Pin: {pin_en}", Loglevel.DEBUG)
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)

self.tmc_logger.log("STEP Pin: {pin_step}", Loglevel.DEBUG)
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)

self.tmc_logger.log("DIR Pin: {pin_dir}", Loglevel.DEBUG)
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)
Expand Down
77 changes: 77 additions & 0 deletions src/TMC_2209/_TMC_2209_GPIO_board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#pylint: disable=unused-import
#pylint: disable=ungrouped-imports
"""
Many boards have RaspberryPI-compatible PinOut,
but require to import special GPIO module instead RPI.GPIO
This module determines the type of board
and import the corresponding GPIO module
Can be extended to support BeagleBone or other boards
"""

from os.path import exists
from ._TMC_2209_logger import TMC_logger, Loglevel

BOARD = "UNKNOWN"
dependencies_logger = TMC_logger(Loglevel.DEBUG, "DEPENDENCIES")

if not exists('/proc/device-tree/model'):
from Mock import GPIO
else:
with open('/proc/device-tree/model', encoding="utf-8") as f:
model = f.readline().lower()
if "raspberry" in model:
try:
from RPi import GPIO
BOARD = "RASPBERRY_PI"
except ModuleNotFoundError as err:
dependencies_logger.log(
(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"
"Exiting..."),
Loglevel.ERROR)
raise
except ImportError as err:
dependencies_logger.log(
(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"
"Exiting..."),
Loglevel.ERROR)
raise
elif "nvidia jetson" in model:
try:
from Jetson import GPIO
BOARD = "NVIDIA_JETSON"
except ModuleNotFoundError as err:
dependencies_logger.log(
(f"ModuleNotFoundError: {err}\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..."),
Loglevel.ERROR)
raise
except ImportError as err:
dependencies_logger.log(
(f"ImportError: {err}\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..."),
Loglevel.ERROR)
raise
else:
# just in case
dependencies_logger.log(
"The board is not recognized. Trying import default RPi.GPIO module...",
Loglevel.INFO)
BOARD = "UNKNOWN"
try:
from RPi import GPIO
except ImportError:
from Mock import GPIO
Loading

0 comments on commit 94bea92

Please sign in to comment.