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());
And that is all there is to it. The class above will move the servo through a range and repeat. Enjoy.
In the previous post, I discussed how to connect Gadgeteer to a Bluetooth module. What I didn’t explain was the header on the Extender Module. It may seem obvious to some but the reason the module in my picture has a header is because I soldered one on…even better I had a friend who is better at soldering do it for me.
Here is the Extender Module sans header:
You can buy headers from various electronics supply stores. Digikey, Mouser, or allelectronics which I include a link for simply because they have a picture available.
Here is what a header looks like:
I used a 90 degree header but straight would be fine too. Just depends on how you want the module to be oriented when in a breadboard.
Again here is what it looks like when finished:
.Net Gadgeteer is great because there are so many modules available already. But what about hardware modules not specifically built for Gadgeteer? Well, I want to show you how easy it is to connect a Bluetooth module to .Net Gadgeteer. Here I will be using Sparkfun’s Bluesmirf modules.
First you need to connect the pins correctly like this:
Extender with Bluetooth pin mapping
Next create a class in your .Net Gadgeteer project to encapsulate the Bluetooth functionality.
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.Interfaces;
/// A bluetooth module for Microsoft .NET Gadgeteer
public class Bluetooth : GTM.Module
public GTI.Serial serial;
public Bluetooth(int socketNumber)
Socket socket = Socket.GetSocket(socketNumber, true, this, null);
serial = new GTI.Serial(socket, 57600, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired, this);
byte tx = 0; ;
byte rx = 0; ;
serial.ReadTimeout = 50;
byte rx_byte = new byte;
byte i = 50;
int read_count = 0;
read_count = serial.Read(rx_byte, 0, 1);
if (read_count > 0)
char chars = Encoding.UTF8.GetChars(rx_byte);
string s = new string(chars);
Now you can create an instance similar to how you would any other module except you will need to pass in the socket number you are using. Here I am using socket 8. Any of the sockets with a “u” should work.
Gadgeteer.Modules.Mine.Bluetooth dm = new GTM.Mine.Bluetooth(8);
And that is all there is to it. The class above will just echo the input and is meant to just show how to use the serial send and receive commands and how to wire up a bluetooth module. Enjoy.
Update: There is now a .Net Gadgeteer bluetooth module available. http://www.ghielectronics.com/catalog/product/312