{"id":17855645,"url":"https://github.com/nebrius/raspi-pwm","last_synced_at":"2025-09-20T22:32:53.109Z","repository":{"id":23871165,"uuid":"27249877","full_name":"nebrius/raspi-pwm","owner":"nebrius","description":"Provides access to PWM on the Raspberry Pi from Node.js","archived":false,"fork":false,"pushed_at":"2021-10-11T15:59:30.000Z","size":75,"stargazers_count":26,"open_issues_count":1,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-29T18:03:10.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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-28T03:13:18.000Z","updated_at":"2024-09-15T14:14:00.000Z","dependencies_parsed_at":"2022-09-07T10:41:42.545Z","dependency_job_id":null,"html_url":"https://github.com/nebrius/raspi-pwm","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-pwm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-pwm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-pwm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nebrius%2Fraspi-pwm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nebrius","download_url":"https://codeload.github.com/nebrius/raspi-pwm/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:54.413Z","updated_at":"2025-09-20T22:32:47.822Z","avatar_url":"https://github.com/nebrius.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"Raspi PWM\n==========\n\n**NOTICE: This package has been deprecated in favor of [raspi-soft-pwm](https://github.com/nebrius/raspi-soft-pwm)**\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\nRaspi PWM is part of the [Raspi.js suite](https://github.com/nebrius/raspi) that provides access to the hardware PWM.\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## 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.4.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## Installation\n\nFirst, be sure that you have installed [raspi](https://github.com/nebrius/raspi).\n\nInstall with npm:\n\n```sh\nnpm install raspi-pwm\n```\n\n**Note:** this project is written in [TypeScript](http://www.typescriptlang.org/) and includes type definitions in the package.json file. This means that if you want to use it from TypeScript, you don't need to install a separate @types module.\n\n## Example Usage\n\nIn TypeScript/ES6:\n\n```TypeScript\nimport { init } from 'raspi';\nimport { PWM } from 'raspi-pwm';\n\ninit(() =\u003e {\n  const led = new PWM('P1-12');\n  led.write(0.5); // 50% Duty Cycle, half brightness\n});\n```\n\nIn JavaScript:\n\n```JavaScript\nconst raspi = require('raspi');\nconst pwm = require('raspi-pwm');\n\nraspi.init(() =\u003e {\n  const led = new pwm.PWM('P1-12');\n  led.write(0.5); // 50% Duty Cycle, aka half brightness\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## PWM ports\n\nRaspberry Pi Model B Rev 2 and older versions of the Raspberry Pi only expose one PWM port on pin `P1-12`, so be sure to always use that port (or leave it as the default). The Raspberry Pi Model B+ and newer exposes two PWM ports.\n\nOn newer Raspberry Pi's, these two PWM ports can be accessed via four different pins. `PWM0` can be accessed on either pin `P1-12` _or_ `P1-32`, and `PWM1` can be accessed on either pin `P1-33` _or_ `P1-35`. Each PWM _cannot_ be accessed on both pins though.\n\nIf you try to run the following code, which initializes both PWM0 ports,  _you will get an exception_.\n\n```JavaScript\nconst raspi = require('raspi');\nconst pwm = require('raspi-pwm');\n\nraspi.init(() =\u003e {\n  const led1 = new pwm.PWM('P1-12');\n  const led2 = new pwm.PWM('P1-32');\n});\n```\n\n## API\n\n### new PWM(config)\n\nInstantiates a new PWM instance on the given pin. Note that PWM is limited to only 1 pin on the Model A/B and 2 pins on the A+/B+/2/Zero. On the A/B, the PWM pin is exposed on `GPIO18`. The A+/B+/2 is a little more complicated. The first PWM is exposed on two pins, `GPIO18` and `GPIO12`. This PWM can only be active on one of these pins at a time, however, so choose carefully. The second PWM pin on the A+/B+/2/Zero is exposed on `GPIO19`. Check the [wiring information wiki](https://github.com/nebrius/raspi-io/wiki) for more information.\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\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\u003econfig (optional)\u003c/td\u003e\n    \u003ctd\u003eNumber | String | Object\u003c/td\u003e\n    \u003ctd\u003eThe configuration for the PWM pin. If the config is a number or string, it is assumed to be the pin number for the peripheral. If it is an object, the following properties are supported:\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd colspan=\"2\"\u003e\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\u003epin (optional)\u003c/td\u003e\n          \u003ctd\u003eNumber | String\u003c/td\u003e\n          \u003ctd\u003eThe pin number or descriptor for the peripheral. Defaults to 1 (GPIO18, PWM0).\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n          \u003ctd\u003efrequency (optional)\u003c/td\u003e\n          \u003ctd\u003eNumber\u003c/td\u003e\n          \u003ctd\u003eThe frequency, in Hz, of the PWM signal. Defaults to 50.\u003c/td\u003e\n        \u003c/tr\u003e\n      \u003c/table\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### Instance Properties\n\n#### frequency\n\nA number representing the frequency initialization value, in Hz. If a value for `frequency` was passed to the constructor, it is reflected back here. If no value for `frequency` was passed to the constructor, then this reflects the default frequency value of `50`.\n\n#### dutyCycle\n\nA number representing the last written dutyCycle. If this property is read before a value is written, `0` is returned.\n\n### Instance Methods\n\n#### write(dutyCycle)\n\nSets the duty cycle for the PWM output, a floating point value between 0 and 1.\n\n_Arguments_:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eArgument\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\u003edutyCycle\u003c/td\u003e\n    \u003ctd\u003eNumber\u003c/td\u003e\n    \u003ctd\u003eThe duty cycle for the PWM to set, must be a floating point number between 0 and 1\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n_Returns_: None\n\n**Note:** The PWM does not start outputting a signal until write is called for the first time.\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-pwm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnebrius%2Fraspi-pwm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnebrius%2Fraspi-pwm/lists"}