Help with UART on TCM2209 with Micropython and Pico

Hi All

Bare with me here, quite new to everything…

I am trying to learn how to drive stepper motors with MicroPython using TMC2209 v3. So far I figured out how to drive it with steps… And then started learning PWM which lead me down the UART path (to set steps), this is where I’ve hit a wall.

So at this stage I am just trying to understand how to work with UART using TMC2209. I am using Pico and MicroPython (sys.version: 3.4.0; MicroPython v1.22.1 on 2024-01-05)

Code: Select all

from machine import UART, Pin
import utime

uart = UART(0, baudrate=115200, tx=Pin(0), rx=Pin(1))

uart.write(b"?V\n")

utime.sleep(1)

print("UART Response:", uart.readline())

Response is always “None”. I’ve spent hours trying this and that and I am not having any luck. Any advice would be super appreciated.

Regarding wiring: I am using 1k resistor on GP0, both GP0 and GP1 are jumper-wired to TMC RX pin.

Thanks!

2 Likes

hi @pinkerer - welcome to the forums :slight_smile:
I’ve had super frustrating times with uart & micropython in the past so i can relate

readline() is always a tricky one because it can be hard to debug with. If it times out it will always return None, but you may have just been looking for the wrong return character

it might be prudent while debugging to print all uart activity to the shell. consider adding the following to your code. it can also go in a main loop to continuously provide debugging information.

The following will dequeue a character from the uart whenever one is available

if uart.any():  # Check if any data is available in the buffer
        buffer = uart.read()  # Read data from UART
        print(''.join([chr(b) for b in buffer]), end='')  # Convert bytes to string and print

source: https://chat.openai.com/c/3507585f-4b35-4c60-a4cb-aa0c56a177f8

2 Likes

Did a bit ore digging. Things seems to be a lot more complex than simple UART r/w. There are experimental code snippets and some lib, but seems like serial communication with a stepper using Micropython is somewhat underdeveloped (unless you want to code from scratch) using C… Anyway, thought I’d just close this off :slight_smile:

2 Likes