Uncategorized

LX-224HV Servo notes

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

tlfong01Question How can Rpi4B talk to duplex BUS UART servo LX-224HV? Answer 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 …Adrian Maire13.2kHello @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. tlfong013983Ah, 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.Ah, supper time, so see you late this evening or tomorrow. Cheers. Adrian MaireIn 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. tlfong013983Ah 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 Adrian MaireI created this room (chat.stackexchange.com/rooms/112557/lx-224hv-uart-interface‌​) so we don’t load this Q&A page too much with unrelated/unfinished content. At the end we can add the working result here just for future users. tlfong013983Sep 3, 10:38Ah, a very good idea. Now I can be more casual thinking aloud, brainstorming crazy ideas that often later turned out wrong, because I am now trying out things in the area I have no experience at all. I only heard about the idea of “simplex” when playing with walkie talkie, and I never heard of the term UART/Bus Servo (As I confessed, all my life I have been playing only with toy PWM servos TowerPro MG995/6 and SG90) .  1 hour later… tlfong013983Sep 3, 11:55update 2020sep03hkt1155Now I am assenbing a TXS0102 for experimenting with the LX-224HV simplex circuit. I actually have a couple of already assembled TXS/TXB01 02/03/06/08 in hand, but I want a semi permanent test bench version to keep a record.

user image

As usual, comments are counter suggestions are always welcome, especially before I fry something. Ah, you remind me one good thing about chatting in the chat room is that I can easy insert pictures.  1 day later… Adrian Maire13.2kSep 4, 17:02To be honest, it is also the first time for me playing with the UART servo. So experimenting too.Beautiful PCB! Is it a customized PCB that you designed/ordered?On my side, I still have to try reproduce the signal of your oscilloscope and see if the servo is going to answer or not. Also waiting for the little controller, but this will take some time.  5 hours later… tlfong013983Sep 4, 22:24(1) HiWonder seems to have a 2020 cheaper model LX-20S. Did you see this when you ordered yours last time? This model has only one axis, but I think it is more affordable to fry, or for a project with many servos.The TXS0102 module is from a TaoBao shop. I remember that they delayed my small order of 20 pieces, because they need to make large quantities for Singapore. Singapore has a reputation of making high quality products (sometimes military grade). So I think they require good quality TXS0102 too. Before that I tried different cheap versions of TXS0102/04/06/08 but found them problematic. So this time I am wiring a new one on bread board to do a more rigorous test.I am thinking of testing LX-224 UART commands this weekend. I think I don’t need to use Rpi python. A lazy way is to use Win10 RealTerm terminal emulator to send and receive commands to LX-224. I hjave been searching for an updated version of LeWanSoul command list. But I could not find one. This might be bad news, becasue they might have abandoned the project during LX-16.Therefore not more updated command list. If my test this weekend is smooth, perhaps I can use python to create new commands such as turning 306 degrees. Ah bed time. See you over the weekend. Cheers.  18 hours later… Adrian Maire13.2kSep 5, 16:26Hello 🙂
I have been making some tests and I have good news.Reading and testing about UART, it transmit 10bits for each (8bit) byte of data: First it transmit a “10” and then the data.
Also, it transmit first the less significant bits and after the most.

Example: x05 will be transmitted as 10-10100000With this in mind, the screenshot of your oscilloscope transmit following to the servo:

10-10101010 10-10101010 10-10000000 10-11000000 10-11011000 10-00000111

In numbers:

x55 x55 x01 x03 x1B xE0

Adding semantic:

0x55 0x55 (initial tag)
0x01: Servo ID (1)
0x03: Size of the data (by the doc, this includes from the size to the check-sum)
0x1B: Read Input voltage request
0xE0: checksum = ~(id+length+params) = ~(0x01+0x03+0x1B) = ~(0x1F) = 0xE0Then I tried to send those values through the RaspberryPi, and the oscilloscope give me the exact signal you shown.
However the servo is still not responding, so I am wondering the following issues:
– The servo has burn, due to any mistake during the test.
– The servo expect 12V signal (HV version). I expect the signal to be 5V even if the input voltage is 12V. Trying 12V bus imply burning the servo in case it expect 5V.
– Any other error in the electronic (?)  11 hours later… Adrian Maire13.2kSun 4:07When you have a moment, could I ask you try to connect higher voltage to the board?

1) Disconnect the servo (as it is not HV)
2) Connect a higher source to the board, e.g. 8V should not be a risk for the board
3) Send some signal (rotate or what-ever).

4) See if the signal is 5V or 8V? tlfong013983Ah, the following three things you found out is very important, should save me a lot of time doing trials and errors: (1) Reading and testing about UART, it transmit 10bits for each (8bit) byte of data: (2) First it transmit a “10” and then the data.
(3) Also, it transmit first the less significant bits and after the most. But I don’t seem to find this protocol in the LewanSoul command user guide. I need to read the guide one more time and update my summary shown below。

user image

I am also considering the test command strings I should try use first. I found you use of the broadcast address 0xfe a bit confusing. I need to think again to see 0xfe is a good address to test. I am studying the following to get to know more.

user image

I think the simplest commands I might try first is 0x26, 0x27, and 0x28, (1) Read Temperature, (2) Read Vcc, and (3) Read Position (I can move the servo by hand and see if Position changes). tlfong013983For your suggestion on testing the offline tester board, let me make some comments first.(1) The BusLinker V2.4 is for old version LX-16A, so it says Vin = 6V ~ 8.4V, so there should be no problem if I set Vin to 8V and send a rotate commend. I will do that later, but as you have guessed, the logic output should be 5V. Anyway, I will try that and let you know if your guess if correct.You said my screen capture is “x55 x55 x01 x03 x1B xE0”. I need to read the command table to see what this means, but I will also try to use my terminal emulator Win10 RealTerm, or RpiCuteCom, or Rpi python to send this string, and also your decoded command “10-10101010 10-10101010 10-10000000 10-11000000 10-11011000 10-00000111” and see what happens. I will also try read temperature, Vin, and Pos as I suggested earlier.Ah, bed time. Call it a day. See you tomorrow. Cheers.You said perhaps the following: “The servo expect 12V signal (HV version)”. I think this is very unlikely, but I will, as you suggest, try Vin = 8V and see what happens. Anyway, will carry on tomorrow. Cheers. Adrian MaireSun 23:35I need to read the command table to see what this means,

I did that already, just read my previous comment, it explains each bytes 🙂  14 hours later… tlfong013983Mon 13:10Yes, I saw that you explained each byes of my bus link rotate motor screen capture. But I don’t understand why my “Rotate Motor” string becomes your “Read Voltage Input Request”?

user image

  2 hours later… Adrian Maire13.2kMon 14:53>But I don’t understand why my “Rotate Motor” string becomes your “Read Voltage Input Request”?

IMO, When you use the software (Hiwonder windows UI), it request periodically temperature/voltage/position to the servo, to display them in the screen. The “rotate” directive is probably sent before.Te more clear: I think that out of the many communications that happens between the servo and Hiwonder software, you made zoom on the one which request voltage input.  1 hour later… tlfong013983Mon 16:13Ah, yes, actually that is what I have just done before I saw your message. (1) I did also suspect the Bus Servo Terminal does repeatedly request Vin, Temp, Pos. In other words, there is no need to rotate the motor in order to display waveform on the scope. (2) So this time I set to servo mode, and adjust position to around 735 and watching the scope.(3) I found scope shows repeated waveforms every 350 ms, roughly in two parts. (4) I always find it difficult to read the bits and bytes, perhaps you can help out and translate the bits into bytes.

user image

user image

user image

user image

user image

Notes – (a) I did try to change Vin from 6V to 8V and found no change in the amplitude of the 5V UART waveform, so I guess Vin is solely for powering the motor, and has nothing to do with the UART stuff. (b) I also guess, the BusLinker is for LX-16A which is not HV and only work to 7.2V. But the servo LX-824HV should work to 11.1V, so I increase Vin to 10.0V and found every body happy to work as usual, for at least about 15 minutes without any smoke coming out.Now about the 10bit command string. I guess the initial “10-” before the “0x55 0x55” string is just to “wake up” the servo, and is not part of the command string, which only starts with 0x55, 0x55. So If I am going to use a terminal emulator, or later a python program, I can forget the “10-” part and just start a commend with 0x55, 0x55. I have not yet decided not to do next. Comments and suggestions welcome.Please also feel free to ask me to try other things you like. Ah, jogging time. See you late this evening or tomorrow. Cheers. Adrian Maire13.2kMon 16:54I am currently at work, so I will translate the screenshots later.
Thank you very much for testing 8V and 10V and confirming that the UART signal is always 5V. With this, I can discard the issue of voltage and try others ideas.
Considering the “10”: it is nothing about the servo itself, but about UART protocol in general. Reading a bit more about the subject: UART send a “0” before each bytes and a “1” after each byte (so we see the “10” between them). This is used to synchronize clocks in the serial communication. you don’t need to add them to the string, it is automatically done by the UART chip. However, when we read with the oscilloscope, it is apparent and we need to consider it.  6 hours later… tlfong013983Mon 23:06(removed)Now I have set up and tested the following hardware and software to prepare testing sending commands to servo to request temperature.(1) Set up PC Win10 USB to UART adapter baud rate 115200bd.(2) Setup Win10 RealTerm and test loopback (hex) numbers(3) Setup TXS0104 3V3 to 5V0 logical level shifter.(4) Test loop back with 5V0 TxD shorted to RxD

user image

user image

user image

user image

Test plan tomorrow. Tomorrow will test the real thing:(1) Short 5V0 TxD to RxD(2) Connect shorted TxD/RxD to signal terminal of LX-824HV(3) Send command request for temperature(4) If all goes well, LX-824HC should return temperature.Bed time, call it a day, carry on tomorrow.  13 hours later… tlfong013983Tue 12:44You said the following: “However the servo is still not responding, so I am wondering the following issues: The servo has burn, due to any mistake during the test.
(1) Servo expect 12V signal (HV version). I expect the signal to be 5V even if the input voltage is 12V. Trying 12V bus imply burning the servo in case it expect 5V.
(2) Any other error in the electronic (?)(1) If you once used 12V UART signal, it is very likely the servo is fried.(2) You did not mention where did you buy the servo. If it is from eBay or other not that reliable shops, then you might get a fake model, or “damaged and returned to shop” thing. I noticed that there are many shops in CN selling LX-224HV, to newbies and schools.It is likely that those newbies do not know how to properly handle the HV toy and fired it and return it. Some bad guys might just sell the damaged toys on eBay. That is one of the reasons I posted detailed info of the toy I ordered. I found that in CN there are a couple of flagship or big authorized or seemingly authorized shop.One of the big shops has the following note in their ad: “We Accept Returned Goods“, that means they accept used toys, usually paying a low fee, to any used toys, damaged or good, without asking any question. Then they may resell it to bad eBay guys, …  3 hours later… Adrian Maire13.2kTue 16:04If you onace used 12V UART signal, it is very likely the servo is fried.
I did not, that is why I asked you to test the signal voltage first. 🙂You did not mention where did you buy the servo.
Here, we have not that many choices where to buy them. I got it on Alibaba, and usually what I get there works fine. Any way, I should receive the controller soon, so I will let you know if it works with it.
Also, eBay is not that evil: you can be cheated (ofc), but usually (and if you are a bit careful) you get correct stuff. I had never issues with eBay in my case.Yesterday, I wrote a small C++ code to send the UART signal and activate/deactivate writing mode. (using WiringPi lib). It works mostly, but I have issues synchronizing UART and the “writing” pin, because UART is buffered: I activate “writing” then send the signal to UART, and finally deactivate “writing”, but that way the UART signal finish after the “writing” is disabled. I tried with some timers, but in the micro-seconds, those don’t work reliably. I am thinking how to implement that by hardware.

(Mental note: why the hell they did not implemented 4-wires standard UART!!! )  1 day later… tlfong013983Wed 22:31(1) I agree eBay is not always evil, but I think eBay’s quality control is not as good as Amazon or AliExpress. Actually I was once a member of AliBaBa, but I later opened an account in AliPay and TaoBao, which belongs to Alibaba. (2) I think I understand what your C++ code is trying to do, but I think it is tedious.(3) I read the BusLink doc saying that its UART connector can be used by MCU to talk to servo, but I am not sure if you must use Win10 and install driver for that.(4) I found Win10 RealTerm hard to handle, and I need to reset every now and then. Now I have decided to switch to Rpi4B CutCom which is simpler than RealTerm, and CuteCom is easier to convert to Thonny python. But I have only 50% confidence that my TXS0102/04 can replace the BusLink. Will take me a couple more days to find out. Cheers. tlfong01Wed 22:51Just now I googled and find a python library for BusLink Terminal on Python. In other words no more using Windows. If your HC126 adapter is almost identical to BusLink Terminal, perhaps you can also try this python LeWanSoul LX-16A library. For now I will still carry on my TXS0104 setup. Adrian Maire13.2kHi tlfong01 🙂
I finally got the controller board from Aliexpress, so I could try the different servos. As a note, the HV version is also moving with 5V (much easier to avoid frying the servo).I managed to do the C++ code, but unfortunately, I can’t manage to reliably disable TX on time. The problem is that the OS timers and scheduling is on the 10ms range, while this communication happens in the 0.1ms.. This makes impossible to control enTX and TX by software on any modern OS.

user image

If you test it, you will see that the enTX will be disabled after last bit of the UART, but with significant JiterWhat to do now?
1) I will try to use the 5V TX RX GND of the board to control the servo from the RPI.
2) Revert-engineer the board if possible.
Depending on result… we will see.  14 hours later… tlfong013983Thu 12:46Well, if wiringPi and wiringSerial’s operation delay is of the order of 10ms, it is too slow for your HC126 enTxD circuit. As I see, there are at least two more alternatives: (1) Use level shifter to shift Rpi’s TxD, RxD to 5V and use the plain HC126 cct or BusLink Terminal Board to talk to servo, (2) My suggested TXS0102/04 level shifting and auto direction control two-in-one solution. WARNING – I have not yet tested it. I think I have only 50% chance winning. 🙂BTW, I have skimmed the following: maximkulkin Enable standalone mode for terminal app (lewansoul_lx16a_terminal.py, 695 lines) – Maxim Kulkin (maximkulkin), GitHub 2019feb27
github.com/maximkulkin/…The python library by Maxim Kulkin is well documented, but I am not interested to over simplify the 625 lines long python code to start my preliminary testing. I will just first try it in CuteCom, and then use Thonny python to test the very basic commands, (1) Read Position, (2) Read Temperature, and (3) Read Vin.  2 hours later… Adrian Maire13.2kThu 15:11Hello,
So yesterday I did some more tries with the board. And I managed to control the servo from the RaspberryPI GPIO through the board.

user image

To summarize:
– The raspberryPi Tx and Rx are converted from 3.3V to 5V, and then connected to the 5V/Tx/Rx/GND pins on the board.
– I implemented some additional logic in C++ to make it rotate and request Vin.

Both: moving the servo and requesting Vin works.(I will push the c++ code as soon as possible)What now?

1) Your python approach is interesting, I am excited to see if it’s going to work.
2) On my side, I will reverse-engineer the board, to see if I can skip it. But probably your suggestion of TXS0102/04 is a good approach. tlfong013983Thu 15:32Oh my goodness. (2) This is a milestone. “I implemented some additional logic in C++ to make it rotate and request Vin”(2) Your idea of “reverse-engineer the board, to see if I can skip it.” is good. I have no idea of how difficult it is. I have the feeling that it might be very difficult, as the BuskLink Terminal App is a bit complicated, as Maxim Kulkin’s terminal + UI python code. Anyway, good luck.Now I have read the “LewanSoul Bus Servo Communication Protocol”. It is only 11 pages long, implying not too many commands to deal with. As said earlier, I will only test the read temp, vin, and pos commands. I have summarized the protocol guide, and upload here, in case you are interested to see what I am doing.

user image

user image

Adrian MaireYes, this doc has became my favorite nightstand book too 😛BTW: what software do you use to highlight PDF? it seems very convenient tlfong01Thu 15:50Ah, what do you mean by “favorite night stand”? I was about to curse that the guide seemed to be written by a nerd/geek in a hurry. Geeks usually have high IQ like the uni profs and so their ordinary IQ students find the prof’s lecture hard to follow. Adrian MaireOhh! It’s an expression here, to indicate that I have it close to me all the time and I spend lot of time on it. (Not really that I like it especially) tlfong01Ah, I used to highlight my lengthy reports to my very busy ex boss, who only has time to play golf, no time to read my rubbish. So if he is very busy, he will just read the pink sentences, and so not busy, the green stuff, and so so, read the blue stuff. Adrian MairePink/Green/Blue: convenient.I am going back to work. I wish you a good after-noon and luck with your researches 🙂 tlfong013983And I used to use these tools/procedures to convert pdf and actually all documents that can display in Windows (Yes, I am a Windows guy). (1) Display anything on the Windows screen, (2) Crop/Capture the interesting portion of screen into a JPG file, (3) Use the very powerful PhotoShop to edit the jpg image, (4) use the PhotoShop “TRANSPARENT” thing (I am using Chinese Windows, so I don’t know the “thing” in English! :)) to highlight what you want.Ah, I missed my afternoon tea! See you later.  2 hours later… tlfong01Thu 17:37Progress Report 2020sep10hkt1737 tlfong013983Thu 17:48I feel jealous that the other guy next Continent is making great progress today. So to catch up, I abandoned the Rpi CuteCom I am setting up, and went back to the not so stable Win Real Term to test the read temperature LeWanSoul command with my LX-224HV. I have already done the following before the test this time. (1) Use BusLink board to test servo can rotate, move to position, read temp, pos, and vin. (2) Adrian helped to decode the read Vin request as 0x55, 0x55, 0x01, 0x03, 0x1b, 0xe0.(3) I tested Win10 RealTerm UART loopback, with TxD shorted to RxD, at logical level 3V3 (UART adapter jumper set to 3V3), (4) I ten tested Win10 RealTerm UART loopback at logical level 5V0, using TXS0104 to do level shift up, (5) Next is the fun part: (a) I power servo with 5V, (b) set RealTerm input string to readVin, (c) send readVin without connecting the signal (TxD shorted to RxD) to servo. RealTemp output displayed the readVin string and nothing else.(d) send request again, this time, RealTerm displayed more numbers (from servo, I guess). (e) I repeated send without signal connected, and then connected to servo). The RealTerm output is displayed below.

user image

Now I need someone kindly to decode the seemingly reply from the servo, hopefully something like a Vin value of 5V. Ah, I am missing the locking down supper, will come back later this evening, … Adrian Maire13.2kThu 18:09

user image

tlfong01Thanks a lot. So I will do my always dodgy calculation after supper. Cheers. Adrian Maire13.2kx55 x55: start communication frame
x01: ID from the servo replying
x05: length of the message, including this byte and following
x1B: command: 27 is response to VIN_READ
x4E and x14: value of voltage.
x7C checksum.

continuingx14=20, x4E=78: 5198 tlfong01Ha, so the value is 0x4E14. I will ask the online hex to decimal converter for help. Adrian Maire13.2k4E is lower bits and 14 higher, so you have to reverse them: x14 x4E14=20, 4E=78, so 20*256+78 = 5198There is no description of what does that mean, but considering other parameters, it seems like mV, thus 5.198V tlfong01Ah, yes I first tried 4e14 returning some rubbish, then 144e gives 5198. I hope it means 5.198V.tks bye Adrian MaireThu 18:27>JPG
Ohh! I though you had some tool to directly highlight the PDF. Like with Okular PDF-reader  23 hours later… tlfong013983yst 17:07@AdrianMaire Ah, yes, so there are two approaches: (1) Use Okular to edit the PDF file, and then screen capture to JPG, (2) Screen capture PDF to JPG, then PhotoShop editing.Progress report 2020sep11hkt1707.Now that I found the LX-824HV LeWanSoul tests with Windows RealTerm using BusLink and TXS0104 OK, I am moving to Rpi4B and CuteCom and test the ReadVin command again. I found the test OK, with some teething problems. I am saving a record for later reference and troubleshooting. Next step is to use Thonny python to do everything, ie, no more terminal emulators RealTerm or CuteCom.

user image

tlfong013983yst 17:32

user image

Jogging time. See you later. Cheers. Adrian Maireyst 17:55Wooww! Nice testing environment  The last message was posted 16 hours ago. 

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.