Using ssc-32 and Arduino together

Ah cool, you should be in good shape then. Bear in mind I’m not specifically familiar with the Arduino so this is more of a generalized reply about the concept.

First off just read through the SSC-32 user’s guide to get an idea how its command syntax works.

Basically you want to replace what would typically be a PC or an atom bot board with your Arduino. With that concept in mind, depending on whether you have TTL or RS-232 output for the Arduino serial port you need to connect to the TX, RX, and GND pins of the header labeled 14 in the guide (for TTL) or to the DB-9 connector labeled 12 (RS-232). A note on the RS-232: if you would normally plug an Arduino RS-232 output directly to the serial port of a PC using a male-to-female extension (ie striaght through) cable then you will need a null-modem adapter between the Arduino and the SSC-32 DB-9 to get the TXD and RXD pins swapped.

Once you have a hardware connection then you need to configure the baud rate and serial parameters on both ends to be the same. I would recommend at least 38,400 but your Arduino may be capable of 115.2K which would be the best choice. The word size, parity, and stop bits are forced by the SSC-32 to be 8 bits, no parity, 1 stop and you will need to make certain the Arduino is set that way. When you pick a baud rate then verify the SSC-32 jumpers labeled 9 in the user manual are set to the chosen baud rate. For reference there are a set of 16 pictures in the users guide showing some common shorting bar setups and the available SSC-32 baud rates are the bottom four pictures.

Ok so I am going to expect at this point that you have the Arduino adequately powered and the SSC-32 powered ideally with 6V on VS1, the VS2=VS1 jumpers installed, the VL=VS1 jumper removed, and a 9V battery powering the VL input. Also per the above you should have a serial connection between the Arduino and the SSC-32 and baud rate and serial settings configured. It wouldn’t hurt to have a servo on port 0 of the SSC-32 just so we have a common point of reference for an example, and having servos on ports 0-3 will work directly with what I type below.

Generally speaking the first step after configuring your serial port would be to send the servo(s) to their neutral position. The syntax for this would be sending a string “#0 P1500\r”. If you have multiple servos you can initialize them all on the same line like “#0 P1500 #1 P1500 #2 P1500 #3 P1500\r”.

Now change your main loop to look for a button press or other user input. When you see that input you can send a command to move the servo to a new position. For example we can say -45 degrees from neutral would be “#0 P1000\r”. That command will send the servo to -45 degrees as fast as it can go. One of the nice features of the SSC-32 is it can do timed moves, that is it divides a movement range up into a series of smaller steps such that the servo moves as smoothly as possible from start to finish over the requested time period. A modification of the above command demonstrating this woud be “#0 P1000 T2000\r”. An even more useful extension of this feature is the SSC-32 can do this timed move with multiple servos all going to different locations and arriving at the same time. An example would be “#0 P1000 #1 P1400 #2 P1750 #3 P2000 T1500\r”.

So I would like to think you should have the basic concept of how to move a servo using serial commands issued by the Arduino at this point. You have made no mention of your target application yet so there isn’t much more for me to work with example wise.

Thank you, I now can move right to the real experiment! About my application, it is an inverted pendulum robot. I have Arduino, SSC-32, IMU, IRs, Ping and 4 reflectors (to set up optical encoders). Servos are going to be 2 continuous rotations, and I could put them on a single Arduino, but to learn the communication system of SSC-32 I am doing this way. Any your comment is very welcome: I am a novice in the field :wink:

My Arduino has a USB, not DB9, and I have to use its output pins of TX and RX. In this case, RX from Arduino, goes to the TX of SSC-32, and TX from Arduino goes to the RX of SSC-32, right? :slight_smile:

I would verify this in the datasheet for the module but those are probably 3.3V TTL level signals. I can’t say for certain, you may need to post on an Adruino specific forum, but if the connections are 5V tolerant then it should be ok to connect them directly to the TX and RX pins of the SSC-32, the ones labeled 14 in the user manual. If they are not 5V tolerant then you will need to put some resistors in series or possibly a buffer of some sort. I can’t say for certain but it is a common enough issue with interfacing different modules together that it should be easy to get an answer in the Arduino support forum if needed. The SSC-32 TTL lines are from a controller running at 5V so just need to be a little careful there and do a little fact checking before just slapping it together.

If I understand the concept of “inverted pendulum robot” then it is something that balances itself on two wheels? You may want to keep in mind when coding that there is a time delay between sending a command and having it acted upon at the motors. This is because the serial communication need to occur and that takes a few hundred microseconds at least and possibly more if a lower end baud rate is used. the other fact to consider is the servos are only updated 50 times a second, i.e every 20mS, so be conscious of that fact when working out your code. the only type of this robot I’ve seen before had direct control of the h-bridges driving the motors and updated at several kHZ rate. this made for a very responsive control of the motor torque, but whether that was necessary or not I do not know. good luck and keep us posted, maybe pictures of your assembly, as you progress.

sure, thank you for valuable comments. Please also let me know, if I put pictures when read, here, or a special part of forum? I didn’t find an exhibition forum index, may be it is called different? :wink:

Well just to make sure again:

I read this:
The Arduino Duemilanove has a number of facilities for communicating with a computer, another Arduino, or other microcontrollers. The ATmega168 provides UART TTL (5V) serial communication, which is available on digital pins 0 (RX) and 1 (TX)…

here:
arduino.cc/en/Main/ArduinoBoardDuemilanove

so that, I can connect the RX/TX from Arduino to TX/RX on SSC-32 right? :slight_smile:

ah sure. hmmm… that’s kind of an odd way to connect stuff (in the schematic of the arduino) as its sort of sharing the TTL serial lines between the USB adapter (FTDI FT232RL, FTW) and ports 0, 1. I see there is a 1K resistor between the connections but just keep in mind if you send something to the Arduino with the SSC-32 attached (and powered) then it is going to see the characters as well, and if the SSC-32 isn’t powered it might drag down those lines such that the PC can’t talk to the Arduino boot loader or whatever it’s using. Depending on how often you plan on re-programming the Arduino it might be worthwhile to put a two-pole switch in series with the TXD and RXD lines between the SSC-32 and Arduino. Something like a Radio Shack 275-407 or 275-403 would work fine.

Ok, well, first I tried and I was wrong in my programming and nothing worked! then I found this tutorial that helped to understand what you say better, so I put the link here may be helpful to others too :slight_smile:

learnhub.com/lesson/page/7448-mo … an-arduino

If here something is not right, please tell me:

void setup() {
  Serial.begin(9600);
}

void loop() {
  move(1, 2000, 100);
  move(1, 1000, 100);
}

void move(int servo, int position, int time) {
  Serial.print("#");
  Serial.print(servo);
  Serial.print(" P");
  Serial.print(position);
  Serial.print(" T");
  Serial.println(time);
  delay(time);
}

I have one more question:
Well my servo is continuous rotation. If I want it to go forward for 10 seconds, and then, say, backward for 15 seconds, how should I code it?

thank you :slight_smile:

generally speaking continuous rotation servos are normal servos where the feedback pot has been disconnected from the output shaft and replaced with a voltage divider that approximates 0 degrees position. what this means in english is sending 1500ms should be a stopped condition for the motor because the servo control board in the servo thinks the shaft is at 0 degrees. if you give the servo a slight longer or shorter pulse the servo control board will attempt to position the motor at the new angle, however becaue the voltage that represents that angle is a hard-wired constant the motor will just continue to turn. usually the range of 0rpm to full speed is fairly small in terms of change from 1500ms… I think I recall it being as low as +/- 100.

for your example, granted here I don’t know which adjustment direction is CW vs CCW, just pick CW to be +100 and CCW to be -100. Thus you would send 1400, delay for the 10 seconds, then send 1600, delay for 15 seconds, then send 1500 to stop moving.

The Hitec servo motors have a positive pule to direction relationship. ~1500 will stop the motor, shorter pulses will rotate CCW, longer pulses will rotate CW.

Lets assume “forward” is CW rotation, you would send this.

#0 P1500 cr #0 P2000 T10000 cr (pause for 10 seconds) #0 P1000 T15000 cr (pause for 15 seconds)

Actually Jim that code will accelerate for 10 seconds, then decelerate for 15 seconds. It will take well over a second for it to get moving at top speed, then it will take well over a second to decelerate back to 0 and another again well over a second to accelerate back up to full speed in the opposite direction. Maybe it was your intention to introduce ramp up / ramp down in your example by way of adding the T parameter to the string. It is an important difference though from what I posted which will just bang from stop to full CW to full CCW to stop. :wink:

Doh! That’s what I get for posting before I’m fully awake. lol

You’re right. :blush: Sorry for the confusion.

#0 P1500 cr (motor stopped waiting for command to move forward) #0 P2000 cr (pause for 10 seconds) #0 P1000 cr (pause for 15 seconds)

Hey Eddie, you’re starting a lot of posts with “actually Jim” lately :slight_smile: I need to pay better attention. lol

Sorry. No disrespect intended. :frowning:

Ah, none taken! I have just been burning the candle at both ends lately. lol

I really appreciate the help! :smiley:

well would you please explain for non-English people, what is:

…burning the candle at both ends lately
please? )

Um, well it’s an idiom for working long hours with little rest. Not sure of the origin.

it makes more sense in the non-abridged version of “burning the candle at both ends of the day”, which in the old days meant it was before dawn when you got up to go to work and after twilight by the time you got home. Of course this time of year the people living way north kind of experience that effect implicitly anyway. :wink:

Um, Eddie you forgot “actually Jim” lol :smiley:

That makes a lot more sense now, thanks. :wink:

“Actually jim”, LOL,
I tried to implement the code you recomended:

#0 P1500 cr
#0 P2000 T10000 cr
(pause for 10 seconds)
#0 P1000 T15000 cr
(pause for 15 seconds)

in this way with Arduino:

void setup() 
{ 
  Serial.begin(9600); 
} 

void loop() 
{ 
    Serial.println("#0 P1500"); 
    Serial.println("#0 P2000 T10000"); 
    delay(10000);
    Serial.println("#0 P1000 T15000");     
    delay(15000); 
}

But it does not work as I expect! the speed of motors in different turning in the loop are different, but my power source is not a battery to say that it falls down.

Well, all of my effort to lean ssc 32 is for my aim is to study Kalman filtering, where my KF code is ready, but I can’t command motors with ssc 32 so that the robot passes a square of 50cm, again and again.

considering the Arduino structure as I provided above, how do you code it? may be you know how to do it right?
Thank you!!!