.Net Gadgeteer; Servo Connection

A few days ago I showed how to hook up Sparkfun’s Bluesmirf modules. Today, I will show how to connect a servo to .Net Gadgeteer.

To determine which sockets are capable of PWM you can consult the GHI Gadgeteer site. There is a useful diagram there of the socket mapping:
As you can see the sockets with a “P” have PWM (this would be sockets 8,11). And on these socket’s pins 7,8,9 are the PWM pins. Code below better illustrates this.

The servo I am using an older micro servo, Cirrus cs-21bb, but this should work with most servos.

The pin connections to the server are very simple:

  • The servos ground wire (black ) is connected to the ground of your 5v external power source. And be sure to also connect ground to the Gedgeteer’s ground pin on the Extender Module.
  • The servos power wire (red ) is connected to your external power source’s positive(+).
  • The servos control wire (white) is connected to the Gadgeteer’s PWM output pin which is pin 7,8, or 9.

Here is a close up of the Extender Module wired to the servo:

As you can see the breadboards power rail is powered seperately from the Gadgeteer but the grounds are common. It is important that the grounds be common.

And here is a broader view of the set up:

Here is a code snippet:

      GT.Interfaces.PWMOutput servo = this.extender.SetupPWMOutput(GT.Socket.Pin.Seven);//must be pin 7,8,9
      servo.Active = true;
      while (1 == 1)
      {
         //full range of Cirrus cs-21bb servo, hightime range 700-2000
          for (UInt32 hightime = 700; hightime <= 2000; hightime += 72)          
           {
              servo.SetPulse(20 * 1000 * 1000, hightime * 1000);
              Debug.Print("High Time= " + hightime.ToString());
              System.Threading.Thread.Sleep(100);
          }
      }

And that is all there is to it. The class above will move the servo through a range and repeat. Enjoy.

Advertisements

10 thoughts on “.Net Gadgeteer; Servo Connection

  1. Nice writeup…wish I’d found this last night. I was struggling with making some FEZ panda servo example code work with Gadgeteer. Turned out that my big problem was trying to power the servo straight off the extender module, rather than from external power.

    Maybe the FEZ Panda provides more current, but those examples showed hooking directly into the 5V and GND on the board itself. Learned a bunch in the process, though.

  2. Great article, thanks for sharing!

    I’m excited to learn I can drive up to six servos using the basic FEZ Spider with 2 extender modules, without any extra hardware!

    Cheers!

  3. Hello,

    One noob question. Why do you need to connect Gadgeteer ground to external power source ground? What happens if you don’t do that?
    What if you have two different power sources (for two motors)?

    • Its a great question.

      The extender module is extending your Gadgeteer into other circuits. So there are a few issues to consider here. The main issue in this case is servo noise. Servos are very noise (all DC motors are). Without a common ground, noise will travel back through the signal wire (white wire) and into your MCU (Gadgeteer Mainboard) or into other modules. When you fail to connect everything to a common ground, what you will usually experience is a MCU that shuts down or you might get noise in other signals. Its *usually* harmless but the program will stop running most often. If the difference in potential is great enough there is a risk of shock and circuit damage.

      Basically, having a single power source with a common ground is a good idea. Capacitors across noisy circuits is also a good idea. Finding the right size of cap is more of an art however. For instance, the Sanyo IR range sensors can be noisy. Putting a 35uf cap across + and- can stop spikes from inducing noise.

      There is much more to be said on this topic. I hope I answered your question.
      http://en.wikipedia.org/wiki/Ground_loop_(electricity)

      • Wow, thank you for you long reply. It is very helpful. But I still have one shot question. If I have two servo motors, each connected to own power source.
        1. If I use one extender module. May I connect ground from extender module with ground of first power source and secound power source?
        2. May I use two extender modules and on first connect ground of first motor power source and secound on other motor power source, or I need to connect all grounds (from power source 1, power source 2 and microcontroler) together?

        And thank you again for your help

      • In the case of two servos you will want each servo’s ground and the MCU (Gadgeteer mainboard) to all share a common ground.
        Each extender module (all modules really) share the same ground with the MCU. So as long as you connect each servo’s ground to the extender module’s ground you will be good to go. By connecting everything to the extender’s ground you close the loop, driving everything to a common ground.

        1.) Yes. I assume you are using regulated DC power sources.
        2.) Yes. As I explained above, the ground on each extender module is common with the MCU and all modules.

      • I just realized you had an “OR” in your second question…so yes is a confusing answer. 🙂
        Let me clarify, Yes, you can just connect the servo and its ground to the extender’s ground. You don’t need to connect each power sources ground together because connecting to the Gadgeteer’s extender’s ground you are effectively doing that already. I hope that makes sense.

        Hmm, this sounds like something I should write a while post about. Thanks again for the questions.

  4. Pingback: .net Gadgeteer Servo | Tommy Dykes | Designer Maker

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s