{"id":17855606,"url":"https://github.com/nebrius/raspi-peripheral","last_synced_at":"2025-09-20T22:32:57.887Z","repository":{"id":23601227,"uuid":"26970078","full_name":"nebrius/raspi-peripheral","owner":"nebrius","description":"Provides a base class and pin management functions for the raspi suite","archived":false,"fork":false,"pushed_at":"2019-10-05T18:22:29.000Z","size":85,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-28T08:15:41.311Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nebrius.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-21T17:24:07.000Z","updated_at":"2022-11-04T16:07:27.000Z","dependencies_parsed_at":"2022-08-17T22:15:12.664Z","dependency_job_id":null,"html_url":"https://github.com/nebrius/raspi-peripheral","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-peripheral","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-peripheral/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-peripheral/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-peripheral/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nebrius","download_url":"https://codeload.github.com/nebrius/raspi-peripheral/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233682445,"owners_count":18713552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-28T02:23:46.581Z","updated_at":"2025-09-20T22:32:52.609Z","avatar_url":"https://github.com/nebrius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Raspi Peripheral\n================\n\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nebrius/raspi-io?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Build Status](https://travis-ci.org/nebrius/raspi-peripheral.svg?branch=master)](https://travis-ci.org/nebrius/raspi-peripheral)\n[![Coverage Status](https://coveralls.io/repos/github/nebrius/raspi-peripheral/badge.svg?branch=master)](https://coveralls.io/github/nebrius/raspi-peripheral?branch=master)\n\nRaspi Peripheral is part of the [Raspi.js suite](https://github.com/nebrius/raspi) and provides the base class for other Raspi peripherals. Peripherals for use within the Raspi ecosystem should extend this base class. This class provides management of pins and ensures that only one peripheral can be active on any given pin at one time.\n\nIf you have a bug report, feature request, or wish to contribute code, please be sure to check out the [Raspi IO Contributing Guide](https://github.com/nebrius/raspi-io/blob/master/CONTRIBUTING.md).\n\n**Warning:** This package is not intended to be used directly!\n\n## System Requirements\n\n- Raspberry Pi Model B Rev 1 or newer (sorry Model A users)\n- Raspbian Jessie or newer\n  - [Node-RED](http://nodered.org/) works, but can be finicky and difficult to debug.\n  - See https://github.com/nebrius/raspi-io/issues/24 for more info about support for other OSes\n- Node 6.0.0 or newer\n\nDetailed instructions for getting a Raspberry Pi ready for NodeBots, including how to install Node.js, can be found in the [wiki](https://github.com/nebrius/raspi-io/wiki/Getting-a-Raspberry-Pi-ready-for-NodeBots)\n\n**Warning:** when using this module, it MUST be installed with user-level permissions, but run with root permissions (e.g. `sudo node index.js`).\n\n## Installation\n\nInstall with npm:\n\n```Shell\nnpm install raspi-peripheral\n```\n\n## Example\n\n```JavaScript\nimport { Peripheral } from 'raspi-peripheral';\n\nclass MyPeripheral extends Peripheral {\n  write(value) {\n    if (this.alive) {\n      // Do stuff\n    }\n  }\n}\n```\n\nRaspi Peripheral is written in TypeScript, so writing your peripheral in TypeScript or ECMAScript 2015 is easiest, but you can also do it in ECMAScript 5:\n\n```JavaScript\nvar Peripheral = require('raspi-peripheral').Peripheral;\n\nfunction MyPeripheral(pin) {\n  Peripheral.call(this, pin);\n}\nutil.inherits(MyPeripheral, Peripheral);\n\nMyPeripheral.prototype.write = function(value) {\n  if (this.alive) {\n    // Do stuff\n  }\n};\n```\n\n## Pin Naming\n\nThe pins on the Raspberry Pi are a little complicated. There are multiple headers on some Raspberry Pis with extra pins, and the pin numbers are not consistent between Raspberry Pi board versions.\n\nTo help make it easier, you can specify pins in three ways. The first is to specify the pin by function, e.g. ```'GPIO18'```. The second way is to specify by pin number, which is specified in the form \"P[header]-[pin]\", e.g. ```'P1-7'```. The final way is specify the [Wiring Pi virtual pin number](http://wiringpi.com/pins/), e.g. ```7```. If you specify a number instead of a string, it is assumed to be a Wiring Pi number.\n\nBe sure to read the [full list of pins](https://github.com/nebrius/raspi-io/wiki/Pin-Information) on the supported models of the Raspberry Pi.\n\n## API\n\n### new Peripheral(pins)\n\nThe base constructor must be called with a single argument, the pin or pins to use. If a number or string is passed in, it is assumed to be a single pin. If an array is passed in, each entry in the array is assumed to be a single pin.\n\n### Instance Properties\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eProperty\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctr\u003e\n    \u003ctd\u003epins (readonly)\u003c/td\u003e\n    \u003ctd\u003eArray\u003c/td\u003e\n    \u003ctd\u003eThe pins associated with this peripheral. This value is the normalized Wiring Pi pin number and may not be the same value that was passed to the constructor.\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ealive (readonly)\u003c/td\u003e\n    \u003ctd\u003eBoolean\u003c/td\u003e\n    \u003ctd\u003eWhether or not the pin is \"alive\". A pin is considered not alive when the application initialized a new peripheral on the same pin as this peripheral. You should always make sure to query \"alive\" before performing any operation inside your peripheral instance code.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### Instance Methods\n\n#### destroy()\n\nThis method \"destroys\" the pin. Destroying a pin sets the alive flag to false and emits a \"destroy\" event. The ```destroy``` method is automatically called whenever a new peripheral is initialized over another peripheral.\n\nIf you need to perform any cleanup in your peripheral code, you should listen for the \"destroy\" event in your peripheral's constructor.\n\nThis method _should not_ be called directly. The Peripheral base class will call this method automatically when a new peripheral is initialized over the old one.\n\n_Arguments_: None\n\n_Returns_: None\n\n#### validateAlive()\n\nThis method checks if the peripheral is alive or not. If the peripheral is not alive, it throws a handy exception.\n\n_Arguments_: None\n\n_Returns_: None\n\n## Example gulpfile for compiling to ECMAScript 6\n\nIf you want to use ECMAScript 6 for your peripheral, here is an example gulpfile:\n\n```JavaScript\nvar gulp = require('gulp');\nvar traceur = require('gulp-traceur');\nvar sourcemaps = require('gulp-sourcemaps');\nvar del = require('del');\n\ngulp.task('default', function() {\n  return gulp.src('index.js')\n    .pipe(sourcemaps.init())\n      .pipe(traceur({\n        modules: 'commonjs'\n      }))\n    .pipe(sourcemaps.write())\n    .pipe(gulp.dest('lib'));\n});\n\ngulp.task('clean', function(cb) {\n  del(['lib/index.js'], cb);\n});\n```\n\nThis gulpfile assumes you have a single source file called ```index.js```. Note that the traceur runtime is loaded automatically by the Raspi Peripheral module, so there is no need to do it in your module. Make sure to include the four modules required in this file in your package.json's ```dev-dependencies``` section.\n\nLicense\n=======\n\nThe MIT License (MIT)\n\nCopyright (c) 2014-2017 Bryan Hughes \u003cbryan@nebri.us\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Fraspi-peripheral","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnebrius%2Fraspi-peripheral","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Fraspi-peripheral/lists"}