Mark Niemann-Ross * mark@niemannross.com
|>
R*aspberry[pi]
!!
Raspberry Pi Model 4
Linux / Python
~ $45 USD (depending on model)
consumes ~3-6 watts
USB, HDMI, Ethernet, GPIO, camera port, display port, audio
Configuring geany for R
Saved as “hello_world.R”
opens terminal. Plot is created as PDF next to program
Geany terminal can be used to run R
enter Geany terminal, then type R to start R
sudo to install packages
Other libraries:
One of many libraries for GPIO access
sudo apt-get install libgpiod-dev gpiod
# assign buttons
TRYME_btn <- 21 # BCM numbering scheme
while (TRUE) {
getGPIOcmd <- paste("gpioget -l gpiochip0", TRYME_btn)
if (system(getGPIOcmd, intern = TRUE) == 0) print("Try Me!")
} # control-Z stops the loop1 Available on github as hello_gpio.r
https://github.com/mnr/R-for-Data-Science-Lunchbreak-Lessons/blob/7b7ce391ac36db029b6820847c9102579fc48682/2023%20cascade%20R%20and%20RPi/hello_gpio.R
# assign buttons (use BCM - not board)
getGPIOcmd <- "gpioget gpiochip0 21"
# assign control pin (use BCM)
setGPIOcmd_on <- "gpioset gpiochip0 9=1"
setGPIOcmd_off <- "gpioset gpiochip0 9=0"
while (TRUE) {
if (system(getGPIOcmd, intern=TRUE) == 1) print ("Try Me!")
system(setGPIOcmd_on)
Sys.sleep(1)
system(setGPIOcmd_off)
Sys.sleep(3)
}1 Saved as hello_gpio_control.R
https://github.com/mnr/R-for-Data-Science-Lunchbreak-Lessons/blob/7b7ce391ac36db029b6820847c9102579fc48682/2023%20cascade%20R%20and%20RPi/hello_gpio_control.R
Problem: Drivers for circuits are written in other languages.
Solution: R works with other languages
rcpp for C
reticulate for python