View Full Version : [Question(s)] Controlling servos using Midi...help

07-27-2008, 10:23 AM
Ok...I have an SSC-32. I have no idea how to program it...how to control it...how to do much of anything.

I suppose I could figure out how to plug it into a computer...

In anycase, I could really use a piece of software that would convert MIDI signals say use the note number 0-127 to choose the servo number, and use the velocity 0-127 to set the position of the servo horn.

Of course what would really make me happy would be an SSC-32 MAX/MSP object. but again...you would need to know how to program in order to do that.

Also, There are a host of different midi controllers out there. It would be sort of awesome if every one of them could be controlled via MIDI... or MAX... I know a lot of electronic art people who would be really happy with that. If people make code to do that, post it here.


07-27-2008, 02:21 PM
In theory it's not that tough a project.

You would either need to map multiple SSC32's, of course, or have multiple notes mapped to the same servo, since you only have 32 on the SSC.

For simplicity, look at the second.

128 notes, 32 servos = 128/32 = 4 notes per servo.

The range a servo can move with the SSC32 is 2000uS pulse (500-2500 range)

2000/128 = ~16uS per velocity step.

The format for the SSC32 is:
#<channel> P <pulse width> S <speed [optional]> T <Time in MS to take [optiona]> <cr [carriage return]>

So we would use a program to fill out variables and send to the serial port a string like this:
#(note_value/32) P (500+(velocity * 16))<cr>

In pseudo code

GET MIDI-Velocity
LET INT note_value = (MIDI-Note / 32)
LET INT velocity = (500 + (MIDI-Velocity / 16))
IF velocity > 2500 THEN velocity = 2500 // round the small overage, MIDI 127 = 2532!
CONCATENATE STRING $Out = "#" + note_value + "P" + velocity + ASCII(13)

In practice, you need a library to read from the midi port, and a library to write to the com port in whatever language you choose.

MAX/MSP is supposed to be ideal for this - but I've never used it... If you look up how to capture midi data and how to write to a com port, bashing that pseudo-code into place should be a few trivial minutes. It really is that easy (at the simplest).

Wanna give it a go?

07-27-2008, 05:46 PM
In actual numbers and letters and stuff...what would a message sent to the SSC-32 look like. I think I might be able to write directly to the comport using the UDPsend object in max...with a phidget Servo you send it

setMotorPosition 0 114

That would set the motor in the number 1 slot to its center position if you were using a phidget 4. What would the message sent to an SSC-32 look like?


07-27-2008, 05:53 PM
Your example would be:
#0 P1500<cr>

Additional examples:

#2 P1600 <cr>

Servo #3 with a 1600uSec pulse

#14 P2100 S700<cr>

Move servo #15 2100uSec at the speed of 700uS per Second

#22 P600 T1000<cr> Take 1000uSec (1 second) to move servo #23 to position 600uS

<cr> = Carriage Return, ASCII 13. You *must* terminate all commands with a carriage return character - not an LF (Line Feed) or CR/LF (Carriage Return/Line Feed)

07-27-2008, 06:39 PM
Ok...here is what I can do. I can only send a list of numbers to the com port using max. So...if I send:
35 48 112 49 13
the servo plugged in to port 0 will go all the way one way.

so I'm sending asci code...but I'm not sure where to go from here.

07-27-2008, 06:53 PM
Ok...I can now move a servo all the way one way, all the way the other, and center it by sending ascii code...not fun!

07-27-2008, 09:20 PM
I just spend the last few hours making a table that converts from midi to ascii. I still have to set it up to control all 32 servos...


07-27-2008, 09:31 PM
youch. That stinks! There's nothing like a CHR() function that will do that work for you? And you really can't send character strings out from MAX? I knew I didn't learn it for a reason! ;)

07-27-2008, 10:35 PM
Ok...its done. I uploaded it to:


I'm tired.


07-27-2008, 11:24 PM
Wow! Kudos, DB!

07-28-2008, 01:41 AM
2 problems with the software I posted. There is a "right to left problem, and the servo selector takes one input before selecting the appropriate servo...so if you move servo 0 to 114, and then move servo 2 to 75, servo 0 will move to 114.

Also, somehow 2 of my servos just burned up. Maybe noone should use this software until I solve the problem.


07-28-2008, 02:09 AM
Yikes! And [comfort] on your loss!

I "unapproved" your upload. If it's letting the magic smoke escape from servos, it's probably not ready for general consumption.

I don't think that causes any "harm" to your account, having a file unapproved. If you notice any reason why that's not a GoodThing, let me know and I'll delete it instead.

Sorry, DB, good luck resolving it! Sorry that I don't know MAX to help. Maybe someone else does and you can send it to them directly?

07-28-2008, 02:12 AM
what could burn out a servo like that?

07-28-2008, 02:20 AM
I'd have to post-mortem to know for sure, but slamming it against the stops and holding it there. Also would be suspicious of going over the #uS range of the servo.

What kind of servos, and were you going to the extremes? How old were these servos? Did they have any substantial load?

07-28-2008, 02:23 AM
It was 2 shoulder servos on my hexapod. The load was not all that extreme, and they should have been centered. They were both hitech 645mgs... a couple weeks old. I'll have to check through my tables and see if that was the problem.


07-28-2008, 02:27 AM
Ok...I never sent below 500 or above 2500

07-28-2008, 02:27 AM
If you have another PC (or feel comfortable/want to learn how building a loopback plug), we could remove your SSC32 and run the same procedure that might have burned out your servos (ouch!), and check to see exactly what was getting issued to the SSC.

The procedure is to put a cross-over or null modem in the line and redirect your coms traffic to a terminal program (I use realterm now). Another way to do it is to use a loopback plug. Basically just cross RX and TX in the plug and capture the data stream with something like realterm...

07-28-2008, 02:30 AM
I can just send all of the messages sent to the terminal...


07-28-2008, 02:34 AM
"Most servos have more than 90deg of mechanical range. In fact, most servos can move up to 180deg of rotation. However, some servos can be damaged when commanded past their m,echanical limitations. The SSC-32 lets you use this extra range" [...] "Remember that some servos may not be able to move the entire 180deg range. Use care when testing servos. Move to the extreme left or right slowly, looking for a point when additional positioning values no longer result in additional servo output shaft movement. When this value is found, put it as a limit in your program to prevent damaging the servo. Generally, micro servos are not able to move the entire 180 deg range"

From: Getting Started in the SSC-32 manual.

I think I gave you some pretty bad advice, maybe I should have RTFM'd more closely FIRST. Mea Maxima Culpa.

Do you have a paypal account? I'll contribute to the "sacrificed servo" fund...

07-28-2008, 02:37 AM
are you kidding...you made it possible for me to control 32 servos from one chip. I had 6 phidget 4s to control 18! so the way I see it...you just saved me what...$400. So I'm out a couple of servos...You live and you learn.


07-28-2008, 02:41 AM
Ok...just to be sure...the limits are 750-2250?

07-28-2008, 02:46 AM
Thanks for that, but even if I didn't pull the trigger, I loaded the proverbial gun. I feel like a doofus (nicest word I could come up with to keep the thread family-friendly). I opened my "mouth" from a theoretical position instead of an applied position. I smoke hardware daily doing that (if you're not smoking hardware you're not inventing), but I really don't feel good about smoking OTHER people's hardware...

07-28-2008, 02:48 AM
I'd explore those limits carefully. Can you make a slider that increments the values by a handful and displays the value sent? You could back it off real quick if it pegs on either side.

My only 645 is the shoulder of my arm, and it'd take hours to get it out of there...

07-28-2008, 02:54 AM
That's odd - the spec sheet on the 645MG quotes:

Range (1-2ms pulse):90 degreesRange (maximum*):200 degrees

It says that it might vary slightly at the max from servo to servo, but you shouldn't have gone over it (2000 * 0.10 = 200 deg) - I'd have expected even with the variance that it could tolerate the extreme for some period of time before going "boom", unless they were left at the extremes for a period of time...

07-28-2008, 03:19 AM
Ok...I just hooked up a different servo to the same port, and ran it through a sweep. I found a couple of places where it jerked to one side or another, and checked my table...seams I put in a couple 43s instead of 53s. not sure how that adds up to fried servo, but that might just be it. so I sent it things like # 2 p 11 "43" 0 <cr> The servo would swing all the way to one side, then back to where the table left off when it got that string. It may be that I was changing the pulses too quickly. In anycase, I went through 0 - 127 and cleaned all that out. I still have to fix the right to left problem, and I'll probably go through and disable 500-749 and 2250-2500...

See...it wasn't even your fault.


07-28-2008, 03:24 AM
# 2 P 11 would send it way out of range. I just checked (the bottom is 500 Min) on an S148, and it will swing it all the way to the minimum (500) and then decide that it can't complete your request, and return to previous.

I'm not sure what you're doing with that string? What's actually getting sent to the SSC-32 there? That doesn't look at all like a valid string?

07-28-2008, 03:31 AM
That wasn't a valid string...That was the problem I think.

(# 0 p 1605 <cr>) looks like (35 48 112 49 54 48 53 13) I mixed up a couple of 43s in the place of 53s in the string so it would have read (# 0 p 160 "43" <cr>) The servo moved to the 500 place, and then returned to where it left off.


07-28-2008, 04:19 AM
Well...I went through and checked the table. 0 still = 500 and 127 = 2500...outside of that it looks pretty good.

I'm using a couple Mg995s "tower pro ebay servos"

They seam fine with the range and everything. Switching back and forth from one servo to the other also seams OK. I'll see about loading the software as an alpha version tomorrow.


07-28-2008, 04:21 AM
seriously though...thank you for all of your help. Today was a good day. I learned how to do something that I really needed to be able to do.


07-28-2008, 11:47 AM
I'm glad you got to push the envelope a little on your day. :) Sorry I didn't get back with you last night, my Internet connections (both of them) were toast for 7+hrs... :(

I can't think of any guaranteed method of confirming just how far a servo can be pushed. Maybe a couple input boxes on your control that people have to enter the range in, and if it's outside of a "safe" 90deg, they have to confirm a warning?

07-29-2008, 01:14 AM
The software is fixed. I'm posting it labeled as an alpha version. You have to click a toggle to extend the available values from 750-2250 to 500-2500. Thank you adrenalynn for all of your help.

YEAH...It works!


07-29-2008, 01:26 AM
Here it is.

Clickme (http://forums.trossenrobotics.com/downloads.php?do=file&id=96)


07-29-2008, 01:36 AM
Grats, DB! Thanks for releasing it!

You know, I have some great keyboards, but I couldn't find my MIDI card if my life depended upon it...

07-29-2008, 01:54 AM
I know this is going to sound a bit stupid, but I don't expect people to actually use a keyboard to talk to this program...See...coming to robotics from the art side of things, I know about this much when it comes to coding (holds fingers up showing that he knows nothing). But...I can program like nobodies business in MAX/MSP. So...for me if there wasn't a MAX patch for controlling a servo controller, then I couldn't use it. That is why I have been glued to Phidgets for so long. That said, I'm finally free. I can use an SSC-32...at least on my PC. I'll have to figure something else out for my mac.

I just want all the other MAX users out there to have the same freedom I now have. So...people using programs like supercolider and flash (with the midi plug in)...and even programs like Cubase can send midi data through an IAC (inter application) driver to this software and use an SSC-32...



07-29-2008, 02:02 AM
Aha! I see where you're going with that. I could also see some live performance art possibilities with a midi device, though.

Why won't this work identically on the mac? At least an older Mac has rs232 ports, and there's usb->serial that work with the mac.

07-29-2008, 02:09 AM
It may work on a mac...I don't have a serial adaptor for my mac though so I can't test it, and I have to "recompile" the max patch for it to run on a mac.

Basically you open the program in max on a mac, and then have max build an application that would be .app instead of .exe

It should work...but I can't be sure.


07-29-2008, 02:20 AM
Nod. That's kinda what I figured.

What kind of Mac do you have?

07-29-2008, 02:41 AM
a white macbook...not the pro

Model Name: MacBook
Model Identifier: MacBook3,1
Processor Name: Intel Core 2 Duo
Processor Speed: 2.2 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 4 MB
Memory: 1 GB
Bus Speed: 800 MHz
Boot ROM Version: MB31.008D.B00
SMC Version: 1.24f2
Serial Number: W8743D3EZ63
Sudden Motion Sensor:
State: Enabled

07-29-2008, 03:17 AM
That has a PCMCIA slot, right?

Or USB -> RS232 is pretty ubiquitous: http://www.newegg.com/Product/Product.aspx?Item=N82E16812200141


MacOS compatible, in theory... I don't have any Macs that modern to test it with. ;)