Giter Club home page Giter Club logo

tmc2209_raspberry_pi's Introduction

Moin, nice to see you

Welcome to my page!
I'm Christian, mechanical engineer from ๐Ÿ‡ฉ๐Ÿ‡ช East Frisia, Germany

Mechanical Engineering

Autodesk Inventor FreeCAD Dassault Systรจmes Abaqus Octave/Matlab Blender Ultimaker Cura

Software Development

C C++ Python Bash Arduino Espressif Raspberry Pi Visual Studio Code Git GitHub Actions PyPI

tmc2209_raspberry_pi's People

Contributors

chr157i4n avatar claasiihasii avatar ju57u5 avatar ligaz avatar plexiable avatar protsey avatar sibovg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tmc2209_raspberry_pi's Issues

Implementing CRC check for reply datagrams

4 bytes are beeing send to the driver with the last byte beeing CRC.
the reply datagram from the driver consists of 8 bytes, of which the last last one is also CRC.
Notice that the Raspberry Pi receives first its own 4 bytes and afterwards the 8 reply bytes, due to the shared RX and TX on the TMC.

A check with the CRC byte, whether the reply datagram is flawless should be implemented

see:
TMC2209 datasheet
("4.1.2 Read Access" on site 19)

Operating motor with UART & setCurrent

My setup is that I would like to drive my 42HS48 motor with a TMC2209 v3.1 by UART.
The supplier who sold me the motor gave me a datasheet. According to this datasheet my motor is a 2A motor however I found other sellers online who sell the same motor but with different (lower) 1.68A current rating. Chinese sellers often dont have a clue of what they sell they just simply use a different specs that they find online and the specs sheet might have nothing to do with the physical motor in my hand. Im being cautious with the current rating.

Ive read the manual on the front page:

**test_script_05_vactual.py**
VACTUAL allows moving the motor by UART control. It gives the motor velocity in +-(2^23)-1 [ฮผsteps / t]

If Im not mistaken this is the test file I need to run to test my motor movement using only UART.

Where can I set the maximum current within this file?

I found this:

#-----------------------------------------------------------------------
# these functions change settings in the TMC register
#-----------------------------------------------------------------------
tmc.setDirection_reg(False)
tmc.setVSense(True)
tmc.setCurrent(300)
tmc.setIScaleAnalog(True)
tmc.setInterpolation(True)
tmc.setSpreadCycle(False)
tmc.setMicrosteppingResolution(2)
tmc.setInternalRSense(False)

Here are my questions:

How does tmc.setCurrent(300) refer to the output current I want to register for the motor drive? What is this 300?

Because my motor's current rating is unknown Originally I set the Vref manually to 2.46V. This as the maximum for TMC2209 v3.1 using this calculator on the page:
https://wiki.fysetc.com/Silent2209/

The function setCurrent only works correctly if the Vref voltage ist 1.2V, otherwise change Vref to 1.2V or give the actual Vref as parameter to the setCurrent function.

Do I have to manually adjust the Vref for each driver if I want to use setCurrent?
How do I test if this set current is working? I dont want to set Vref too low for setcurrent 1.2V and if I cannot change by UART setting then driver burns out due to low current setting. Is there a way for me to get a report back if setCurrent works and at what value it is at?

Also do I need to connect DIAG pin somewhere to send a Vref voltage feedback to the RPi?

I dont not want to use microstepping. Just full step. Do I nee to change anything in:

tmc.setMicrosteppingResolution(2)

Thanks again.

Implementing velocity ramping with VActual

excerpt from the TMC2209 datasheet:

14 Internal Step Pulse Generator

The TMC2209 family integrates a high-resolution step pulse generator, allowing motor motion via the
UART interface. However, no velocity ramping is provided. Ramping is not required, if the target
motion velocity is smaller than the start & stop frequency of the motor. For higher velocities, ramp up
the frequency in small steps to accelerate the motor, and ramp down again to decelerate the motor.
Figure

So in order to get to high velocity with VActual velocity ramping is required.

positions being skipped (due to performance issues)

Hi, its me again.
After some more testing I am facing another problem:
Sometimes the stepper does not wait for one command to be fully carried out before starting the next. For example:

tmc.set_max_speed_fullstep(500)
tmc.run_to_position_steps(10)
        
tmc.set_max_speed_fullstep(100)
tmc.run_to_position_steps(2000)

This seems to be a performance problem because taxing the cpu (e.g. opening a browser) escalates the situation to the point where the movement is just a rapid back and forth.
Occasionally even the homing step in the beginning of my script gets skipped.
I tried tweaking the values for acceleration and speed, limiting them to 500 fullstep for acceleration and 250 fullstep for speed.

Do you have any suggestion on how tackle this problem?
Or is what I am trying to do more than what is possible in python.

I am running a Pi3B+ with raspbian 64bit btw. I could switch to a lite and or 32bit version if that helps.

Some background:
I just need the motor to run through a series of positions, preferably changing speeds between after every position. The idea is to have four "slow" sections and faster sections in between. At the end of the linear setup the contraption shall return to the first position.
the length of the whole rail measures about 12000 Steps

Permission denied: '/dev/serial0

Hi,

I wanted to try the UART test script but Im getting permission denied problems:

`pi@raspberrypi:~/Desktop/TMC2209 $ python3 -m tests.test_script_01_uart_connection

SCRIPT START

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 322, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
PermissionError: [Errno 13] Permission denied: '/dev/serial0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/pi/Desktop/TMC2209/tests/test_script_01_uart_connection.py", line 17, in <module>
tmc = TMC_2209(16, 20, 21)
File "/home/pi/Desktop/TMC2209/src/TMC_2209/TMC_2209_StepperDriver.py", line 80, in init
self.tmc_uart = TMC_UART(serialport, baudrate, driver_address)
File "/home/pi/Desktop/TMC2209/src/TMC_2209/TMC_2209_uart.py", line 30, in init
self.ser = serial.Serial (serialport, baudrate)
File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 244, in init
self.open()
File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 325, in open
raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 13] could not open port /dev/serial0: [Errno 13] Permission denied: '/dev/serial0'
Exception ignored in: <function TMC_UART.del at 0x7f803b2700>
Traceback (most recent call last):
File "/home/pi/Desktop/TMC2209/src/TMC_2209/TMC_2209_uart.py", line 48, in del
self.ser.close()
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function TMC_2209.del at 0x7f803c1f70>
Traceback (most recent call last):
File "/home/pi/Desktop/TMC2209/src/TMC_2209/TMC_2209_StepperDriver.py", line 102, in del
self.log("Deinit", Loglevel.info.value)
File "/home/pi/Desktop/TMC2209/src/TMC_2209/TMC_2209_StepperDriver.py", line 122, in log
print(self.logprefix+""+str(self.tmc_uart.mtr_id)+": "+message)
AttributeError: 'NoneType' object has no attribute 'mtr_id'
pi@raspberrypi:~/Desktop/TMC2209 $`

Ive checked config.txt. UART1 is enabled.

Do you know what could be the problem?
Thank you

TWOTREES TMC2209 v2.0 passes tests but fails to energize stepper

Describe the bug
The basic tests seem to pass happily (pin, uart), but the stepper isn't moving when trying the basic movement demo. Doesn't even seem to be energized since I can turn it freely during movement.

Sanity checks performed:

  • Measured resistance on both coils is 2 Ohm
  • Stepper spins freely without power
  • Stepper Locks up when coil connected directly to the power supply
  • Triple-checked wiring
  • Made sure each coil is connected to A/B terminals of
  • UART test seems to pass
  • Pins test seems to pass

Any tips about how to proceed?
I tried the movement pin/uart debug and movement demo scripts on 3 different, brand-new drivers with the same result.
Any other basic troubleshooting I might be missing?

python -m demo.debug_script_01_uart_connection

---
SCRIPT START
---
TMC2209 0: Init
TMC2209 0: EN Pin: 26
TMC2209 0: STEP Pin: 19
TMC2209 0: DIR Pin: 13
TMC2209 0: GPIO Init finished
TMC2209 0: Init finished
---
---
TMC2209 0: ---
TMC2209 0: TEST UART
TMC2209 0: received 12 bytes; 96 bits
TMC2209 0: hex: 550006e805ff0621000251a5
TMC2209 0: bin: 010101010000000000000110111010000000010111111111000001100010000100000000000000100101000110100101
TMC2209 0: length snd: 4
TMC2209 0: length rtn: 12
TMC2209 0: complete messages:
TMC2209 0: 550006e8
TMC2209 0: 550006e805ff0621000251a5
TMC2209 0: just the first 4 bits:
TMC2209 0: 550006e8
TMC2209 0: 550006e8
TMC2209 0: the Raspberry Pi received the sended
                            bits and the answer from the TMC
TMC2209 0: the Raspberry Pi received exactly the bits it has send.
                    the first 4 bits are the same
TMC2209 0: ---
TMC2209 0: UART connection: OK
TMC2209 0: ---
---
---
TMC2209 0: Deinit
TMC2209 0: Motor output active: False
TMC2209 0: GPIO cleanup
TMC2209 0: Deinit finished
---
SCRIPT FINISHED
---

python -m demo.demo_script_01_uart_connection

---
SCRIPT START
---
TMC2209 0: Init
TMC2209 0: GPIO Init finished
TMC2209 0: clearing GSTAT
TMC2209 0: Init finished
TMC2209 0: Init
TMC2209 0: EN Pin: 26
TMC2209 0: STEP Pin: 19
TMC2209 0: DIR Pin: 13
TMC2209 0: GPIO Init finished
TMC2209 0: clearing GSTAT
TMC2209 0: Init finished
TMC2209 0: Deinit
TMC2209 0: Motor output active: False
TMC2209 0: GPIO cleanup
TMC2209 0: Deinit finished
TMC2209 0: write normal motor direction
TMC2209 0: activated 5V-out for current scale
TMC2209 0: CS too low; switching to VSense True
TMC2209 0: activated High sensitivity, low sense resistor voltage
TMC2209 0: cs_irun: 9
TMC2209 0: CS_IHold: 4
TMC2209 0: Delay: 10
TMC2209 0: actual current: 306 mA
TMC2209 0: ihold_irun: 0b10100000100100000100
TMC2209 0: writing ihold_irun
TMC2209 0: enabled PDN_UART
TMC2209 0: writing microstep interpolation setting: True
TMC2209 0: activated Stealthchop
TMC2209 0: writing 2 microstep setting
TMC2209 0: writing MStep Reg Select: True
TMC2209 0: activated operation with external sense resistors
---
---
TMC2209 0: ---
TMC2209 0: INPUTS
TMC2209 0: 0b100001000000000000001001010001
TMC2209 0: spread is low
TMC2209 0: dir is high
TMC2209 0: step is low
TMC2209 0: en is high
TMC2209 0: ---
TMC2209 0: ---
TMC2209 0: CHOPPER CONTROL
TMC2209 0: 0b10111000000110000000001010011
TMC2209 0: native 2 microstep setting
TMC2209 0: interpolation to 256 ยตsteps
TMC2209 0: 1: High sensitivity, low sense resistor voltage
TMC2209 0: ---
TMC2209 0: ---
TMC2209 0: DRIVER STATUS:
TMC2209 0: -0b111111111101110000000000000000
TMC2209 0: Info: motor is standing still
TMC2209 0: Info: motor is running on StealthChop
TMC2209 0: CS actual: 9
TMC2209 0: ---
TMC2209 0: ---
TMC2209 0: GENERAL CONFIG
TMC2209 0: 0b111000000
TMC2209 0: Driver is using internal reference derived from 5VOUT
TMC2209 0: Operation with external sense resistors
TMC2209 0: StealthChop PWM mode enabled
TMC2209 0: normal motor direction
TMC2209 0: INDEX shows the first microstep position of sequencer
TMC2209 0: INDEX output as selected by index_otpw
TMC2209 0: Microstep resolution selected by MSTEP register
TMC2209 0: ---
---
---
TMC2209 0: Deinit
TMC2209 0: Motor output active: False
TMC2209 0: GPIO cleanup
TMC2209 0: Deinit finished
---
SCRIPT FINISHED
---

python -m demo.demo_script_02_pin_connection

---
SCRIPT START
---
TMC2209 0: Init
TMC2209 0: GPIO Init finished
TMC2209 0: clearing GSTAT
TMC2209 0: Init finished
TMC2209 0: write normal motor direction
TMC2209 0: activated 5V-out for current scale
TMC2209 0: CS too low; switching to VSense True
TMC2209 0: activated High sensitivity, low sense resistor voltage
TMC2209 0: cs_irun: 9
TMC2209 0: CS_IHold: 4
TMC2209 0: Delay: 10
TMC2209 0: actual current: 306 mA
TMC2209 0: ihold_irun: 0b10100000100100000100
TMC2209 0: writing ihold_irun
TMC2209 0: enabled PDN_UART
TMC2209 0: writing microstep interpolation setting: True
TMC2209 0: activated Stealthchop
TMC2209 0: writing 2 microstep setting
TMC2209 0: writing MStep Reg Select: True
TMC2209 0: activated operation with external sense resistors
---
---
TMC2209 0: ---
TMC2209 0: INPUTS
TMC2209 0: 0b100001000000000000001011010001
TMC2209 0: spread is low
TMC2209 0: dir is high
TMC2209 0: step is high
TMC2209 0: en is high
TMC2209 0: ---
TMC2209 0: ---
TMC2209 0: INPUTS
TMC2209 0: 0b100001000000000000000001010000
TMC2209 0: spread is low
TMC2209 0: dir is low
TMC2209 0: step is low
TMC2209 0: en is low
TMC2209 0: ---
TMC2209 0: ---
TMC2209 0: INPUTS
TMC2209 0: 0b100001000000000000001011010001
TMC2209 0: spread is low
TMC2209 0: dir is high
TMC2209 0: step is high
TMC2209 0: en is high
TMC2209 0: ---
TMC2209 0: Motor output active: False
TMC2209 0: ---
TMC2209 0: Pin DIR:     OK
TMC2209 0: Pin STEP:    OK
TMC2209 0: Pin EN:      OK
TMC2209 0: ---
---
---
TMC2209 0: Motor output active: False
---
---
TMC2209 0: Deinit
TMC2209 0: Motor output active: False
TMC2209 0: GPIO cleanup
TMC2209 0: Deinit finished
---
SCRIPT FINISHED
---

python -m demo.demo_script_03_basic_movement

---
SCRIPT START
---
TMC2209 0: Init
TMC2209 0: EN Pin: 26
TMC2209 0: STEP Pin: 19
TMC2209 0: DIR Pin: 13
TMC2209 0: GPIO Init finished
TMC2209 0: clearing GSTAT
TMC2209 0: Init finished
TMC2209 0: write normal motor direction
TMC2209 0: activated 5V-out for current scale
TMC2209 0: CS too low; switching to VSense True
TMC2209 0: activated High sensitivity, low sense resistor voltage
TMC2209 0: cs_irun: 9
TMC2209 0: CS_IHold: 4
TMC2209 0: Delay: 10
TMC2209 0: actual current: 306 mA
TMC2209 0: ihold_irun: 0b10100000100100000100
TMC2209 0: writing ihold_irun
TMC2209 0: enabled PDN_UART
TMC2209 0: writing microstep interpolation setting: True
TMC2209 0: activated Stealthchop
TMC2209 0: writing 2 microstep setting
TMC2209 0: writing MStep Reg Select: True
TMC2209 0: activated operation with external sense resistors
---
---
TMC2209 0: ---
TMC2209 0: INPUTS
TMC2209 0: 0b100001000000000000001001010001
TMC2209 0: spread is low
TMC2209 0: dir is high
TMC2209 0: step is low
TMC2209 0: en is high
TMC2209 0: ---
TMC2209 0: ---
TMC2209 0: CHOPPER CONTROL
TMC2209 0: 0b10111000000110000000001010011
TMC2209 0: native 2 microstep setting
TMC2209 0: interpolation to 256 ยตsteps
TMC2209 0: 1: High sensitivity, low sense resistor voltage
TMC2209 0: ---
TMC2209 0: ---
TMC2209 0: DRIVER STATUS:
TMC2209 0: -0b111111111101110000000000000000
TMC2209 0: Info: motor is standing still
TMC2209 0: Info: motor is running on StealthChop
TMC2209 0: CS actual: 9
TMC2209 0: ---
TMC2209 0: ---
TMC2209 0: GENERAL CONFIG
TMC2209 0: 0b111000000
TMC2209 0: Driver is using internal reference derived from 5VOUT
TMC2209 0: Operation with external sense resistors
TMC2209 0: StealthChop PWM mode enabled
TMC2209 0: normal motor direction
TMC2209 0: INDEX shows the first microstep position of sequencer
TMC2209 0: INDEX output as selected by index_otpw
TMC2209 0: Microstep resolution selected by MSTEP register
TMC2209 0: ---
---
---
TMC2209 0: Motor output active: True
TMC2209 0: Motor output active: False
---
---
TMC2209 0: Deinit
TMC2209 0: Motor output active: False
TMC2209 0: GPIO cleanup
TMC2209 0: Deinit finished
---
SCRIPT FINISHED
---

To Reproduce
Steps to reproduce the behavior:

  1. clone the repo
  2. from repo root, run `python -m demo.demo_X.py

Expected behavior
Stepper should rotate, as per demo/demo_script_03_basic_movement.py

Versions

  • Raspberry Pi 4
  • Raspbian GNU/Linux 11 (bullseye)
  • 0.4.3
  • TWOTREES TMC2209 v2.0

Additional context
photo1712622653
TMC2209 is powered using a variable power supply set to 12V
RPi powered seperately

TMC2209: after 10 tries not valid write access

Describe the bug
After writing quite a few values to the TMC registers, the error occurs

To Reproduce
Write a setting in a loop, after a while the error occurs

Error source
The error occurs in TMC_2209_uart.write_reg_check() when the register IFCNT reaches 255. According to the Datasheet, the register IFCNT wraps around from 255 to 0, but that condition isn't handled, so it just throws an error, even though everyting is fine.

Temporary Fix

    def write_reg_check(self, register, val, tries=10):
        ifcnt1 = self.read_int(reg.IFCNT)
        
        if(ifcnt1 == 255): # <-- wraparound fix
            ifcnt1 = -1

        while(True):
            self.write_reg(register, val)
            tries -= 1
            ifcnt2 = self.read_int(reg.IFCNT)
            if(ifcnt1 >= ifcnt2):
                print("TMC2209: writing not successful!")
                print("TMC2209: ifcnt:",ifcnt1,ifcnt2)
            else:
                return True
            if(tries<=0):
                print("TMC2209: after 10 tries not valid write access")
                self.handle_error()
                return -1

It would probably be prettier to add the right check to the error checking if instead of my "dirty" fix ๐Ÿ˜…

Implementing automatic switching between VSense

Implenting automatic switching between VSense 1 and VSense 0.

For high currents VSense 0 needs to be used.
In Order to get more accurate currents, for lower currents VSense 1 should be used.

https://github.com/teemuatlut/TMCStepper/blob/master/src/source/TMCStepper.cpp

#-----------------------------------------------------------------------
# sets the current flow for the motor
# run_current in mA
# check whether Vref is actually 1.2V
#-----------------------------------------------------------------------
def setCurrent(self, run_current, hold_current_multiplier = 0.5, hold_current_delay = 10, Vref = 1.2):
CS_IRun = 0
Rsense = 0.11
Vfs = 0
if(self.getVSense()):
self.log("Vsense: 1", Loglevel.info.value)
Vfs = 0.180 * Vref / 2.5
else:
self.log("Vsense: 0", Loglevel.info.value)
Vfs = 0.325 * Vref / 2.5
CS_IRun = 32.0*1.41421*run_current/1000.0*(Rsense+0.02)/Vfs - 1
CS_IRun = min(CS_IRun, 31)
CS_IRun = max(CS_IRun, 0)
CS_IHold = hold_current_multiplier * CS_IRun
CS_IRun = round(CS_IRun)
CS_IHold = round(CS_IHold)
hold_current_delay = round(hold_current_delay)
self.log("CS_IRun: " + str(CS_IRun), Loglevel.info.value)
self.log("CS_IHold: " + str(CS_IHold), Loglevel.info.value)
self.log("Delay: " + str(hold_current_delay), Loglevel.info.value)
self.setIRun_Ihold(CS_IHold, CS_IRun, hold_current_delay)

When will version 0.4.3 be released

Hi,

First of all, thank you so much for this excellent library @Chr157i4n! Really appreciate it. However, I'm experiencing issues with my project due to #49 which was fixed in 7092ad1. Is there a roadmap of when version 0.4.3 will be released on pip?

Thanks!

Compatible with Watterott TMC2209?

Hello, is your libary also working in UART mode with the Watterott TMC2209 I cannot get a working connection neither with the ESP32 nor the RPI, I followed the instructions to solder the pads on bottomside of the Watterott chip together.
Any help would be nice

Standstill current reduction not working (iHOLD)

Describe the bug
When setting IHOLD and IRUN the current doesn't get reduced when the motor is standing still

To Reproduce
Set a different hold_current_multiplier with tmc.setCurrent(600, hold_current_multiplier=0)
When the stepper is enabled and standing still, it remains powered.

Expected behavior
When hold_current_multiplier=0, the stepper should freewheel (or spinning almost freely) when it is standing still and enabled

Cause
According to official documentation, when using uart, you should set pdn_disable in GCONF to 1 to enable standstill current reduction.
(see Documentation p.20)

Solution
Set pdn_disable to 1

Temporary fix:

gconf = tmc.readGCONF()
gconf = gconf | 1 << 6
tmc.tmc_uart.write_reg_check(0x00, gconf)

First vactual after TMC power-on is different than the rest

Describe the bug
After the TMC driver has been turned on, the first call to set_vactual_rpm() produces a different (lower) vactual value than all the other next calls.

To Reproduce
Steps to reproduce the behavior:

  1. power on the TMC2209 driver
  2. run the attached file stepper_test1.py several times

Expected behavior
Even the first call produces the same correct speed.

Versions

  • Raspberry Pi 4
  • OS Version 12-bookworm
  • Version of this library 0.4.1
  • TMC2209 version and manufacturer BigTreeTech TMC2209 v1.2

console_output.txt
stepper_test1.py.txt

about wiring diagram and wiring table

Thank you very much for sharing. I'm a little confused about the wiring diagram and wiring table and I'm hoping you can shed some light on it. In the wiring table, GND2 is connected to the GND of the Raspberry Pi. What does GND2 represent? My understanding is the GND of the 5V output. Why is the GND connected to the Raspberry Pi in the picture the power supply GND?

Do something else while running a stepper

Hi
I am trying to build a machine that reads data from a serial port while simultaneously moving the reading-head of the serial device with a stepper motor.
Both operations, the reading & saving data and the movement of the motor work without any problems in their own scripts, but when I combine them with multiprocessing the stepper stutters and the Pi3B+ freezes up.
As I am a python-beginner I am not even sure if this is a problem with the library per se.

from TMC_2209.TMC_2209_StepperDriver import *
import time
import multiprocessing
import serial
import time
import csv

ser = serial.Serial('/dev/ttyACM0', 9600)
ser.flushInput()
print(ser.name) 


def reading():
    while True:
        try:
            ser_bytes = ser.readline()
            decoded_bytes = ser_bytes.decode('utf-8').rstrip()
            l=len(decoded_bytes)
            rdate=decoded_bytes[0:10]
            rtime=decoded_bytes[11:19]
            tagid=decoded_bytes[20:l-6]
            # removing the 5 last charaters for the temp with 2 decimals an seperating /t
            temp=decoded_bytes[l-5:l-1]
            # temperature with decimalpoint 2 decimals and leaving the unit
            print(rdate)
            print(rtime)
            print(tagid)
            print(temp)
            
            with open("test_data.csv","a") as f:
                writer = csv.writer(f,delimiter=',')
                writer.writerow([rdate,rtime,tagid,temp])
        except:
            print("Keyboard Interrupt")
            break

    

def movement():
    while True:
        tmc.set_max_speed_fullstep(500)
        tmc.run_to_position_steps(200)
        print("go to box1 start")
        tmc.set_max_speed_fullstep(10)
        tmc.run_to_position_steps(400)
        print("go to box1 end")

        tmc.set_max_speed_fullstep(500)
        tmc.run_to_position_steps(600)
        print("go to box2 start")
        
        tmc.set_max_speed_fullstep(10)
        tmc.run_to_position_steps(800)
        print("go to box1 end")
        

print("---")
print("SCRIPT START")
print("---")




#-----------------------------------------------------------------------
# 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)





#-----------------------------------------------------------------------
# set the loglevel of the libary (currently only printed)
# set whether the movement should be relative or absolute
# both optional
#-----------------------------------------------------------------------
tmc.set_loglevel(Loglevel.DEBUG)
tmc.set_movement_abs_rel(MovementAbsRel.ABSOLUTE)





#-----------------------------------------------------------------------
# these functions change settings in the TMC register
#-----------------------------------------------------------------------
tmc.set_direction_reg(False)
tmc.set_current(300)
tmc.set_interpolation(True)
tmc.set_spreadcycle(True)
tmc.set_microstepping_resolution(2)
tmc.set_internal_rsense(False)


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

#-----------------------------------------------------------------------
# these functions read and print the current settings in the TMC register
#-----------------------------------------------------------------------
tmc.readIOIN()
tmc.readCHOPCONF()
tmc.readDRVSTATUS()
tmc.readGCONF()

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

#-----------------------------------------------------------------------
# set the Acceleration and maximal Speed
#-----------------------------------------------------------------------
# tmc.set_acceleration(2000)
# tmc.set_max_speed(500)

#-----------------------------------------------------------------------
# set the Acceleration and maximal Speed in fullsteps
#-----------------------------------------------------------------------
tmc.set_acceleration_fullstep(500)
tmc.set_max_speed_fullstep(250)

#-----------------------------------------------------------------------
# activate the motor current output
#-----------------------------------------------------------------------
tmc.set_motor_enabled(True)

#-----------------------------------------------------------------------
# homing
# 1. param: DIAG pin
# 2. param: maximum number of revolutions. Can be negative for inverse direction
# 3. param(optional): StallGuard detection threshold
#-----------------------------------------------------------------------
print ("homing")
tmc.do_homing(26,-2000,50)

#then run moving and reading simultaneously

while True:
    print("moving and reading")
    if __name__ == '__main__':
        p1 = multiprocessing.Process(name='p1',target=movement)
        p = multiprocessing.Process(name='p',target=reading)
        p1.start()
        p.start()



#-----------------------------------------------------------------------
# deactivate the motor current output
#-----------------------------------------------------------------------
tmc.set_motor_enabled(False)

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





#-----------------------------------------------------------------------
# deinitiate the TMC_2209 class
#-----------------------------------------------------------------------
tmc.deinit()
del tmc

print("---")
print("SCRIPT FINISHED")
print("---")

Schematics

Hi, could you please provide schematics? I'm using tmc2209 with raspberry pi zero w, and this is what I get:

pi@pi:~/TMC2209_Raspberry_Pi $ python3 test_script_01_uart_connection.py 
---
SCRIPT START
---
TMC2209: Init
TMC2209: GPIO Init finished
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: did not get the expected 4 data bytes. Instead got 0 Bytes
TMC2209: after 10 tries not valid answer. exiting
TMC2209: Deinit
TMC2209: Motor output active: False

Would love to check if I had some error wiring, I just connected tmc2209 RX to RPi's TX(8 pin) and tmc2209 TX to RPi's RX(10 pin).

Add to pip

It would be great if I could download this library from pip and keep it up to date without copying the code from the repo.

Current method works great for running tests but I want to build something more serious.

Destructor not beeing called

Describe the bug
The destructor of the TMC class is not beeing called.
Therefore the StallGuard thread is still running and causing the following error

 Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name='<stdout>'> at interpreter shutdown, possibly due to daemon threads
Python runtime state: finalizing (tstate=0x5c3888)

Current thread 0xb6f41980 (most recent call first):
<no Python frame>
Aborted 

Expected behavior
that the destructor is beeing called when the class is beeing deleted ("del tmc")

Versions
Raspberry Pi CM4
Raspberry Pi OS 11 "Bullseye"
Version 0.1.7 of this library
FYSETC TMC2209 V3.0

Adding a function for continous turning

Hi,

For a project I'm working on I needed to make a stepper turn continuously for up to an hour. I've used your library with VACTUAL to make it work by adding a function set to true the deinitalize flag at the end so the driver doesn't deinitalize itself at the end of the code.

#-----------------------------------------------------------------------
# set deinitialize to true
#-----------------------------------------------------------------------       
    def setDeinitializeTrue(self):
        self._deinit_finished = True

Though this might be useful to someone else in an other project someday. Could you add it to the TMC_2209_StepperDriver.py ?

How to disable UART and use just STEP/DIR

Describe the bug
I would like to control CL57T using this driver, but unfortunetly this stepper driver does not support uart.

Wouldn't it be possible to adapt your library to accept also stepper drivers without UART connection?

Thank you!

Motor randomly spins in the wrong direction

Description
When I run my code the motor randomly spins in the wrong direction sometimes.

To Reproduce
Steps to reproduce the behavior:

  1. Installed libraries
  2. Ran code
  3. Motor spins in wrong direction at random times

Expected behavior
Expected it to consistently run in the right direction

Versions

  • Raspberry Pi 3B+
  • Latest Version of Library
  • Bigtreetech TMC2209 v1.2

Code

from TMC_2209.TMC_2209_StepperDriver import *
import time

# initiate the TMC_2209 class
# use your pins for pin_step, pin_dir, pin_en here

tmc = TMC_2209(16, 20, 21)

# set whether the movement should be relative or absolute
#tmc.setMovementAbsRel(MovementAbsRel.relative)

# these functions change settings in the TMC register
tmc.setDirection_reg(True)
tmc.setVSense(True)
tmc.setCurrent(300)
tmc.setIScaleAnalog(True)
tmc.setInterpolation(True)
tmc.setSpreadCycle(False)
tmc.setMicrosteppingResolution(16)
tmc.setInternalRSense(False)

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

# set the Accerleration and maximal Speed
tmc.setAcceleration(16000)
tmc.setMaxSpeed(4000)

#activate motor
tmc.setMotorEnabled(True)

tmc.runToPositionSteps(6000, MovementAbsRel.relative)

tmc.setMotorEnabled(False)
del tmc

Connecting two tmc2209 to serial

What is the recommended way to connect multiple 2209 steppers to the same rpi uart? Do I run them in serial or tie them both in to the same pin in parallel?

RuntimeError when redoing homing after failed attempt

Describe the bug
I am running the do_homing method, but when I try to rerun the homing after a failed attempt, I get this error:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Traceback (most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ /home/pi/Downloads/dip_coater/src/dip_coater/tui.py:267 in do_homing_action                                                                                                      โ”‚
โ”‚                                                                                                                                                                                  โ”‚
โ”‚    264 โ”‚   โ”‚   โ”‚   log.write(f"[cyan]Doing homing ({revs=}, {threshold=}, {speed=} RPM)...[/]") โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ locals โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ                                             โ”‚
โ”‚    265 โ”‚   โ”‚   โ”‚   self.set_motor_state("homing")                                               โ”‚       log = RichLog(id='logger') โ”‚                                             โ”‚
โ”‚    266 โ”‚   โ”‚   โ”‚   await asyncio.sleep(0.1)                                                     โ”‚      revs = 10                   โ”‚                                             โ”‚
โ”‚ โฑ  267 โ”‚   โ”‚   โ”‚   self.motor_driver.do_homing(revs, threshold, speed)                          โ”‚      self = MotorControls()      โ”‚                                             โ”‚
โ”‚    268 โ”‚   โ”‚   โ”‚   log.write("-> Finished homing.")                                             โ”‚     speed = 75                   โ”‚                                             โ”‚
โ”‚    269 โ”‚   โ”‚   โ”‚   self.set_motor_state("enabled")                                              โ”‚ threshold = 190                  โ”‚                                             โ”‚
โ”‚    270 โ”‚   โ”‚   elif self._motor_state == "homing":                                              โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ                                             โ”‚
โ”‚                                                                                                                                                                                  โ”‚
โ”‚ /home/pi/Downloads/dip_coater/src/dip_coater/motor.py:145 in do_homing                                                                                                           โ”‚
โ”‚                                                                                                                                                                                  โ”‚
โ”‚   142 โ”‚   โ”‚   """                                                                              โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ locals โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ    โ”‚
โ”‚   143 โ”‚   โ”‚   # Homing sets the spreadcycle to StealthChop, so we need to store the original s โ”‚  revolutions = 10                                                          โ”‚    โ”‚
โ”‚   144 โ”‚   โ”‚   spread_cycle = self.tmc.get_spreadcycle()                                        โ”‚         self = <dip_coater.motor.TMC2209_MotorDriver object at 0xb5553100> โ”‚    โ”‚
โ”‚ โฑ 145 โ”‚   โ”‚   self.tmc.do_homing(                                                              โ”‚    speed_rpm = 75                                                          โ”‚    โ”‚
โ”‚   146 โ”‚   โ”‚   โ”‚   diag_pin=self.diag_pin,                                                      โ”‚ spread_cycle = 0                                                           โ”‚    โ”‚
โ”‚   147 โ”‚   โ”‚   โ”‚   revolutions=revolutions,                                                     โ”‚    threshold = 190                                                         โ”‚    โ”‚
โ”‚   148 โ”‚   โ”‚   โ”‚   threshold=threshold,                                                         โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ    โ”‚
โ”‚                                                                                                                                                                                  โ”‚
โ”‚ /home/pi/.local/lib/python3.8/site-packages/TMC_2209/TMC_2209_StepperDriver.py:230 in do_homing                                                                                  โ”‚
โ”‚                                                                                                                                                                                  โ”‚
โ”‚   227 โ”‚   โ”‚                                                                                    โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ locals โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚
โ”‚   228 โ”‚   โ”‚   self.tmc_logger.log(f"Stallguard threshold: {self._sg_threshold}", Loglevel.DEBU โ”‚    diag_pin = 26                                                              โ”‚ โ”‚
โ”‚   229 โ”‚   โ”‚                                                                                    โ”‚ revolutions = 10                                                              โ”‚ โ”‚
โ”‚ โฑ 230 โ”‚   โ”‚   self.set_stallguard_callback(diag_pin, self._sg_threshold, self.stop,            โ”‚        self = <TMC_2209.TMC_2209_StepperDriver.TMC_2209 object at 0xb5553148> โ”‚ โ”‚
โ”‚   231 โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”‚    0.5*tmc_math.rps_to_steps(speed_rpm/60, self._steps โ”‚   speed_rpm = 75                                                              โ”‚ โ”‚
โ”‚   232 โ”‚   โ”‚                                                                                    โ”‚   threshold = 190                                                             โ”‚ โ”‚
โ”‚   233 โ”‚   โ”‚   homing_failed = self.set_vactual_rpm(speed_rpm, revolutions=revolutions)         โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ โ”‚
โ”‚                                                                                                                                                                                  โ”‚
โ”‚ /home/pi/.local/lib/python3.8/site-packages/TMC_2209/TMC_2209_StepperDriver.py:486 in set_stallguard_callback                                                                    โ”‚
โ”‚                                                                                                                                                                                  โ”‚
โ”‚   483 โ”‚   โ”‚                                                                                                                                                                      โ”‚
โ”‚   484 โ”‚   โ”‚   GPIO.setup(self._pin_stallguard, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)                                                                                              โ”‚
โ”‚   485 โ”‚   โ”‚                                                                                                                                                                      โ”‚
โ”‚ โฑ 486 โ”‚   โ”‚   GPIO.add_event_detect(self._pin_stallguard, GPIO.RISING, callback=self.stallguar                                                                                   โ”‚
โ”‚   487 โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”‚     bouncetime=300)                                                                                                                              โ”‚
โ”‚   488                                                                                                                                                                            โ”‚
โ”‚   489                                                                                                                                                                            โ”‚
โ”‚                                                                                                                                                                                  โ”‚
โ”‚ โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ locals โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ                                                                      โ”‚
โ”‚ โ”‚       callback = <bound method stop of <TMC_2209.TMC_2209_StepperDriver.TMC_2209 object at 0xb5553148>> โ”‚                                                                      โ”‚
โ”‚ โ”‚      min_speed = 1000.0                                                                                 โ”‚                                                                      โ”‚
โ”‚ โ”‚ pin_stallguard = 26                                                                                     โ”‚                                                                      โ”‚
โ”‚ โ”‚           self = <TMC_2209.TMC_2209_StepperDriver.TMC_2209 object at 0xb5553148>                        โ”‚                                                                      โ”‚
โ”‚ โ”‚      threshold = 190                                                                                    โ”‚                                                                      โ”‚
โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ                                                                      โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
RuntimeError: Conflicting edge detection already enabled for this GPIO channel

To Reproduce
Steps to reproduce the behavior:

  1. installed the library with pip
  2. ran the function 'do_homing'
  3. Homing failed because I did not set the revolutions parameter high enough
  4. Retried homing
  5. Got the error

Expected behavior
The event should be removed from the diag pin after homing has finished.

Versions

  • Raspberry Pi Version 4 model B
  • OS Version
  • Version of this library 0.4.4
  • TMC2209 1.3 Bigtreetech

stallguard / finding values

hi christian,

i have been using a bigtreetech board with marlin before. with the stallguard autohoming function of marlin, i was able to very smoothly find the endstops of my sliders. one light touch and stallguard got triggered.

now, i wanted to try to do this sligthly differently - and i found your library. most things work quite nicely, but the one thing that seems difficult is finding threshholds for stallguard. sometimes, despite being stuck, the driver doesnt register this, while at other times, it triggers in situations where it shouldn't ...

i've been playing with various combinations of current limit and threshold values, but was unable to find anything reliable.

do you have any recommendations / strategies for finding good settings? i'm using leadscrew sliders like this, which have rather clear end stops.

s-l1600

regards

.rm

Stallguard fires right away

Getting another problem:
Stallguard fires right away.
only if i'm o very low speed and low acceleration. like 10,15
Here is my code:

`
tmc.setDirection_reg(False)
tmc.setVSense(True)

tmc.setIScaleAnalog(True)
tmc.setInterpolation(True)
tmc.setSpreadCycle(False)
tmc.setMicrosteppingResolution(1)
tmc.setInternalRSense(False)

tmc.setCurrent(200)
tmc.setAcceleration(100)
tmc.setMaxSpeed(100)

tmc.setMotorEnabled(True)

def my_callback(channel):
print("StallGuard!")
tmc.stop()

tmc.getStallguard_Result()
tmc.setStallguard_Callback(21, 50, my_callback)

finishedsuccessfully = tmc.runToPositionSteps(2000, MovementAbsRel.relative)
tmc.getStallguard_Result()
if(finishedsuccessfully == True):
print("Movement finished successfully")
else:
print("Movement was not completed")

tmc.setMotorEnabled(False)

`

Simple setup, stepper 17hs13 with 0.4A
PSU is 9v
Any suggestions?
Badly wat to use Stallguard instead of using microswitches.

Thanks

Versions

  • using esp32
  • OS Version windows
  • Version of this library
  • TMC2209 version and manufacturer dont have ver. aliexpress

any chance of adding VACTUAL?

W 0x22 24 VACTUAL
VACTUAL allows moving the motor by UART control.
It gives the motor velocity in +-(2^23)-1 [ยตsteps / t]
0: Normal operation. Driver reacts to STEP input.
/=0: Motor moves with the velocity given by VACTUAL. Step
pulses can be monitored via INDEX output. The motor
direction is controlled by the sign of VACTUAL.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.