# How to interface UART servo? (LX-224HV)

I am trying to interface a RaspberryPi (2B) GPIO-UART to the this serial servo (Hiwonder LX-224HV), as a first step before to switch the Raspberry by an ARM MCU (STM32F407ZE on custom circuit).

The servo is supposed to follow a simple protocol, however, I am unable to manage any response from the servo (neither movement or UART response).

The documentation I found about the servo is limited (Note that this is another servo model, but according to vendor, their controller is compatible with both, consequently, I assume some compatibility):

Testing signal:

For testing purpose, I am sending the following message through command line:

#Some ports initialization here
echo "0" > /sys/class/gpio/gpio24/value # disable rx
echo "1" > /sys/class/gpio/gpio23/value # enable dx
echo -n -e "\x55\x55\xfe\x04\x0e\x01\xee" > /dev/ttyAMA0; sleep 0.001;
echo "0" > /sys/class/gpio/gpio23/value # enable dx
echo "1" > /sys/class/gpio/gpio24/value # disable rx


• 0x55 0x55: transmission start tag.
• 0xFE: Id of the target servo, 254 means broadcast
• 0x04: Length of the block, including this length to ending checksum
• 0x01: default Id (not used?)
• 0xEE: Checksum ~(254+4+14+1) = ~(17) = 238

The circuit is set as follow:

simulate this circuit – Schematic created using CircuitLab

Note, I added a resistor to avoid burning any component in case of short-cut, It also allows to see variations in the signal if the servo tries to send any data.

The connection to the servo is done as follow:

• 0-5V to signal, high impedance most of the time.
• 12V to the VDD
• 0V to the GND

The result signal:

The resulting signal at the signal pin of the servo-motor is as follow:

There is no significant signal after this, which I interpret as the servo not responding for any reason.

The question:

Is there any obvious missing element in this approach? or ultimately, how to interface with this servo?

I found many others servos with similar interface, so I believe this could help further users..

• Note: I also tried other types of messages (rotate), without more success Aug 28, 2020 at 15:20
• I think the following document is more helpful: dropbox.com/sh/b3v81sb9nwir16q/AADXOwhdw7KLq5t5UM8ND3kwa/… Thank you Aug 28, 2020 at 15:28
• Multidrop serial on a bidirectional line is a quite normal thing; let's please address the actual issue of the question not unfamiliarity with the concept. Some things to check would be that the baud rate is correctly set, that the device expects these voltage levels and this inversion sense (vs any of the RSxxx standards which would be opposite sense and possibly higher voltage), that the device address is correct, and that the transmit word is getting completely clocked out before the driver is disabled. Consider probing both sides of that series resistor... Aug 29, 2020 at 0:33
• @Adrian Maire, Good morning. The docs in your drop boxed are very good and comprehensive. So I google and learned many more things I didn't expect to know. Questions: (1) *Have you bought the LX-244 offline controller/tester? I am drafting a shopping list, including the offline controller. You might like to comment on my incomplete answer, or brainstorming me counter suggestions. Cheers. Aug 29, 2020 at 4:20
• (1) I did not bought the controller/tester board initially because I did not expected this to be so difficult, however considering the current situation, I did bough one yesterday which should arrive in some 1-2months. (2) Yes, the baud-rate is set to the expected frequency (excepting any error from my part). (3) the device address should be correct, as I am using broadcast. (4) The word is getting completely clocked out before the driver is disabled: Checked. (5) Voltages and levels: you see the wave from the oscilloscope, but I can't ensure anything more. Aug 29, 2020 at 10:49

After some time researching the topic together @tlfong01 and me(@adrian_maire), we managed to get the servo working through the Raspberry Pi (from now: RPI) without the need of the driver board.

For this purpose, several problems has been solved:

1. Converting voltage level from 3.3V (RPI) to 5V (servo bus)
2. Implementing the different UART messages for the RPI
3. Converting full-duplex UART to half-duplex UART

Converting voltage level from 3.3V to 5V

Even if this could be a sub-optimal solution, considering that the 74HC126D allows level conversion, two of them has been used to manage both problems: enabling and disabling of Tx/Rx and level conversion at the same time.

simulate this circuit – Schematic created using CircuitLab

Implementing the different UART messages for the RPI

A project has been created (GPL3) to any of you to use it.

https://github.com/Escain/HiwonderRPI

(The code is unfortunately too large to include here.)

Converting full-duplex UART to half-duplex UART

For the conversion of full-duplex to half-duplex UART, the servo relay on the enabling and disabling of the full-duplex TX (transmission) and RX (reception) line:

• When RPI transmit, it enable TX and disable RX
• When RPI don't transmit, it disable TX and enable RX so the servo can answer.

The servo start answering UART request some 0.1ms after reception, this is below the OS scheduling time of any modern operating system, including Raspian. In consequence the first attempt to drive en-TX and en-RX by software was totally unsuccessful.

To solve this issue, the en-TX is implemented by hardware, through a retriggering monostate 555 timer of around 0.1 ms. The en-RX is just the negation of en-TX.

simulate this circuit

Connecting all together:

1. Tx is connected to the RPI GPIO 14
2. Rx is connected to the RPI GPIO 15
3. enTx from both circuits are connected together
4. Servo S is connected to the signal of the servo
5. Gnd and VCC (3.3V, 5V and 9V) are connected to the circuits and to the servo. (This servo is HV and thus, support up to 12V, but others Hiwonver servos can NOT manage 12V, be careful).

Question

How can Rpi4B talk to duplex BUS UART servo LX-224HV?

Part B - Rpi4B UART to LX-224HV Simplex Serial Ciruit Design V0.1

Next step is to let Rpi to send commands to LX-224 and see if is replies back anything. The OP reports nothing comes back. So I will repeat his commands and see if I have better luck.

The Op is sending the following commands. I think I better read the servo command manual to make sure the commands are OK and will not fry the servo.

0x55 0x55: transmission start tag.

0xFE: Id of the target servo, 254 means broadcast

0x04: Length of the block, including this length to ending checksum

0x01: default Id (not used?)

0xEE: Checksum ~(254+4+14+1) = ~(17) = 238


Part A - LX224HX Troubleshooting Using BusLink V2.4

I am using the HiWonder Bus Linker V2.4 to display the send receive signals when the LX-224 UART/Bus servo is set to motor mode and move continuously at about 700 rpm.

References

/ to continue, ...

Appendices

Appendix A - The OP's test setup

Appendix B - HiWonder LX-224 BusServoController setup

Appendix C - HiWonder LX-224 BusLink V2.4 Setup

Appendix D - TSX0104 Level Shifter for implementing LX224 Simplex UART/BUS Servo Bidirectional Control

/ to continue, ...

Not yet completed answer. Stay tuned, ...

• Hello @tlfong01, thanks you for your great research :-) Looking at your oscilloscope output, it does not resemble to any of the message that I have in the documentation. My initial conclusion is that the protocol explained is either wrong or has been significantly changed. It would be interesting to have more samples of communication to reverse-engineer the protocol. The on of your picture is probably about querying the temperature/voltage or position. Sep 2, 2020 at 9:26
• Ah, I see. But I am not surprised, because I am using the Win10 Bus Servo Terminal GUI command to turn the motor non stop so I can easily us a scope to display something. There are other things that cause trouble: (1) I am using BusLink version 2.6, but I read the AliExpress and Amazon are selling old versions. So there might be outdated commands. The other thing is that I found HiWonder keeps saying that they cannot help users to develop software, because HiWonder is asking LeWanSoul to develop the LeWanSoul simplex uart servo protocol. So LeWanSoul might not the have motor turning commands. Sep 2, 2020 at 9:38
• Ah, supper time, so see you late this evening or tomorrow. Cheers. Sep 2, 2020 at 9:39
• In your circuit, I suggest you to add the pull-up resistor and also some 0.5k in-serie resistor between the bus and the servo. This will avoid any error to burn to quickly your devices. Sep 2, 2020 at 9:40
• Ah that is a good advice I carelessly forgot . I usually use 330R or 470R series resistor to limit the motor current. I am also using a very small 220VAc to 12VDC 1A (yes, 1A only) PSU then step down to LM2596 12V to 5V to supply the LX-224. So I think LX-224 should at most take 1A or a bit more, hopefully no to fry anything. And also that is why I am using the less expensive servo, not the most expensive one, just in case, ... Cheers Sep 2, 2020 at 9:47