{"id":15043665,"url":"https://github.com/nebrius/raspi-llio","last_synced_at":"2025-04-14T23:12:30.162Z","repository":{"id":21559027,"uuid":"24878774","full_name":"nebrius/raspi-llio","owner":"nebrius","description":"Provides Node.js bindings to the WiringPi library for controlling a Raspberry Pi's I/O","archived":false,"fork":false,"pushed_at":"2016-01-13T23:32:21.000Z","size":27,"stargazers_count":16,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T23:12:14.184Z","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":null,"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":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-07T06:05:57.000Z","updated_at":"2020-12-16T16:34:41.000Z","dependencies_parsed_at":"2022-08-21T18:20:58.771Z","dependency_job_id":null,"html_url":"https://github.com/nebrius/raspi-llio","commit_stats":null,"previous_names":["bryan-m-hughes/raspi-llio"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-llio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-llio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-llio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-llio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nebrius","download_url":"https://codeload.github.com/nebrius/raspi-llio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975329,"owners_count":21192210,"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-09-24T20:49:24.245Z","updated_at":"2025-04-14T23:12:30.124Z","avatar_url":"https://github.com/nebrius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Raspberry Pi Low Level IO\n=========================\n\n[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)\n\n**WARNING** This module has been _deprecated_ in favor of [Raspi.js](https://github.com/nebrius/raspi). Raspi.js uses a more advanced mechanism for managing peripherals, and is considerably more performant. Bugs will not be fixed in this module.\n\nThe raspi-llio (Low Level Input/Output) module exposes the [Wiring Pi](http://wiringpi.com/) C library to Node.js, which\nprovides access to GPIO, PWM, I2C, SPI, and UART capabilities. For more in depth information on how raspi-llio works,\nvisit the Wiring Pi docs. All methods in this library map directly to a Wiring Pi method. Many of the methods are wrapped\nup in an object that must first be instantiated and handles file descriptors transparently.\n\n# Installation\n\nBefore using raspi-llio, you must install the Wiring Pi library on your Raspberry Pi:\n\n```\ngit clone git://git.drogon.net/wiringPi\ncd wiringPi\n./build\n```\n\nOnce that is done:\n\n```\nnpm install raspi-llio\n```\n\n# API\n\n## Root Namespace\n\nThe raspi-llio module consists of four namespaces, GPIO, I2C, PWM, and a single method ```getBoardRev```:\n\n### getBoardRev\n\nThe ```getBoardRev``` method takes no parameters and returns either 1 or 2, indicating if this is a Raspberry Pi Model B\nrev 1 or 2.\n\n## GPIO\n\nUsing GPIO is straightforward, just create an instance of a pin and call ```digitalWrite``` or ```digitalRead```:\n\n```javascript\nvar raspi = require('raspi-llio');\n\nvar pin7 = new raspi.GPIO(7, raspi.GPIO.OUTPUT);\nvar pin11 = new raspi.GPIO(11, raspi.GPIO.INPUT);\n\nconsole.log(pin11.digitalRead() == raspi.GPIO.LOW); // Prints true\npin7.digitalWrite(raspi.GPIO.HIGH);\nconsole.log(pin11.digitalRead() == raspi.GPIO.HIGH); // Prints true\n```\n\n### new _constructor_(pin, mode, [pullUpDown])\n\nInstantiates a new GPIO pin instance.\n\n#### Parameters:\n\n- pin (_number_)\n    - The pin number, as numbered on the P1 header\n- mode (```raspi.GPIO.INPUT, raspi.GPIO.OUTPUT```)\n    - The mode for the pin\n- pullUpDown (```raspi.GPIO.PUD_OFF, raspi.GPIO.PUD_DOWN, raspi.GPIO.PUD_UP```) Optional.\n    - Enables a pull up or pull down resistor on the pin\n\n## GPIO Instances\n\n### value digitalRead()\n\nReads the value on the pin and returns either ```raspi.GPIO.LOW``` or ```raspi.GPIO.HIGH```. Only valid when the pin mode\nis ```INPUT```.\n\n### digitalWrite(value)\n\nThe digital write method takes one parameter, either ```raspi.GPIO.LOW``` or ```raspi.GPIO.HIGH``` and sets the pin value.\nOnly valid when the pin mode is ```OUTPUT```\n\n## PWM\n\nGenerating a PWM output works like GPIO; you first instantiate a PWM instance and then call ```pwmWrite```. To control a servo:\n\n```javascript\nvar raspi = require('raspi-llio');\n\nvar pwm = new raspi.PWM();\nraspi.PWM.setMode(0);\nraspi.PWM.setClockDivisor(400);\nraspi.PWM.setRange(1000);\n\nvar value = 40;\nsetInterval(function() {\n  if (value == 40) {\n    value = 90;\n  } else {\n    value = 40;\n  }\n  pwm.write(value);\n}, 2000);\n```\n\n**Important**: If you are driving a servo, the value should be between about 40 and 90 for 90 degree servos, and 20 and 110 for 180\ndegree servos. Make sure to test these values with your specific servo and make sure you aren't overdriving your servo,\nas this can also harm your Raspberry Pi. Also make sure that you have a good power supply because the 5V power\non the Raspberry Pi is notoriously fickle. If you see that your Raspberry Pi is being reset when trying to drive a sero,\nyou will need to either get a better power supply for your Raspberry Pi, or you will need to power the servo using an\nexternal source.\n\n### new _constructor_()\n\nInstantiates a new PWM channel instance.\n\n### setMode(mode)\n\nSets the PWM mode, must be one of ```raspi.PWM.PWM_MODE_MS``` or ```raspi.PWM.PWM_MODE_BAL```. See the [BCM2835 ARM Peripherals datasheet](http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf)\nfor more information.\n\n### setRange(range)\n\nSets the value of the PWM range register. See the [BCM2835 ARM Peripherals datasheet](http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf)\nfor more information.\n\n### setClockDivisor(divisor)\n\nSets the PWM clock divisor. See the [BCM2835 ARM Peripherals datasheet](http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf)\nfor more information.\n\n## PWM Instances\n\n### write(value)\n\nSets the PWM duty cycle to ```value / 1000```, assuming the default clock divisor and range.  The value should be between\n0 and the max PWM value. The max PWM value is set by ```raspi.PWM.setPwmRange()``` and defaults to 1024.\n\n## I2C\n\nInterfacing with I2C devices requires instantiating a new instance that represents an external device attached via I2C:\n\n```javascript\nvar raspi = require('raspi-llio');\n\nvar sensor = new raspi.I2C(0x18);\n\nsetInterval(function(){\n  console.log(sensor.readReg16(5));\n}, 500);\n```\n\nSome I2C devices work by being read from/written to directly. In these cases, use the ```read``` and ```write``` methods.\nMost devices are register based, however, so use the ```readRegX``` and ```writeRegX``` methods. Consult the data sheets\nfor the I2C device to determine which method is appropriate.\n\n**Note:** If you encounter a \"No such file or directory\" error when trying to use I2C peripherals, you may need to load the I2C driver from the command line with:\n\n```\ngpio load i2c\n```\n\n### new _constructor_(address)\n\nInstantiates a new I2C peripheral instance that corresponds to the device at the given address.\n\n## I2C Instances\n\n### data read()\n\nReads some data from the I2C peripheral. Blocks if there is nothing to read until something can be read.\n\n### write(data)\n\nWrites some data to the I2C peripheral.\n\n### writeReg8(register, data)\n\nWrites some data to an 8-bit register in the I2C peripheral.\n\n### writeReg16(register, data)\n\nWrites some data to a 16-bit register in the I2C peripheral.\n\n### data readReg8(register)\n\nReads some data from an 8-bit register in the I2C peripheral.\n\n### data readReg16(register)\n\nReads some data from a 16-bit register in the I2C peripheral.\n\n## SPI\n\nInterfacing with an SPI device requires instantiating an SPI instance representing an SPI channel at a certain speed:\n\n```javascript\nvar raspi = require('raspi-llio');\n\nvar spi = new raspi.SPI(0, 1000000); // Creates an SPI on channel 0 running at 1Mbps\nspi.readWrite('Hello World');\n```\n\n**Warning**: the SPI module is untested\n\n### new _constructor_(channel, speed)\n\nInstantiates a new SPI instance with the given channel, which must be 0 or 1, at the specified speed in bps, which must be\nbetween 500000 and 32000000.\n\n## SPI Instances\n\n### data_out readWrite(data_in)\n\nSimultaneously reads and writes data to/from the SPI device.\n\n**Note:** If you encounter a \"No such file or directory\" error when trying to use SPI peripherals, you may need to load the SPI driver from the command line with:\n\n```\ngpio load spi\n```\n\n## UART\n\nInterfacing with a UART-compatible device (i.e. TTY devices) requires instantiating a UART instance for a device at a given BAUD rate.\n\n```javascript\nvar raspi = require('raspi-llio');\n\nvar uart = new raspi.UART('/dev/ttyAMA0', 115200);\nsetInterval(function() {\n  var data = '';\n  while (uart.dataAvailable()) {\n    data += uart.getCharacter();\n  };\n  if (data) {\n    console.log(data);\n  }\n}, 500);\n```\n\n**Warning**: the UART module is untested\n\n### new _constructor_(device, baud)\n\nInstantiates a UART instance for the given device (e.g. ```/dev/tty0```) at a given BAUD rate, which must be a positive integer.\n\n## UART Instances\n\n### write(data)\n\nWrites the given string to the UART device.\n\n### amount dataAvailable()\n\nReturns the number of characters available for reading.\n\n### char getCharacter()\n\nGets a single character from the device. Blocks for up to 10 seconds before throwing an error if no data is available.\n\n### flush()\n\nFlushes the serial device.\n\n## Further Reading\n\nYou may also be interested in the [Raspi IO](https://github.com/bryan-m-hughes/raspi-io) library, which provides a more abstract API that is compatible with [Johnny-Five](https://github.com/rwaldron/johnny-five).\n\nLicense\n=======\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 Bryan Hughes \u003cbryan@theoreticalideations.com\u003e\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the 'Software'), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Fraspi-llio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnebrius%2Fraspi-llio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Fraspi-llio/lists"}