Go Down

Topic: SOLVED: Devantech SD21 servo contr. and desperate programmer, after one year... (Read 11162 times) previous topic - next topic


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"



Well after blowing up a couple of servos due to a bad battery, I have built some simple code to mimic a walk with 3 legs on my Hexapod (new Servos are on the way). The walk is a simple 3 legged sweep forward then back, in a 20 count loop.  All was I looking for was SD21 function and to see if I had any major position issues.  At 6 volts positioning was not always good, at 5 Volts much better.

I did notice on my servos they got a little louder as the loop progressed, this is most likely a result of servo quality.  It seems to be only a couple of servos so no big issue there.

The Pod is sitting on a paint can so no weight on the servos at the moment.   

In the process I discovered a few things that you may l already know, but just in case.

The cheap servos are very voltage fussy, I found if the voltage was not steady and within the middle of the range, the positioning was quite poor.  To clean up my voltage I installed a BEC, Battery Eliminator Circuit.   In the R/C flight world it allows you to eliminate the battery for the receiver by supplying a steady 5 volts from your primary battery, and is ideal for small robots using this board.

My current BEC is only 10 Amps, but I have a 20 Amp on on the way.  This allows me to provide a steady 5 Volts to the Servos, the 20 Amp is adjustable for output voltage.  The down side is you need a fan, these generate a fair bit of heat under load and are designed to have airflow over them.  I have a little 5 volt computer fan I run off servo connector 21, it is about an inch square and generates enough airflow to keep things cool.

I found by using the BEC, I both protect my servos and seem to get better positioning, the power supplied to the servos side is only running the servos. Currently I use a 5 volt run from my bread board to power the logic side.  It is just a little simpler for debugging.  But it may also assist in keeping things cleaner.  When the bigger BEC comes I am going to running them both off the main battery and see if there is any difference.

I also found better positioning by slowing down the servo movement, I pass a speed, currently 12 (randomly selected).  Although it is a bit slow the servos seem to come back the same position.  At least they have not knocked over my endpoint sticks a small straw stood up :).
I need to play with that value.

Overall I am finding the SD21 does the job,  but information is hard to come by as you noted it does not seem very popular.

My final positioning tests will happen about week from now, I have a small FSR and have come up with a rig I can position under a leg.  In theory if the leg returns to the same position each time the FSR should have about the same reading.  I figure about 100 iterations at a variety of speeds should test the servo positioning pretty well and give me a set of benchmarks.

I use a Castle Creations BEC you can find some info here http://www.castlecreations.com/products/ccbec.html  I happen to be familiar with them, there are likely similar solutions in the robotics world.

I also switched to a different I2C library, primarily for better error control but it has some, at least to me nice features.



Our project is not that heavy duty, we are trying to maximize the 12V 2500mAH battery life by cutting the power from motors and servos when they are not needed. Silent and bright, LED's are blinking and NRF24L01 is powered all the time.

If ever I start project with unlimited power supply, that BEC is on the list.

The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"


A little tidbit from Devantech if you are running version 7 of the firmware you can save your servo start positions

you write 0x5A to register 126 (dec)/7E (hex)

I use a different Ic2 library but I included an example here of my servo save function.  I have a little function that checks for the SD21 and returns the address, firmware version and battery voltage.  The voltage is a little useless as I use a BEC but it does confirm the BEC is functioning correctly.

Code notes:

The Address of the SD 21 is set globally
The delay is there to give the communication time to complete,
it is a debugging and testing setting only.

Code: [Select]

// Firmware Version 7 allows saving servo info

void Save_servo()
// we write 0x5A to register 126 Decimal (7E hex)
// fixed value

  err_c = I2c.write(SD21,0x7E);  // set the register pointer
  if (err_c != 0)
      Serial.println("  Save_Servo - Error setting Servo pointer");

err_c = I2c.write(SD21,0x7E,0x5A);
  if (err_c != 0)
      Serial.println("   Save_Servo - Error Saving Servo setting");

delay (10);


i am doing a project...i am using arduino and devantech sd21 to control a hexapod spider... can someone show me a sample code.. that works ? or can give me any usefull advice of how to.


You are going to pretty much figure it out on your own.   My code is in limbo for a few more weeks, then I will be back to it.  But this is not a popular platform for multileg robots.

There is tons of stuff out there, but start simple 1 leg, your controller and some basic code.  Make that leg work then get the leg on the other side to work, it does not have to look really pretty it just has function.   Remember to define ranges of motion.

I have about 15 sketches related to this, in addition to the main, just to test out ideas and control schemes.

You are best off to work through the code yourself multileg robots are fairly complex you need to understand what each section your code is doing.  You can not "fake" your way through it.

I am happy to help you out figuring out the board, but for clarity you start your own post.

Go Up