LX-224HV and AX-12A servo discussion notes

Sep 9, 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.3kHi 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.3kThu 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.3kThu 18:09

user image

tlfong01Thanks a lot. So I will do my always dodgy calculation after supper. Cheers. Adrian Maire13.3kx55 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.3k4E 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… tlfong013983Fri 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

tlfong013983Fri 17:32

user image

Jogging time. See you later. Cheers. Adrian MaireFri 17:55Wooww! Nice testing environment  2 days later… tlfong013983Sun 15:11I am glad you like it. Now I have merged the two proto boards together in an all-in-one board, and then used CuteCom to readVin some twenty times, to see how accurate or reliable are the measurements.

user image

user image

tlfong013983Sun 16:00

user image

tlfong013983Sun 16:10Next step is to write a python program to repeatedly read Vin, and at the same time use a scope to display the request string from Rpi, and the reply string from servo. What I am curious to know is the response time between servo receiving request string, to servo sending the data (Vin) string. The LeWanSoul user guide says your need to be quick, but does not say how quick you should be. tlfong01Sun 16:32Earlier I tried to upload a picture but got an error message saying that the image to upload could not be found, so I tried again and again. Now there are three identical images. Please use any one you like.  20 hours later… tlfong013983Mon 12:24So now I am writing a python to analyse the timing of request/reply Vin value, to make sure of the requirement of the Enable/Disable of the simplex UART commands using HC126. Though the TXS0102/04 seems to work, but I have no confidence that the OR’ing of output TxD/RxD won’t generate other problems. As I mentioned in my (already deleted) answer, I once studied the very expensive Danamixel bus servo but could afford to play with it.Now I am googling around to see if there is any alternative comparable with LewanSoul but not too expensive, and also have a good documentation. I found the following review and now reading it.(1) Review of Three Serial Bus Servos (Robotis Dynamixel, DST Robot, and LewanSoul Lobot) – Roger Cheng, Hackaday, 2018jul05
hackaday.com/2018/07/05/…. Cheers.One problem with the Chat Room here is that I am too slow to write a message. Usually I need more than 3 minutes to write and proofread. But my messages become “permanent” and I could no longer correct any spelling or SEMANTIC ERRORS later. This might cause big confusion to future readers.One workaround is for me to from time to time update my answer, after a milestone in our project, and also warning the future readers that ours is an exploratory project, and that many things discussed in the chat room is simply wrong if not misleading. But of course the future reading can skimmed through our chat record and understand why we did it this way or that way, after WE MADE MISTAKES. In short, we learn by making mistakes and correct them.  4 hours later… tlfong013983Mon 16:46Now I have completed the python program to read LX-824HV’s Vin value. The program logic is a bit complicated, so I have written a summary for it.

user image

You might like to comment or make counter suggestion for my python program logic. If the test is successful, I will then tidy up and document the program and upload the complete listing here. But there is nothing urgent. So I will slow down now. Cheers.PS – I might goggle further on serial bus servo. The article I mentioned above is two years old, and it appears that there has not been too much progress in the area. Some 5 years ago I read about the “Open Digital Servo” proposed by SparkFun, but I sadly heard that it was a failure. I guess for now the expensive DynaMixal and cheap HiWonder are still the two serial bus servos that worth our time to invest.  7 hours later… Adrian Maire13.3kMon 23:31“but does not say how quick you should be.”
From the tests I did, I found it is much less than 1ms, I remember something slightly longer than the transmission of a byte by the UART (0.5ms – 1ms), from the last sent bit to the start of the servo reply.“This might cause big confusion to future readers.”
Nobody expect the chat to be a precise document. (IMO) is fine to have typos, and errors. (I am not even sure many people will read this)On my side, I continued to play a bit with the servos, and also trying to solve the enTX/enRx pin (like you).
Here is a question that I posted about it: stackoverflow.com/questions/…
One of the comments is interesting, I still need to test it.  11 hours later… tlfong013983yst 10:25Ah, this is useful to me: “From the tests I did, I found it is much less than 1ms“.Yes, I agree with the following: “Nobody expect the chat to be a precise document. (IMO) is fine to have typos, and errors, (I am not even sure many people will read this)”And now I think that readers following this chat should automatically filter the typos as he read along. As I said earlier, I might try to make a summary after each milestone, and also brief project report on completion of project.BTW, I googled further but still have not found useful to guide me where to go next on serial bus servos. This is another abandoned project: GigaBrain Dynamixel and LX-16A Project – rpi.org.forums 2018sep19
raspberrypi.org/forums/…I am also updating my knowledge on logical level shifters. Here is an updated of the catalogs: (1) Logical Level Shifter Catalog – AdaFruit

(2) Logic Level Converter Catalog – SparkFun
sparkfun.com/categories/361It is too late for me to update (2) to following: (2) Logic Level Converter Catalog – SparkFun (***I always forgot that opto-isolaters are also level shifters***)
sparkfun.com/categories/361  5 hours later… tlfong013983yst 16:03Yes, my test confirms your much less than 1ms is about 200us

user image

The output has a little problem. The TXS0104’s 10k Or’ed 10k (Or’ed with LX-827 input) seems not strong enough, with the result the output could not be pulled down to a clear cut zero. I tried to parallel 4k7 to make the pull up stronger, but it seems not making any difference. Anyway, Rpi at the 3V3 side seeem to read the data OK.

user image

I forgot to give a title to the above scope screen capture.

user image

I also now understand why you said that each LewanSoul byte is 10 bits, beginning with “10”. More precisely, the beginning “10” should be “stop bit/idle high bit/level (“1”) and “start bit” (“0”).Anyway, the TXS0104 circuit seems working, though not perfectly. So I will move on to tidy up my quick and dirty python program and show a complete listing here, perhaps some time after afternoon tea/jogging/supper. Cheers.  5 hours later… tlfong013983yst 21:26I forgot that the TXS0204 5V side TxD ORed with RxD and LX-824 is shifted down to 3V3 and at 3V3 side RxD read by Rpi is between 1V (Low) and 3.2V (High) and therefore acceptable to Rpi.

user image

tlfong013983yst 21:47And this is the complete listing of the program to test the TXS0104 LX-824TV interface circuit.

# srv_util_01_v153.py
# LX-824HV Testing v1.0  tlfong01 2020sep15hkt2133

# Contents

# Serial UART LoopBack Program v0.62 (Minimal)
# Serial UART LoopBack Program v0.98 (Multiple ports USB and on board UYART Ports)
# HiWonder serial bus servo LX-824HV LewanSoul command testing (2020sep15)

# Serial UART LoopBack Program v0.99 - https://penzu.com/p/f2cb232e
# serial_loopback_test_v062.py tlfong01 2020jun03hkt1447
# Rpi4B buster (r2020feb13), python 3.7.3 (r2019dec20), thonny v3.2.7 (r2020jan22)

(see full text)The above program follows the recommendation style of StackOverflow – MCVE (Minimal, Comprehensive, Verifiable Example). Or CPR (Copy-Paste-Run) No external library is required to run it.  1 hour later… tlfong013983yst 23:14I am going to write some more python programs to control the LewanSoul serial bus servo. I google a couple of forums and found quite a lot of discussions on Dynamixel and almost nothing on LewanSoul servos.Luckily we have the following two references: (1) LewanSoul Bus Servo Communication Protocol User Guide. (2) lewansoul_lx16a_terminal.py, Maxim Kulkin (maximkulkin), GitHub 2019feb27. One bad thing is that all things I found are based on LX-16A, nothing about LX-224HV and LX-824HV. Anyway, I think we have enough references to move on.I found the following two EE SE forum discussions on serial bus servo Dynamixel, but I found them not very useful. (3) Single wire two-way serial communication – hardware configuration (Dynamixel XL-320)- EESE 2015aug05

(4) How can I make a half-duplex UART to TTL converter for communicating to a servo (Dynamixel AX-12A) with a HC04 and a HC126? – EESE 2020jul20
electronics.stackexchange.com/…(see full text)  12 hours later… tlfong01398310:56I am using the following Arduino libraries for reference in writing my python code. This is the most up to date LewanSoul code based on LX-16A. Ihave given up searching for more updated libraries for LX-224HV and LX-824HV.LX-16A Arduino Libraries – Eicken & Harrington 2020aug14
arduinolibraries.info/…I found the LX-16A functions in the Arduino library a bit simple and straightforward. So I am now thinking of writing all python functions from scratch. I think if you are writing C++ coode for Cortex M4, you should find this C++ code a good reference.This is an example of the Arduino code for reading Vin of LX-16A

user image

tlfong01398311:24I also found tons of user guides and tutorials for Dynamixel AX-12A. Here is an example for newbies to get started.
wiki.ros.org/…So though I have given up searching further for LX-16A/LX-224HV/LX824HV resources, I can easily find Dynamixel equivalents. One day when I get to know enough with Dynamixel servo, I will consider getting a couple of Dynamixel to play with.Or start DIYing my LX-224HV or AX-12A robot arm: wiki.ros.org/…. Cheers. tlfong01398311:53Earlier I cursed the lousy, badly written LewanSoul user guide. One reason is that the description and terms are very confusing. For example, the user guides says (a) there are two kinds of packets: Read and Write, And that both controller and servo sends “commands”. Saying that servo sends commands is very misleading, because they are “slaves”.I found Dynamixel tutorial on protocol very clear and newbie friendly: Dynamixel Protocol User Guide – Robotis

I am now using a modified form of Dynamixel for my python programming as summarized below:(1) Controller (eg. Arduino, Rpi) and serial bus servo (eg. AX12A, LX-224HV) communicate each other by sending and receiving data called Packet.

(2) There are two kinds of packets:

(a) Instruction (Control) Packet, which Main Controller sends to control (request status/data of) servo, and

(b) Status (Return/Reply) Packet, which servo replies/responses to Controller. 

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 )

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.