Help talking to uart bus servos in 6 axis robotic arm

Thread Starter

-live wire-

Joined Dec 22, 2017
956
So I am designing and building a 6 axis robotic arm and I really need help finding the right library and communication method to talk to the bus servos I have installed. This is the product page and this is the google drive with the documentation that the manufacturer provided. I also put an image of the arm below. The first 3 axes are stepper motors, and the last 3 are servos, and the gripper is also a servo. The microcontroller that is wired to all the hardware is an ESP32 programmed with the arduino IDE, and it must communicate both ways with a computer over serial.

My understanding of how the servos work is this. The way the servos talk to the microcontroller is through UART serial communication. Each servo is first individually given a byte for its ID, and then all servos are connected to the same data line for both RX and TX, as well as the same power supply. When a command is sent out, it starts by addressing the ID of the motor. The servos have a variety of read and write functions that I need to use to get the arm to work the way I want it to. Part of the challenge is that there are parts of the arm that require multiple full rotations (the servos do have continuous rotation capabilities).

There are two big obstacles I am facing that I really need help overcoming:
1. I am unsure how to execute some of the write commands and any of the read commands with the servos I have installed. I have tried a lot of things but I am pretty stuck. I have only had success with the write ID and write position commands.
2. I don't know how to avoid conflicts between the required serial communication between the USB serial communication between the ESP32 and computer, and the serial communication between the servos and the ESP32. I am considering software serial but I am unfamiliar with that.

Thank you!

Simon

1658803639778.png
 

MrChips

Joined Oct 2, 2009
27,122
They say a picture is worth a thousand words.
Start by drawing a picture of all your hardware controllers showing how they are all interconnected.
 

MrChips

Joined Oct 2, 2009
27,122
Thanks for the drawing. That is a good start and it helps a lot.
Now you need to focus on the Arduino or ESP32 box an show in more detail how the PC, servos, stepper motors, sensors are connected. Since there are multiple units you need to show how each is connected, i.e. with bused signals or separate signals.

I see in your photograph that you are using DM542-style motor drivers or similar.
1658844369273.png

These are controlled by separate STEP and DIR signals for each controller.
What you need now is a controller board such as Bitsensor BSMCEO4U-PP.

1658844596471.png

This board will take the commands from USB and relay the STEP/DIR signals to each motor driver board.

Or you can program the Arduino/ESP32 to send out the STEP/DIR signals, eliminating the need for another controller board.
 

BobTPH

Joined Jun 5, 2013
5,762
2. I don't know how to avoid conflicts between the required serial communication between the USB serial communication between the ESP32 and computer, and the serial communication between the servos and the ESP32. I am considering software serial but I am unfamiliar with that.
Doesn’t the chip have more than one UART?
 

MrChips

Joined Oct 2, 2009
27,122
You can bus UART signals but in order to do that you need to be able to disable all slave transmitters.
You can also use RS-485 transceivers and use half-duplex communication.
 

Thread Starter

-live wire-

Joined Dec 22, 2017
956
Thanks for the drawing. That is a good start and it helps a lot.
Now you need to focus on the Arduino or ESP32 box an show in more detail how the PC, servos, stepper motors, sensors are connected. Since there are multiple units you need to show how each is connected, i.e. with bused signals or separate signals.

I see in your photograph that you are using DM542-style motor drivers or similar. These are controlled by separate STEP and DIR signals for each controller... Or you can program the Arduino/ESP32 to send out the STEP/DIR signals, eliminating the need for another controller board.
the ESP32 I am using is currently programmed to send out the STEP/DIR signals to the stepper motors. And yes that is roughly what the stepper motor controller I am using looks like, its the TB6600 or a TB6600 clone.

I basically want the ESP32 to send out the raw signals and take in the raw signals for motors and sensors. However, the ESP32 should get the motor position commands from the computer over serial, and should send back any sensor information over serial with the computer as well. the computer is gonna do the harder processing to figure out what those motor movements should be to accomplish different tasks.

The ESP32 is connected to the PC with one USB cable, and all of the motors and motor controllers and other hardware pins are connected to the ESP32. Here is how it is connected
1658863625287.png


You can bus UART signals but in order to do that you need to be able to disable all slave transmitters.
You can also use RS-485 transceivers and use half-duplex communication.
There is only one data wire coming out of the servo so it has to be half duplex right? Also I am not sure what those tranceivers are and would have to learn how they work and how to use them.

Doesn’t the chip have more than one UART?
that sounds like what I need to do but im not exactly sure how to do it. cause before I was using the TX0 pin of the ESP32 but I think it only has one TX pin. this is the link to the ESP32 I am using and here is a picture of the available GPIO 1658863554814.png


Let me know if theres anything else I should clarify here.
 

MrChips

Joined Oct 2, 2009
27,122
I am just starting to get the picture of what is going on.
Here is what I see or anticipate on what should happen.

PC ←→ ESP32 connected via USB
ESP32 → TB6600 digital output STEP + DIR for each motor
ESP32 ← Limit switch digital input for each sensor

So what else am I missing?
Why do you need multiple UARTs?

Edit: You need to interface the servos with serial communications? Post info and links to the servos.
 

Thread Starter

-live wire-

Joined Dec 22, 2017
956
I am just starting to get the picture of what is going on.
Here is what I see or anticipate on what should happen.

PC ←→ ESP32 connected via USB
ESP32 → TB6600 digital output STEP + DIR for each motor
ESP32 ← Limit switch digital input for each sensor

So what else am I missing?
Why do you need multiple UARTs?

Edit: You need to interface the servos with serial communications? Post info and links to the servos.
The first part is all correct although I also need:
ESP32 ←→ 4x bus servos (link to product) (link to manufacturer provided documentation)
 

BobTPH

Joined Jun 5, 2013
5,762
I don’t know about ESP32 but even very small PICs have 2 UARTs. Some PICs have remapable I/O pins, so pins are not labeled as RXn or TXn, you map each UART to one of many possible GPIO pins.

@MrChips , I think perhaps the USB is through a USB to serial chip, so it needs a UART on the microcontroller.
 

Ya’akov

Joined Jan 27, 2019
6,561
The ESP32 is not a good choice for your application. You should choose an MCU that has more than one UART and you don't need the WiFi.

Something like the Teensy line is probably a good choice.
 

Thread Starter

-live wire-

Joined Dec 22, 2017
956
The ESP32 is not a good choice for your application. You should choose an MCU that has more than one UART and you don't need the WiFi.

Something like the Teensy line is probably a good choice.
I have an arduino mega on hand which I think has multiple RX/TX pins but i wanna run a high baud rate and the microcontroller has to do a fair bit of string parsing and i want it to still be fast when its doing that and idk how well an arduino mega could handle that. it seems like software serial with an ESP32 would be better with how much faster it is.
 

Thread Starter

-live wire-

Joined Dec 22, 2017
956
Hmm ok looking at the teensy 4.1, it seems to have a bunch of serial stuff, a faster clock speed, and more memory. I think I will go with the teensy 4.1, I am ordering it now.
 

Ya’akov

Joined Jan 27, 2019
6,561
Hmm ok looking at the teensy 4.1, it seems to have a bunch of serial stuff, a faster clock speed, and more memory. I think I will go with the teensy 4.1, I am ordering it now.
That is a very capable board. The boards are well supported in the Arduino IDE but you need to download a fork of the IDE from them (which will work with everything else too). That 4.1 can do some pretty amazing stuff. The CPU is good enough that in theory you don't need your desktop if you work out how to do the interface you want on it.
 

BobTPH

Joined Jun 5, 2013
5,762
From the ESP32 datasheet linked to from the board you are using:
ESP32 has three UART interfaces, i.e., UART0, UART1, and UART2, which provide asynchronous communication (RS232 and RS485) and IrDA support, communicating at a speed of up to 5 Mbps. UART provides hardware management of the CTS and RTS signals and software flow control (XON and XOFF). All of the interfaces can be accessed by the DMA controller or directly by the CPU.
 

Thread Starter

-live wire-

Joined Dec 22, 2017
956
From the ESP32 datasheet linked to from the board you are using:
ESP32 has three UART interfaces, i.e., UART0, UART1, and UART2, which provide asynchronous communication (RS232 and RS485) and IrDA support, communicating at a speed of up to 5 Mbps. UART provides hardware management of the CTS and RTS signals and software flow control (XON and XOFF). All of the interfaces can be accessed by the DMA controller or directly by the CPU.
Wait actually I'm not gonna click order on the teensy 4.1 yet even tho its really good, cause it sounds like the ESP32 could work.

I don't really understand the code or how I would make sure it uses UART1 or UART2 for the servos, since UART0 is being used by the USB to PC. If someone could explain that to me I would really appreciate it!

That is a very capable board. The boards are well supported in the Arduino IDE but you need to download a fork of the IDE from them (which will work with everything else too). That 4.1 can do some pretty amazing stuff. The CPU is good enough that in theory you don't need your desktop if you work out how to do the interface you want on it.
Later, I wanna do some image processing and ROS stuff that really has to be done on a desktop PC. But I still need a fast microcontroller to interface with the hardware and talk to the PC over USB
 

Ya’akov

Joined Jan 27, 2019
6,561
From the ESP32 datasheet linked to from the board you are using:
Most ESP variations have more than one UART but they also have WiFi and BT which take up the CPU on the second core and it is not needed in this case. The ESP32 is a really nice MCU if you need wireless, for sure. If you are doing serial communications other boards like the Teensys are more suited.
 

Ya’akov

Joined Jan 27, 2019
6,561
Wait actually I'm not gonna click order on the teensy 4.1 yet even tho its really good, cause it sounds like the ESP32 could work.

I don't really understand the code or how I would make sure it uses UART1 or UART2 for the servos, since UART0 is being used by the USB to PC. If someone could explain that to me I would really appreciate it!



Later, I wanna do some image processing and ROS stuff that really has to be done on a desktop PC. But I still need a fast microcontroller to interface with the hardware and talk to the PC over USB
You are going to need to use a state machine to use the UARTs at the same time. It can certainly be done, and I think the ESP32 you have will do it fine, even better if you work out how to use the second core.
 

Thread Starter

-live wire-

Joined Dec 22, 2017
956
You are going to need to use a state machine to use the UARTs at the same time. It can certainly be done, and I think the ESP32 you have will do it fine, even better if you work out how to use the second core.
Can I just use software serial for the servos?
 
Top