Phoenix code running on an Arduino Mega with an SSC-32

With some recent posts about talking to the SSC-32 from an Arduino, I thought I would share some of the stuff I did about a month or so ago… Note: I am using Arduino version 18

As some of you can probably tell from some of my previous posts, on the Running the Phoenix on C that after I had it part way working I started to make the my libraries closer to that of an Arduino, I have still a ways to go, but in the more recent versions I am probably 80+% there. How do I know? Well as part of this, I ported my code over to the Arduino environment. In Particular I have a Seeeduino Mega board which is based on an Atmega1280 chip, it has 4 USARTS, tons of IO lines, etc.

I had the code working such that I can control the robot by PS2 and/or XBee. The code uses a newer standard PS2 library which I included. Also while I was doing it I noticed that the default hardware implementation for the USARTS did not do any hardware buffering of output and during my research found it had some performance issues which were easy to address. I also included my updated versions of these. If you wish to try these out, they go into the directory:

The Hex_cfg file shows which IO pins I used for this, including a sound pin. Again I used a cheap radio shack speaker so I would have some sound.

Arduino (49.4 KB)

Hi Kurte,

do you have an updated Version from the HardwareSerial?
It doesn’t work with Arduino 0021.


I have not tried running it in awhile, I do have it building with the default hardwareserial.cpp for build 21. It would be missing the speed up fixes for queuing up data as well as the buffering of output data. Will try merging that in soon. Currently have other processors on my test hex robot (so many processors and so few hex robots… :laughing:)


I decided to update the Arduino code to run with version 21 of the the IDE…

I have the hardware serial port code ported over. I think there may be still a few issues with the actual phoenix walking code that I am looking at now… But will need to wait until batteries recharge…

The only thing updated in this zip file was the serial driver code…

I verified that things were still running. May want to play more later with re-calibrating my hex robot and verify how well it walks. But my debug code shows that I appear to be generating the same values for the different leg calculations…

Warning I did not hook up the PS2 to verify it, but none of that code has changed… Will do so as I have not done this with IDE 21 yet. Also may update the PS2 library up to the latest version that I know has been updated recently…


Which Arduino Mega?

In C?

Alan KM6VV

I am currently using an Atmega 1280 based Arduino Mega. In particular I am mainly using: … mbled.html

I also have an older standard one:

I believe the real only difference with with new Arduino Mega 2560:

Is that the 2560 has twice as much memory… However so far that has not been an issue. My main Hex code is somewhere between 30-40K out of the 128K of the current processor.



That’s a much bigger chip then is on the Arduino UNO board (Atmel Mega328, I believe).

And real ‘C’ code, not the “script” (a subset/variation of ‘C’).

When I saw “Arduino” in your subject, I jumped on it to possibly find a starting set of library calls. the println() of Script is somewhat like a Basic, not a printf() like I was expecting to see…

This project is for our local HBRobotics class. Yeah, I tried to steer them into a BasicAtomPro…

Alan KM6VV

Yes this is a nice chip. It has the 128K of memory. It also has 4 USART, which is really nice. I can use one for the debug/USB port, 1 for the SSC-32 and 1 for the XBee. The only slight drawback is that since the chip is running at 16mhz, the USART can not generate 115200, so I am running the SSC-32 at 38400…

The code here is standard Arduino. Which to Me is no big deal. That is your main program has the standard blocks:
void setup()…
void Loop()…

Beyond that there are minor differences like the Arduino environment takes care of some forward references for you…

As for libraries, I have a standard one there for PS2 support. Libraries are written in standard c/c++

As for using standard C, I also have a version of this code that I ported over to standard C/C++ and I used webbotlib for the libraries(, which has a lot of interesting stuff… But again it has very specific things on how the program is organized… I was able to build the program using AVRSTUDIO and the GCC set of tools (WINAVR) and was able to download the program to the Seeeduino Mega with the tool AVRDUDE. I had to experiment with the options to make it work…

Good luck with the project for the HBRobotics class.


Quick Update: I updated to the lated PS2 library and verified that the PS2 still works.

Arduino (50.9 KB)

Thanks for the tips!

I’ve got code running on the UNO now for the HBRobotics 'bot (incomplete).

And after I get a state machine for the obstacle avoidance ported over, I should be in good shape.

I have CVavr, if I can get it moved off of an old laptop. But the little UNO has a boot loader and USB built-in, so it’s good for a simple project like this.

The AtomPro would have been easier. the ARC-32 would be really nice to use, but the UNO is $30 vs $100. Oh well.

Alan KM6VV

Hi Kurte,

can you explain me how to connect SSC32 with Arduino?


Note: I am using an Arduino Mega (actually mostly the seeeduino version…). So I simply connect up the 3 TTL pins of the SSC-32 (same ones you connect something like the BB2 to). I choose one of the serial ports to use (in my case 1):
#define SSCSerial Serial1

I use a servo extension wire, I use a longer one. I plug the one end into the SSC-32. I take the longer Male/Male connector that comes with the servo extender cable, I pull one of the pins out of it and stick it into one of the ground pin (female connectors on the Arduino), I plug the other two into the Recv and transmit pins of Uart1, I plug the appropriate wires coming from the SSC-32 into the Arduino pins I put the pins into…

Code wise, I then simply: Initialize the serial port.

I then use the standard serial communications to the SSC-32. Example here is the function to see if the SSC-32 supports GP…

[code]boolean FIsSSCGPEnabled(void)
char abVer[40]; // give a nice large buffer.
byte cbRead;

cbRead = SSCRead((byte*)abVer, sizeof(abVer), 10000, 13);

DBGPrintf("Check GP Enable - cb %d\r", cbRead);
if (cbRead > 0) {
    byte iT;
    for (iT = 0; iT < cbRead; iT++)
        DBGPrintf("%2x ", abVer[iT]);
    DBGSerial.write((byte*)abVer, cbRead);
if ((cbRead > 3) && (abVer[cbRead-3]=='G') && (abVer[cbRead-2]=='P') && (abVer[cbRead-1]==13))
    return true;

MSound (SOUND_PIN, 2, 40, 2500, 40, 2500);
    XBeePlaySounds(2, 40, 2500, 40, 2500);

return false;


Note: the SSCPrintf/SSCRead functions mentioned above are quick and dirty wrappers, that in the Printf function, simply uses the vsprintf standard c function to format stuff into a buffer and then uses, the standard serial write method to do the actual write to the SSC-32. Details are in the zip file that was posted.


Thank You Kurte!!!

I wont to connect Arduino 2009 for my CH3 hexapod project.
Is it possible connect Arduino 2009 instead of Arduino Mega?

You should be able to. Note: I have not used a non mega, but you should be able to plug the SSC-32 into any two digital IO pins of the Duemilanove and use the SoftwareSerial library, which is part of the standard Arduino library… Note: with software serial you have the same caveats of using the BAP28. That is your code will be sitting doing the transmit until the write is done and if you are not in a read statement and IO comes back from the SSC-32 that IO will be lost…


I want to try to complete my project changing BBII/BasicAtomPro28 with Arduino 2009!!!

Sounds good,

I hope you have the one that is based on a 328 and not the 168 as the 168 only has 16K of memory and 1K of RAM, where the 328 has double each.

In either case, if you are using my code as a starting point, you will probably have to trim things out. I am spoiled with the Mega with 128K of memory and 8K or ram…


Edit: Side note, one thing I like about the Arduino stuff versus the Bap basic software, is you can abstract which type of serial (hardware or software) you are using at the start of the program and none of the rest of the program has to change. Except of course where you are using functionality specific to one or the other…

Yes I’ve 328 Atmega on my Arduino 2009!
I’ve also an Arduino UNO that is a new version of Arduino.

Yes I will starting with your code; My goal is use arduino and PS2 controller to move my hexapod.

I’ve another questions: It’s difficoult connect Xbee with BBII in order to use an homemade remote control???
Can you explain me the connection between xbee and BBII?

There is lots of information about this on the thread: viewtopic.php?f=21&t=5447

It is similar to adding it to an Arduino. Like the Arduino the BB2 (with some chip like a Basic Atom Pro 28) runs with it’s IO lines at +5V and the XBee is +3.3V, so you will need some form of voltage conversion. You can use ones from sparkfun ( … fault.aspx)

Most of these (except the more expensive Parallax one) will require you to solder something, like wires or pins or the like. But you will need at least 4 wires (+5v, Gnd, TX, RX) connected to the adapter, maybe a 5th (RTS). You have the choice of connecting the XBee up to any 2/3 IO pins on the BB2. One choice is to use pins 14/15 (assuming BAP), which allows you to use the hardware serial port on the BAP. If you are using RTS line with the sparkfun adapter it is best to connect it to either IO pins 7 or 8 on the BAP28 as these output at a lower voltage…

As for software and the like there is lots of stuff up in the thread I mentioned earlier… Things like hardware serial port or not, issues of using the RTS line with the software serial support of the BAP (You can have the serin command tell the XBee that it does not want any more characters, but the XBee may send up to 2 more characters which the standard serin command will lose). One of the reasons I wrote my own serin command at the time.

Than there are issues/questions for you to decide on protocol and the like between your remote and your robot. Things like are you using the XBee as simple serial replacement or using it in packet mode… Again lots of stuff on the other thread.