bus servo chat record

Sep 8, 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.3kSep 8, 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.(see full text)  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.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… tlfong013983yst 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… tlfong013983yst 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.3kyst 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… tlfong01398310: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… tlfong01398316: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… tlfong01398321: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

tlfong01398321: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)

from   time import sleep
import serial

serialPort0 = serial.Serial(port = '/dev/serial0',
        baudrate = 9600,
        parity = serial.PARITY_NONE,
        stopbits = serial.STOPBITS_ONE,
        bytesize = serial.EIGHTBITS,
        timeout= 1)

def setSerialPortBaudRate(serialPort, baudrate):
    print('   Begin setSerialPortBaudRate(), ...')
    print('     Serial port =', (serialPort0.name + ','), 'Buad rate =', baudrate)
    serialPort.baudrate = baudrate
    print('   End   setSerialPortBaudRate(), ...')

def serialPortWriteBytes(serialPort, writeBytes):

def serialPortReadBytes(serialPort, maxBytesLength):
    readBytes = serialPort.read(maxBytesLength)
    return readBytes

def serialPortWriteWaitReadBytes(serialPort, writeBytes, maxBytesLength, waitSeconds):
    readBytes = serialPortReadBytes(serialPort, maxBytesLength)
    print('     bytes written = ', writeBytes)
    print('     bytes read    = ', readBytes)
    return readBytes

def repeatWriteBytes(serialPort, writeBytes, waitSeconds, repeatCount):
    print('     Begin repeatWriteOneByte(), ...') 
    for i in range(repeatCount):
        serialPortWriteBytes(serialPort, writeBytes)             
    print('     End repeatWriteOneByte().')

def serialPortLoopBack(serialPort, writeBytes):
    print('   Begin serialPortLoopBack(), ...')
    maxBytesLength = 64
    waitSeconds    = 0.0
    serialPortWriteWaitReadBytes(serialPort, writeBytes, maxBytesLength, waitSeconds) 
    print('   End serialPortLoopBack()\n')

def repeatSerialPortLoopback(serialPort, writeBytes, repeatTimes):
    print('     Begin repeat serialPortLoopBack()')
    print('       repeating', repeatTimes, 'times, <Ctrl> C to abort, ...')
    maxBytes = 64
    waitSeconds = 0.0
    for count in range(repeatTimes):
        # sleep(waitSeconds)
        readBytes = serialPort.read(maxBytes)

    print('      End repeat serialPortLoopBack()')

def testRepeatSerialPortLoopback(serialPort, writeBytes, repeatTimes):
    print('   Begin testRepeatSerialPortLoopback(), ...')
    print('     Serial port =', (serialPort0.name + ' '))
    print('     WriteBytes  =', writeBytes)
    print('     RepeatTimes =', repeatTimes)
    print('     Now repeating', repeatTimes, 'times, <Ctrl> C to abort, ...\n')
    repeatSerialPortLoopback(serialPort, writeBytes, repeatTimes)
    print('    End   testRepeatSerialPortLoopback(), ...\n')
# ### Main ### 

# Set serial serialPort0 115200bd
setSerialPortBaudRate(serialPort0, 115200)

# Loopback bytes object b'xyz123\r\n'
serialPortLoopBack(serialPort0, b'xyz123\r\n')

# Loopback reuest Vin command b'\x55\x55\x01\x03\x1b\xe0'
serialPortLoopBack(serialPort0, b'\x55\x55\x01\x03\x1b\xe0')

# Testing Rpi send/receive LeWanSoul request/reply bytes to/from LX-824HV

requestVin = b'\x55\x55\x01\x03\x1b\xe0'
repeatTimes = 10000000
testRepeatSerialPortLoopback(serialPort0, requestVin, repeatTimes)

# End of program


### Sample output tlfong01  2020sep15hkt2132 ###

   Begin serialPortLoopBack(), ...
     bytes written =  b'UU\x01\x03\x1b\xe0'
     bytes read    =  b'UU\x01\x03\x1b\xe0UU\x01\x05\x1bS\x14w'
   End serialPortLoopBack()

   Begin testRepeatSerialPortLoopback(), ...
     Serial port = /dev/serial0 
     WriteBytes  = b'UU\x01\x03\x1b\xe0'
     RepeatTimes = 10000000
     Now repeating 10000000 times, <Ctrl> C to abort, ...

     Begin repeat serialPortLoopBack()
       repeating 10000000 times, <Ctrl> C to abort, ...


# End

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.


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 )

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.