0
0

Raspberry Pi GPIO Quick Start

Last updated at Posted at 2024-05-04

(自分メモ)
ラズパイのI/O操作サンプル。

環境

  • Raspberry Pi 4
  • Ubuntu 20.04
  • Node.js 22

Javascript Project準備

npm init -y
npm i node-web-gpio

I/O操作

main.js - サンプルコード
const { requestGPIOAccess } = require("node-web-gpio");
const { promisify } = require("util");
const sleep = promisify(setTimeout);

async function main() {
  const gpioAccess = await requestGPIOAccess();
  const port = gpioAccess.ports.get(26);

  await port.export("out");

  for (;;) {
    await port.write(1);
    await sleep(1000);
    await port.write(0);
    await sleep(1000);
  }
}

main()

Build/Run

npm i
sudo node main.js

GPIO 26は37番ピン

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0