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

Thanks Kurte,
29 pages of topics about Xbee!!! :open_mouth:

I use this board to connect Arduino with Xbee:

Looking at your adapter, it says 3.3V on it, so I am taking it your Arduino was running at 3.3v and not 5V? I know that me Seeeduino Megas have a switch to choose which voltage to use. But it also looks like a voltage regulator on it… So maybe it does voltage conversion? Not sure what to tell you here.

Kurt

Hi Kurte,
Arduino 2009 or new Arduino UNO have a 3.3V and 5V pin:

Thanks Jeeg,

I was aware that the Arduino boards can supply a 3.3V… I was just wondering what voltages is this board expecting in on DIN and RTS…

But re-looking at the XBEE board, I now think it is probably fine. That is I missed VIN going into the board. My guess is that you use that pin to connect to the BB2 and that you probably don’t use the 3.3v pin… I can not tell if it has any voltage conversion circuitry or not on the IO pins… Which unit is this one?

Thanks
Kurt

Kurt,

That’s the Arduino UNO. There’s a 3.3v reg on it alright, But I don’t see it going to anything!

Also, schematic shows two 16MHz XTALS, although I only see one on my board. I suspect they’ve realized that one OSC output pin on one uP can feed the OSC input pin on the other…

I’m looking at the “Arduino UNO reference design”.

Alan KM6VV

Is it possible to keep the current code, only the SSC function and PS2?

Not sure what the question is!

There is a PS2 library for the Arduino UNO.

Talking to an SSC-32 is a text string. The pseudo-C code used on the Arduino doesn’t appear to have a fully implemented printf() function, so the strings must be made up peace-meal. Not sure if there is adequate string concatenation either. But the job can be done.

So, some work on the code would have to be done to “port” it to the Arduino.

Alan KM6VV

FYI - you have most of the full set of GCC libraries. So my port of the code that runs in the Arduino environment on an Arduino Mega uses the library function vsprintf to play with. In that code I did some quick and dirty wrapper functions like:

SSCPrintf(const  *format, ...)
{
    char szTemp[80];
   int ich;
    va_list ap;
    va_start(ap, format);
    ich = vsprintf(szTemp, format, ap);
    SSCSerial.write((byte*)szTemp, ich);
    va_end(ap);
}

The code is not very pretty but got the job done.
Kurt

Thanks for the tip. I never really liked vasprintf(), but I suppose in a pinch…

What have you seen of the string concatenation functions?

I did discover that it accepts #define, and full ANSI function prototypes. It’s getting comfortable!

Alan KM6VV

I have not played at all yet with the new features in build 21, but since build 19 there is a full string class (arduino.cc/en/Reference/StringObject) available to you, that looks pretty functional…

There are also some other contributed libraries that add some more streaming functionality. Again I have not played with these…

Kurt

Ah yes!

I’ve started working with build 22. It has the strings functions, they’re under “String - object”.

How did you get by without asin() etc.?

Alan KM6VV

Thank you kurte for the code on the Arduino mega. It works !!!

Hi all,
Do you think it might works without using SSC-32 since Mega has many I/O pins? I have tried on biped but it won’t work when it go over 12 servos.
Beside, if connect SSC-32 to mega is it possible to have XBee connected? Because they both use TX/RX from mega?

It might work without the SSC-32, but I have not fully tested it. I did sort-of try it with just one leg as that was how many extra servos I had and I did not wish to tear apart one of my Hex’s to fully try it. :blush: It probably would work great if I modified the servo driver to use IO pins associated with 16 bit PWM channels. This is what webbotlib (different set of AVR libraries) does. The current servo library says it supports up to 48 servos on a Mega.

As for connecting SSC-32 and XBee on a Mega. No problem. A mega has 4 UARTS, so on mine, one is used for USB, second for SSC-32 and the third with the XBee.

Kurt

I did try that and even the doc says it support up to 48, but it’s not working when I have 12+ servos. 12 servo works fine thou. Perhaps I am still new to this and doesn’t have proper setting. :cry:

Do you need to have somthing in the code to setup UART so they know where to communite with XBEE, SSC32 etc?

As I mentioned I have not tried without the SSC-32. So not sure I can help much here. My guess is maybe has something to do with what timers are available or the like… If I get a chance I will try to take a look at there library to see if I can get a clue…

As for serial ports. The arduino environment sets up hardware serial port objects (Serial, Serial1, Serial2, Serial3) for you. I simply have defines in Hex_Cfg.h to say which one I am using where.

// Which type of control(s) do you want to compile in #define DBGSerial Serial #define SSCSerial Serial1 #define XBeeSerial Serial2

You do need to do a begin on each serial port to let it know what baud rate to use… Example for XBee…

void InitXBee(void) { XBeeSerial.begin(62500); // BUGBUG??? need to see if this baud will work here. // OK lets set the XBEE into API mode... ...

Good Luck
Kurt

P.S - The SSC-32 is a great way to go!!!

EDIT: Took a quick look at the Servo code and it is supposed to handle 12 servos per clock and on the Atmega1280 there are 4 clocks available (5, 1, 3, 4). So it should handle 48. When you say it does not work, where does the error happen? I assume you set the type of board to a Mega 1280(Tools\Board)

Where in the code can be placed Offsets of the legs? I mean the servo position adjustment. I ask because I not a programmer and more electronic and mechanic. :slight_smile:

I was using Mega 2560 but no clue how to setup these clock thingy in code. “handle 12 servos per clock”, I guess that’s why my servos are not working properly above 12.

BTW, I got SSC32 yesterday but haven’t wire up with arduino yet. Any tips how to connect them? I have tried it with lynxtrim it looks fine with standard servo but I burned a Hitec 5485 servo I guess :cry:, perhaps digital servo need some special setting?

The code for the 2560 should be the same as the 1280, and should automatically handle the multiple clocks. When you create your 13th servo, it should detect that that the count went higher and then configure the second clock. Again this is looking at the code as I have not tried this myself…

I would hook up the SSC-32 to one of the UARTS, example Uart2. You would hookup TX2 to the input pin of the SSC-32. Connect up RX2 to the output pin of the SSC-32 and connect up a ground wire between the two…

Digital servo still take a standard PWM type signal. The only differences are: sometimes the range of signals is different and once started you can not turn off most digital servos… (You stop sending signals and it simply stays at the last location).

Good Luck
Kurt

I got this SSC-32 board:bizoner.com/arduino-usb-ssc32-servo-motors-controller-with-bluetooth-apc220-p-215.html

I have connect them like this:

Mega:TX2–>SSC32:RX
Mega:RX2–>SSC32:TX
Gnd–>Gnd
Or should I go TX2–>TX,RX2–>RX???

BTW, here the first try when I do your phoenix code but shows up some errors.
hardmouse.com/robots/ask4help/sscerror.jpg

Sorry to keep bugging you but truly appreciated for your help. :slight_smile: