Main Site Documentation

Control Servo from PWM on Extender module


#1

Hi all,

I recently picked up a small servo for testing with my Spider mainboard, and I’m now trying to make this work, with no luck unfortunately.

I have the servo hooked up via breadboard, using the Extender module as a breakout. The positive wire on the servo is hooked to the 5v terminal on the Extender, the negative to GND, and the white (control) wire is connected to pin 9, which I have configured as a PWMOutput. Here’s the basic code:

static GT.Interfaces.PWMOutput servo;
static Font font = Resources.GetFont(Resources.FontResources.NinaB);

void ProgramStarted()
{
    display.SimpleGraphics.BackgroundColor = GT.Color.LightGray;
    display.SimpleGraphics.DisplayTextInRectangle("Program running...", 2, 2, 150, 30, GT.Color.Red, font);

    servo = extender.SetupPWMOutput(GT.Socket.Pin.Nine);

    button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
}

void button_ButtonPressed(Button sender, Button.ButtonState state)
{
    display.SimpleGraphics.DisplayRectangle(GT.Color.LightGray, 0, GT.Color.LightGray, 2, 35, 150, 30);
    display.SimpleGraphics.DisplayTextInRectangle("Setting servo pulse...", 2, 35, 150, 30, GT.Color.Red, font);
    servo.SetPulse(20000000, 2250 * 1000);
}

The servo specifies a control voltage between 3.3-5v, with a .75-2.25 ms high pulse, and 20ms intervals. When the program calls the line servo.SetPulse, the board resets (this appears similar to the symptom I’m seeing in this thread: http://www.tinyclr.com/forum/21/5121/).

I’ve tried running it both with and without external power, and regardless of how the board is powered, the board resets when I call SetPulse, and the servo does not move (I’ve tried using different pulse settings within the stated range to no effect).

Any suggestions?


#2

Maybe your servo is not happy with 5V? Usually hobby servos are 6V IIRC.


#3

@ Gus,

I don’t think that’s it…the documentation (ok, small slip of paper, really) that came with it specifies “Control with 3.3-5 V signal”.

The full “documentation” states:

The title of the docs say “Standard Servo (4 to 6 volts)”

So I think I should be good with 5V supply, no?

I swapped out the servo temporarily with an LED to make sure my PWM was working, and the LED does light, so I’m pretty sure the code is correct (although it’s possible the values are out of range for the servo, but that shouldn’t make the board reboot).


#4

The dumb question: you have the servo control cable oriented correctly, right?

Here’s an early post I wrote about PWM on the netduino about a zillion years ago :slight_smile:
http://10rem.net/blog/2010/09/27/netduino-basics-using-pulse-width-modulation-pwm

On the netduino (using regular NETMF), the time is in microseconds, not nanoseconds. I’m actually surprised that the Gadgeteer can work with nanoseconds.

I have some tiny servos kicking around here. I’ll need to try to wire one up and see what happens. What brand/model information do you have on your servo? Can you post a picture?

Pete


#5

@ Pete,

I’m pretty sure I have the servo wired correctly…red to +5V, black to GND, and white to pin 9 for control.

The IntelliSense on the Gadgeteer PWM API indicates nanoseconds, so that’s what I’ve been using.

The servo I bought is manufactured by Parallax. I think this is the one:

http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/900-00005/List/0/SortField/4/ProductID/101/Default.aspx

Funny thing…the fact that Parallax lists this as a Futuba servo reminded me that I have a full Futuba R/C aircraft control kit, which I could’ve snagged the servos from…didn’t really need to buy one. :-/

Here’s a pic:


#6

Hmm. This warning on the Parallax site seems to indicate that this servo is too big to power directly from the MCU:

Note: Servo current draw can spike while under load. Be sure that your application’s power supply and voltage regulator is prepared to supply adequate current for all servos used. Do not try to power this servo directly from a BASIC Stamp module’s Vdd or Vin pins; do not connect the servo’s Vss line directly to the BASIC Stamp module’s Vss pin.

The PDF ( http://www.parallax.com/Portals/0/Downloads/docs/prod/motors/900-00005-StdServo-v2.2.pdf ) says 140 +/ 50 mA during operation, 15mA holding draw. Gus may be able to tell us if +5v on the extender is capable of providing that. One way to test would be to wire the servo power to an external 4-6v supply just as you would with a regular motor. Three AA batteries in series will supply 4.5v, four will do 6v.

Lots of other operation info in that PDF.

So, possible causes of problems:
[ulist]
Servo draws too much current
Servo signal voltage is too low (minimum is 3.3v, not sure if Gadgeteer is sending that exactly)
Servo may be underpowered
[/ulist]

Pete


#7

@ Pete

Would have been nice if the “documentation” included with the servo had that warning, or at least pointed to the PDF, but I suppose that folks with servo experience would know better.

Looks like the PDF should have sufficient info for me to figure out how to power the servo externally, separate from the board. Should be a good learning experience.

Interesting though, that there are folks who have powered servos directly from a FEZ Panda without issues…does the Panda supply more power than a STAMP, I wonder?

http://staceyw1.wordpress.com/2011/04/10/simple-servo-control-from-fez/


#8

I’m not sure. It may be true with the Gadgeteer/Spider as well. Gus will need to let us know what the thing can source.

Pete


#9

Yes you should be gone as far as power.

Servos are very important and we plan on doing something for them. Finally, someone developing faster that GHI can provide offers. Lol

Did you scope the pin?


#10

@ Gus,

I’m not clear on what you mean by “scope the pin,” but my full code is listed at the top of the thread…

Is that another iPhone typo? Should “gone” be “good”? :wink:


#11

Yeah no laptop so iPhone is “helping” me with spelling.

I mean scope the pin so you can see if you have the correct pulse size.


#12

@ Gus

Ah! Now I understand. Unfortunately, I don’t currently have access to an oscilloscope or logic analyzer, something I will probably remedy eventually. I should probably check ebay and/or craigslist and see if maybe I could pick up something used at a reasonable price.


#13

Using the PDF Pete helpfully supplied, I wired up an external 9V battery, and now the servo works! Woohoo!

Here’s a pic…unfortunately, the jumper colors somewhat obscure what’s doing what, but I don’t have a large supply of jumper wires just yet, so I’m kinda limited on color choice. :o

I’m going to download Fritzing and try my hand at creating a better illustration of how I have this wired up, in case anyone else needs to breadboard a servo with the Spider or other Gadgeteer board.

Note - I’m using a 9V battery for convenience, but it would be better to use a 6V battery pack or regulated PS.


#14

Fritzing diagram…this is my first effort at drawing something out using Fritzing, so any tips from the pros are welcome:


#15

Congrats! Looks good.

BTW, you might want to check out the DSO Nano. I’m considering getting one to use until such time as I can afford a nice bench model. It’s $100 & it’s OSS/OSH. Good deals on used bench scopes on eBay are hard to come by…


#16

@ Ian

I think I might just have to put the DSO Nano on my Christmas list. I’ve been spending way too much on electronic tools and toys lately, so perhaps if I let my wife buy this one, I can get away with it more easily. :slight_smile:

I’ve added a potentiometer module to the rig to control the position of the servo, and it’s working great. Will post the code on the wiki, hopefully tomorrow.

Any idea how hard it would be to create custom parts in Fritzing for things like the Extender Module? I tried to start one earlier tonight but quickly got over my head, as I have no idea how to represent it in schematic view, much less PCB view.


#17

One last thing I have to add, for any R/C geeks on the forums…having finally gotten the Parallax servo working, I just had to break out my old (as in 20+ years old…I bought it when I was in college) Futuba radio and servos from an old glider I built back in the day. I crashed the glider, but hung onto all the servos and such, since they were still worth keeping.

Well, after 20+ years sitting on a shelf in one house or another, I plugged in the charger, charged up the battery for the transmitter and receiver, and darned if they don’t still work just fine! I don’t know that I’d want to use them to fly a model aircraft without getting replacement batteries, but that is quite a pleasant surprise for batteries and equipment that old. :slight_smile:

So kudos to Futuba for quality and longevity!


#18

Same plan…the Nano is at the top of my birthday list in January :wink: BTW, just saw this… Save another 20% :slight_smile:

Architect can probably better speak to creating Fritzing parts. The best thing to do is open up the Panda parts he created in the part editor and check it out. Unfortunately, Fritzing doesn’t allow the type of modeling of parts that I would like. So, currently all you can do is upload images and place pins on them. The 3D parts Architect created in SketchUp would be a great place to get the images. Most parts we use (modules, mainboards, etc.) are just going to be rectangles with pins around them in the schematic view. For the PCB view, they’ll be basically the same except the shape should match the actual top-view shape of the part as it will be placed on a PCB with the pins in their actual positions. But I don’t think you have to be 100% obligated to completing all three views. I personally would be thrilled just to have breadboard views completed for all the modules first. Then we could supplement the other views as need and time allows. Uploading a photo of the part into breadboard view and placing pins on it is a great start. That can be done quickly. However, the schematic view of the Extender is very simple. It would basically be a square with 10 “connectors” (pins) coming in on one side, 10 connectors going out on the opposite side and 10 connectors going out on the bottom side. You should read over the Fritzing part guidelines before starting but they’re fairly obvious by looking at existing parts.


#19

I created a snippet for the code here:

http://code.tinyclr.com/project/405/servo-control-with-the-gadgeteer-extender-module/

Is there a way to edit code submissions? I tried to add my Fritzing diagram as the image for the snippet, but it ended up as a tiny thumbnail that isn’t much use in terms of helping folks actually use the code…I’d like to add the image as an attachment…can someone from GHI help me with that?


#20

No there is no way to add nice images on coder. Wiki is more suitable for that.