Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gpio

> 编程语言
Open source

Talk to your Single Board Computer's gpio pins

393 stars0 likes2 views
WebsiteGitHub

About

Talk to your Single Board Computer's gpio pins

gpio - talk to your Single Board Computer's gpio headers

Introduction

This plain JavaScript module is generic and only rely on system's sysfs.

Please consider other (more mature) gpio libraries out there which support better your hardware,

For instance, of you're looking for a reliable way to communicate with the Raspberry Pi using JavaScript, check out the wiring-pi JavaScript library. It provides direct bindings to the fully-featured Wiring Pi C library.

But if you want/need a generic lightweight module, this one can be used as fallback.

Support

Following hardware was reported to work (with some limitations or workarounds)

  • ARTIK10 (inputs' pull down resistors are enabled by default)
  • Raspberry Pi (use wiringpi's /usr/bin/gpio to change mode: gpio -g mode 11 up)

Installation

Get node.js for your SBC, If using Debian or deviates (Raspbian for RPi), you can simply run: sudo apt-get install nodejs

otherwise, install from node or compile it

Usage

This library is an npm package, just define "gpio" in your package.json dependencies or

javascript
npm install gpio

Note: you must be have proper privileges to access the GPIO headers (or run node as root).

Standard setup

…

Header direction IN

If you plan to set the header voltage externally, use direction in and read value from your program.

javascript
var gpio = require("gpio");
var gpio4 = gpio.export(4, {
   direction: gpio.DIRECTION.IN,
   ready: function() {
   }
});

API Methods

javascript
// sets pin to high
gpio4.set();
javascript
// sets pin to low (can also call gpio4.reset())
gpio4.set(0);
javascript
// Since setting a value happens asynchronously, this method also takes a
// callback argument which will get fired after the value is set
gpio4.set(function() {
   console.log(gpio4.value);    // should log 1
});
gpio4.set(0, function() {
   console.log(gpio4.value);    // should log 0
});
javascript
// unexport program when done
gpio4.unexport();

EventEmitter

This library uses node's EventEmitter which allows you to watch for value changes and fire a callback.

…

Example

Cycle voltage every half a second

…

References

Demos on Raspberry Pi:

  • Demo using LED: http://www.youtube.com/watch?v=2Juo-CJ6eu4
  • Demo using RC car: http://www.youtube.com/watch?v=klQdX8-YVaI
  • Source code here: https://github.com/EnotionZ/node-rc

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言