rpigpior

R for Raspberry Pi with GPIO support

https://github.com/mnr/rpigpior

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.7%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

R for Raspberry Pi with GPIO support

Basic Info
Statistics
  • Stars: 19
  • Watchers: 2
  • Forks: 1
  • Open Issues: 4
  • Releases: 0
Created almost 9 years ago · Last pushed about 2 years ago
Metadata Files
Readme Changelog Contributing Funding License Code of conduct Codemeta

README.Rmd

---
output: github_document
editor_options: 
  markdown: 
    wrap: 72
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# rpigpior





[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)

[![R-CMD-check](https://github.com/mnr/rpigpior/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mnr/rpigpior/actions/workflows/R-CMD-check.yaml)



`rpigpior` allows the R programming language access to the Raspberry Pi
GPIO using libgpiod. Because libgpiod is already included in Raspbian,
there is nothing else to install.

`rpigpior` provides these tools:

-   `is.rpi` - Returns TRUE if this code is running under Raspbian
-   `rpi_get` - Returns the value of a board level pin (1-40) or an
    error if the pin isn't a data line (3.3v, 5v, or GROUND)
-   `rpi_set` - Sets a pin to on or off
-   `rpi_monitor` - watches a pin for a number of rising or falling
    events
-   `rpi_pwm` - provides diagnostics and support for hardware pulse
    width modulation
-   `rpi_i2c_get` - retrieve a value from an i2c connection
-   `rpi_i2c_set` - set an i2c register to a value

## Installation

`rpigpior` is hosted on github. Until it arrives at cran, you can
install the development version of rpigpior from
[GitHub](https://github.com/mnr/rpigpior) with:

``` r
library(remotes)
remotes::install_github("mnr/rpigpior")
```

Most documentation will tell you to use devtools, but
`install.packages("devtools")` on a Raspberry Pi is an onerous task.

*However*...if you installed R on your Raspberry Pi using
[r4pi](https://r4pi.org/), you can use devtools just like normal.

``` r
# Start R with "sudo R" to install packages
# install.packages("devtools")

# You might want to switch back to non-admin R
library(devtools)
install_github("mnr/rpigpior")
```

Once you've installed, use `library` just like any other R package:

``` r
library(rpigpior)
```

## Is this a Raspberry Pi?

It's helpful to check if your code is running on a Raspberry Pi.

``` r
if ( is.rpi() ) {
   print("Yes, this is a RPi")
} else {
   print ("No, this is not a RPi")
}
```

## Reading a pin

If you connect a switch to board pin 40, this code will read it:

``` r
library(rpigpior)

rpi_get(40) # reads board pin 40
rpi_get(c(7,40)) # reads board pins 7 and 40

> GPIO004  GPIO21
        0       1
```

That assumes the switch to board pin 40 is "pushed" or closed. By the
way, there is a diagram of this located in the *articles* section of the
website (as identified in the package description)

## Turning pins on and off

If you have a LEDs connected to board pin 19, 21, and 23, this code will
turn them on, then one of them off, then all of them off

```         
library(rpigpior)

toggleThese <- c(19,21,23)
rpi_set(toggleThese,1)
Sys.sleep(1)
rpi_set(toggleThese, c(1,0,1))
Sys.sleep(1)
rpi_set(toggleThese, 0)
```

## Citation:

```{r}
citation("rpigpior")
```

## Related notes:

[Related mailing list:
linux-gpio\@vger.kernal.org](https://www.spinics.net/lists/linux-gpio/)

Owner

  • Name: Mark Niemann-Ross
  • Login: mnr
  • Kind: user
  • Location: Portland, OR
  • Company: lynda.com -> LinkedIn Learning -> Microsoft

I write fiction and teach courses in R, Raspberry Pi, and SQL for LinkedIn Learning

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "rpigpior",
  "description": "This provides R with access to the Raspberry Pi General Purpose Input Output (GPIO) via 'libgpiod'. This includes detecting a gpio chip as well as turning pins on and off via [gpioset()] and reading the state of pins via [gpioget()]. No additional libraries need to be installed; Raspbian includes 'libgpiod' as part of the standard installation.",
  "name": "rpigpior: Provides R with Access to the Raspberry Pi",
  "relatedLink": "https://mnr.github.io/rpigpior/",
  "codeRepository": "https://github.com/mnr/rpigpior",
  "issueTracker": "https://github.com/mnr/rpigpior/issues",
  "license": "https://spdx.org/licenses/MIT",
  "version": "0.1.0",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.2.3 (2023-03-15)",
  "author": [
    {
      "@type": "Person",
      "givenName": "Mark",
      "familyName": "Niemann-Ross",
      "email": "mark@niemannross.com",
      "@id": "https://orcid.org/0000-0002-3381-4604"
    }
  ],
  "copyrightHolder": [
    {
      "@type": "Person",
      "givenName": "Mark",
      "familyName": "Niemann-Ross",
      "email": "mark@niemannross.com",
      "@id": "https://orcid.org/0000-0002-3381-4604"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Mark",
      "familyName": "Niemann-Ross",
      "email": "mark@niemannross.com",
      "@id": "https://orcid.org/0000-0002-3381-4604"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "version": ">= 3.0.0",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "R",
      "name": "R",
      "version": ">= 2.10"
    },
    "SystemRequirements": null
  },
  "fileSize": "731.612KB",
  "releaseNotes": "https://github.com/mnr/rpigpior/blob/master/NEWS.md",
  "readme": "https://github.com/mnr/rpigpior/blob/master/README.md",
  "contIntegration": "https://github.com/mnr/rpigpior/actions/workflows/R-CMD-check.yaml",
  "developmentStatus": "https://www.repostatus.org/#active"
}

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1