knitr::opts_chunk$set(echo = TRUE)
Control your Raspberry Pi's servo from R.
Note: This package and README was only tested with the SG90 servo motor.
Acknowledgments: This package imports the gpiozero Python library.
r2servo
is currently only available as a GitHub package.
To install it run the following from an R console:
if (!require("remotes")) { install.packages("remotes") } remotes::install_github("jcrodriguez1989/r2servo", dependencies = TRUE)
Please make sure that your servo is correctly connected to your Raspberry Pi. Take note to which GPIO pin is your servo connected.
In this example, the servo is connected to the GPIO14 pin:
# Load the library. library("r2servo") # Get a servo instance (by default, the initial position is 0, i.e. middle). servo <- get_servo(14) # Read the actual position (should be 0). get_position(servo) # Move it to its maximum position (1). set_position(servo, 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.