serial port servo control

B

boyle5

So I ordered a mini SSC II (the servo controller), in order to
control some servos from the computer. I was hoping to use python to
do the control but have two questions...

1) How should I write to the serial port with python? I found the
module "pyserial":
http://pyserial.sourceforge.net/
on the python cheeseshop, and it looks solid but I thought you might
have a better suggestion.

2) To control the servos I have to send the SSC II a string of 3
numbers, 3 bytes long (so 3 numbers in the range 0 - 255, each as a
single byte, one after another). In C I'd do this by sending 3
char's, as they're only 1 byte, but i'm not exactly sure how to do it
in Python.
 
D

Diez B. Roggisch

So I ordered a mini SSC II (the servo controller), in order to
control some servos from the computer. I was hoping to use python to
do the control but have two questions...

1) How should I write to the serial port with python? I found the
module "pyserial":
http://pyserial.sourceforge.net/
on the python cheeseshop, and it looks solid but I thought you might
have a better suggestion.


pyserial is what you need.
2) To control the servos I have to send the SSC II a string of 3
numbers, 3 bytes long (so 3 numbers in the range 0 - 255, each as a
single byte, one after another). In C I'd do this by sending 3
char's, as they're only 1 byte, but i'm not exactly sure how to do it
in Python.

Strings in python are byte-strings. So you can use them. Additionally, I
recommend looking into the module struct.

Diez
 
R

Richard Brodie

1) How should I write to the serial port with python? I found the
module "pyserial":

I don't think there is any need to hunt for anything better.
In C I'd do this by sending 3 char's, as they're only 1 byte,
but i'm not exactly sure how to do it in Python.

Use a string type. output = chr(x) + chr(y) + chr(z) for example.
There is no restriction on null bytes in strings, so they are
appropriate for binary data.
 
S

Si Ballenger

So I ordered a mini SSC II (the servo controller), in order to
control some servos from the computer. I was hoping to use python to
do the control but have two questions...

1) How should I write to the serial port with python? I found the
module "pyserial":
http://pyserial.sourceforge.net/
on the python cheeseshop, and it looks solid but I thought you might
have a better suggestion.

2) To control the servos I have to send the SSC II a string of 3
numbers, 3 bytes long (so 3 numbers in the range 0 - 255, each as a
single byte, one after another). In C I'd do this by sending 3
char's, as they're only 1 byte, but i'm not exactly sure how to do it
in Python.

Maybe a little off topic, but I've got a page below with some mini ssc
control info.

http://www.geocities.com/zoomkat/index.htm
 
S

Scott David Daniels

Several have suggested struct, I'd suggest you look at array:
import array
v = array.array('B', [1, 2, 3])
for i in range(17):
v[i % 3] *= max(1, i // 3)
v.tostring()

--Scott David Daniels
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top