Thursday, January 09, 2014

RC USB connection protocol

Yesterday I received a hobbyking shipment with a 6 channel remote control and a cable use it from the USB port. However, all the software to use it was written for Windows. Since I use Linux, I decided to see how does the protocol work and write some software for it to practice in virtual before crashing my toys.

It turns out that the protocol is very simple. Two characters per channel. The first two characters of the packet are 'U' and chr(252).

You can run the following lines in python to visualize what's going on.  I release these lines as usual under GNU LGPL.

# Written by gralfca
import sys
def readsync():
    sync = 'U'+ chr(252)
    s = sys.stdin.read(2)
    while s != sync:
        s1 = sys.stdin.read(1)
        s = s[1] + s1

def posval(xx):
    return int(ord(xx[0])*256 + ord(xx[1]))

def readpos():
    return posval(sys.stdin.read(2))

while True:
    readsync()
    positions = [ readpos() for _ in range(6) ]
    print positions

######

You can save the program as poscat.py and then run it as :

cat /dev/ttyUSB0 | python poscat.py

0 Comments:

Post a Comment

<< Home