-
Notifications
You must be signed in to change notification settings - Fork 5
Class: ServoPi
This class contains methods for use with the ServoPi and Servo PWM Pi Zero from
https://www.abelectronics.co.uk/p/72/Servo-PWM-Pi-Zero
Connect()
Connect to the I2C device
Parameters: none
Returns: null
IsConnected()
Check if the device is connected
Parameters: none
Returns: boolean
Dispose()
Dispose of the active I2C device
Parameters: none
Returns: null
SetPwmFreq(freq)
Set the PWM frequency
Parameters: freq - required frequency
Returns: null
SetPwm(channel, on, off)
Set the output on single channels
Parameters: channel - 1 to 16, on - time period, off - time period
Returns: null
SetAllPwm( on, off)
Set the output on all channels
Parameters: on - time period, off - time period
Returns: null
byte OutputEnablePin { get; set; }
Parameters: Set the GPIO pin for the output enable function.
Returns: null
Notes: The default GPIO pin 4 is not supported in Windows 10 IOT so the OE pad will need to be connected to a different GPIO pin.
OutputDisable()
Disable the output via OE pin
Parameters: null
Returns: null
OutputEnable()
Enable the output via OE pin
Parameters: null
Returns: null
To use the ServoPi Pi library in your code you must first import the library dll:
using ABElectronics_Win10IOT_Libraries;
Next you must initialise the ServoPi class:
ABElectronics_Win10IOT_Libraries.ServoPi servo = new ABElectronics_Win10IOT_Libraries.ServoPi(0x40);
The argument is the I2C addresses of the Servo Pi chip.
Next we need to connect to the device and wait for the connection
servo.Connect();
while (!servo.IsConnected)
{
}
Set PWM frequency to 60 Hz and enable the output
servo.SetPWMFreqency(60);
Optional You can set the enable pin to use the output enable functions and the enable and disable the output. The default GPIO pin 4 is not supported in Windows 10 IOT and so the OE pad will need to be connected to a different GPIO pin to use this functionality.
servo.OutputEnablePin(17); // set to GPIO pin 17
servo.OutputEnable();
Move the servo to a position and exit the application.
servo.SetPWM(1, 0, 300);