Snippet - Servo Control with the Gadgeteer Extender Module

[title]Servo Control with the Gadgeteer Extender Module[/title]
This is an example of code you can use to drive a 4-6V servo, using the FEZ Spider (or other .NET Gadgeteer mainboard) and the GHI Extender Module for .NET Gadgeteer.

The example code uses a timer to read the percentage value of a Potentiometer Module for input, and uses that to drive the servo based on observed minimum/maximum values. Actual values for your servo may vary from those listed here, so you may need to tweak the lowLimit and highLimit values.

Once the correct pulse value has been calculated, the timer sends the value via the PWMOutput class’ SetPulse method, which moves the servo to the correct position.

Note that I was not able to successfully power the servo directly from the module (either 3.3v or 5v), and the online documentation for the servo I’m using expressly warns against powering the servo from a microcontroller. I am powering the servo using an external 9v battery, and I’m including a diagram of the wiring for reference. Note that the 9v is more power than the servo is rated for, but the documentation indicates that this is fine. If you have a 6v power supply or battery pack, that might be a better option.

Links for more information:
Servo docs:
Helpful Servo articles (targeted at FEZ Panda, but still useful):