Question regarding UART communication with ESP32 dev board

I can't get UART communication working with ESP32 (BPI-Leaf-S3 - Banana Pi Wiki clone of ESP32-S3-DevKitC-1) with MKS TMC2209 v2.
Here is my wiring diagram:

I'm using following Adruino code (TMC2209/TestConnection.ino at main · janelia-arduino/TMC2209 · GitHub) to test the connection.

In the first step, I want to establish communication between devices. but unfortunately no luck... :frowning:

I have a few questions:

  • Is my wiring right?
  • to get UART communication, should I solider something on driver board?
  • to get UART communication, should I connect motor supply to Vm? If yes is there some minimum required voltage?

Thank you for any ideas and suggestions.

Welcome to the forum

Please post your code here, using code tags when you do

What is the purpose of the 1K resistor ?

Does not look right.

Help us help you.

if you are using Serial1 you need to define the pins, e.g. example code

// ESP32  Serial1 test - for loopback test connect pins 16 and 15 - lines marked with <<<

#define RXD1 16       // <<<<<<<<
#define TXD1 15       // <<<<<<<<<

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);  //  <<<<<<<
  Serial.println();
  Serial.println("\n\nESP32 serial1  test Rx pin 16 Tx pin 15");
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    //Serial.write(inByte);
    Serial1.write(inByte);
  }
}

copy the TMC2209.h and TMC2209.cpp files into the same directory as your .ino file and update the Serial1 settings
in the .ino file replace <> with "", e.g.

#include "TMC2209.h"

Regarding specification the TMC2209 communicates over a UART serial port using a single wire interface, allowing bi-directional operation for full control and diagnostics. The UART single wire interface allows control of the TMC2209 with any set of microcontroller UART serial TX and RX pins. The single serial signal is connected to both the TX pin and the RX pin, with a 1k resistor between the TX pin and the RX pin to separate them.

[Idahowalker] thank you for the feedback. Adding information regarding your comments.

Code that I'm using:

#include <Arduino.h>
#include <TMC2209.h>

HardwareSerial & serial_stream = Serial2;

const long SERIAL_BAUD_RATE = 115200;
const int DELAY = 3000;

// Instantiate TMC2209
TMC2209 stepper_driver;


void setup()
{
  Serial.begin(SERIAL_BAUD_RATE);

  stepper_driver.setup(serial_stream);
}

void loop()
{
  if (stepper_driver.isSetupAndCommunicating())
  {
    Serial.println("Stepper driver is setup and communicating!");
    Serial.println("Try turning driver power off to see what happens.");
  }
  else if (stepper_driver.isCommunicatingButNotSetup())
  {
    Serial.println("Stepper driver is communicating but not setup!");
    Serial.println("Running setup again...");
    stepper_driver.setup(serial_stream);
  }
  else
  {
    Serial.println("Stepper driver is not communicating!");
    Serial.println("Try turning driver power on to see what happens.");
  }
  Serial.println("");
  delay(DELAY);
}

I'm getting the following results:

Stepper driver is not communicating!
Try turning driver power on to see what happens.

the main issue is that I should be able to communicate with TMC2209 driver board over UART port. Unfortunately, It's not working for me. I have tried to use different libraries for TMC2209 communication but I've got the same results.

I have tried to use Serial 1 and Serial 2 - no difference..

Hi tomas_albrektas!
Currently I am working on simillar setup (the only difference is I am using Arduino MEGA instead of ESP32). It seems that your circuit is missing very important connection, namely - enable pin (EN) is not connected. According to TMC2209 manual, chip is enabled when EN pin state is LOW and disabled when setup HI. Did you try that approach?
Please, check this thread, as it contains tons of useful informations. I also highly recommend you to use FlexyStepper or SpeedyStepper library.

Best regards!

PS. This is my first post on this Forum, so I am sorry if I made any mistakes :slight_smile:

1 Like

The other issue you got is not having motor power, the driver wont work without the motor power. Motor power needs to be connected first.

You can solder EN directly to GND to enable the driver, and use UART to turn it on/off.

You also need STEP & DIR pins, you can't control the motor via UART unless you have a closed loop system. UART is only there for programming the various settings of the driver. Though you can basically get away not using the DIR pin, and change the direction via UART. I have done an example of this also.

Also, the TMC2209 library you are using.. what is that? I don't see any settings anywhere?

Check the ESP32 demo code i have posted in the thread mentioned above.

1 Like

@oogryzek, @monkeyfist thank you for your answers. This weekend I will try to implement your suggestions!

Ok got some updates. Regarding DEV board specifications UART1 should be on pins 17 and 18 but I have purchased a Logic analyzer and found out that my RX and TX pins are 16 and 15 pins. Hardware serial library decided to change those pins regarding my MP type...

So when I changed pins UART communication started to work. Also, please keep in mind - UART communication will work only if you will power VMM (like @monkeyfist mentioned).

Unfortunately, I have encountered another problem :smiley: The motor does not rotate - only vibrates :frowning: Maybe something is wrong with RMS, Microstepp settings, A/B connections, or something else...

Here is my test code, maybe you could spot my mistake...

/**
 * Author Teemu Mäntykallio
 * Initializes the library and runs the stepper
 * motor in alternating directions.
 */
#include <Arduino.h>
#include <TMCStepper.h>

#define DIR_PIN 38          // Direction
#define STEP_PIN 39         // Step
#define SERIAL_PORT Serial1 // TMC2208/TMC2224 HardwareSerial port
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2

#define R_SENSE 0.11f // Match to your driver
                      // SilentStepStick series use 0.11
                      // UltiMachine Einsy and Archim2 boards use 0.2
                      // Panucatt BSD2660 uses 0.1
                      // Watterott TMC5160 uses 0.075

// Select your stepper driver type
// TMC2130Stepper driver(CS_PIN, R_SENSE);                           // Hardware SPI
// TMC2130Stepper driver(CS_PIN, R_SENSE, SW_MOSI, SW_MISO, SW_SCK); // Software SPI
// TMC2660Stepper driver(CS_PIN, R_SENSE);                           // Hardware SPI
// TMC2660Stepper driver(CS_PIN, R_SENSE, SW_MOSI, SW_MISO, SW_SCK);
// TMC5160Stepper driver(CS_PIN, R_SENSE);
// TMC5160Stepper driver(CS_PIN, R_SENSE, SW_MOSI, SW_MISO, SW_SCK);

TMC2208Stepper driver(&SERIAL_PORT, R_SENSE); // Hardware Serial
// TMC2208Stepper driver(SW_RX, SW_TX, R_SENSE);                     // Software serial
// TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS);
// TMC2209Stepper driver(SW_RX, SW_TX, R_SENSE, DRIVER_ADDRESS);

void setup()
{
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);

  // Enable one according to your setup
  // SPI.begin();                    // SPI drivers
  SERIAL_PORT.begin(115200); // HW UART drivers
                             // driver.beginSerial(115200);     // SW UART drivers

  driver.begin();          //  SPI: Init CS pins and possible SW SPI pins
                           // UART: Init SW UART (if selected) with default 115200 baudrate
  driver.toff(5);          // Enables driver in software
  driver.rms_current(600); // Set motor RMS current
  driver.microsteps(16);   // Set microsteps to 1/16th

  // driver.en_pwm_mode(true);       // Toggle stealthChop on TMC2130/2160/5130/5160
  driver.en_spreadCycle(false); // Toggle spreadCycle on TMC2208/2209/2224
  driver.pwm_autoscale(true);   // Needed for stealthChop
}

bool shaft = false;

void loop()
{
  // Run 5000 steps and switch direction in software
  for (uint16_t i = 5000; i > 0; i--)
  {
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(160);
    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(160);
  }
  shaft = !shaft;
  driver.shaft(shaft);
}

Never the less I will try to investigate my issues and I will update you on my progress.

Hi tomas_albrektas!
I am not sure if this will change anything, but you choose wrong TMC stepper, i.e. TMC2208 instead of TMC2209.
To be honest - I encountered very similar problem with the library you are using and that was the main reason I switched to FlexyStepper.

Thank you @oogryzek for your comment. In my case, it was my fault :smiley: I don't know why I thought that coils were A1 and B1 (in my motor description they were A and A) :sob: When I connected in the right way and when I set micro steps to 1/16 everything started to work.

Thank you all of your support and Ideas :wink:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.