百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gpio

> 编程语言
开源

跟你的单板电脑的克皮奥针说话

393 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

跟你的单板电脑的克皮奥针说话

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

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