Pi GPIO for Node-RED

2.0.7 · active · verified Sun Apr 19

The node-red-node-pi-gpio package provides a set of Node-RED nodes for interacting with the General Purpose Input/Output (GPIO) pins of a Raspberry Pi. Utilizing the `RPi.GPIO` Python library, it enables flow-based control and monitoring of digital and Pulse Width Modulation (PWM) outputs, as well as digital inputs. The current stable version is 2.0.7. Releases appear to follow a milestone-based cadence rather than a strict schedule, with major version updates incorporating new features or significant changes. Key differentiators include built-in support for mouse and keyboard input detection and direct integration into the Node-RED visual programming environment, simplifying hardware interaction for IoT and automation projects on Raspberry Pi devices. It specifically notes an alternative, `node-red-node-pi-gpiod`, for more accurate servo control, indicating this package is better suited for general purpose digital and basic PWM applications.

Common errors

Warnings

Install

Imports

Quickstart

Describes the installation process and guides a user through creating a basic Node-RED flow with Pi GPIO Input, Output, and Debug/Inject nodes.

/*
  This quickstart demonstrates how to install 'node-red-node-pi-gpio' and describes a basic Node-RED flow setup.
  Since this is a Node-RED node package, direct JavaScript runtime usage is not applicable.
  The instructions guide you through setting up a simple input-to-debug and inject-to-output flow in the Node-RED editor.
*/

// Step 1: Install the Node-RED node package.
// You should run this command in your Node-RED user directory (typically ~/.node-red)
// or use the 'Manage Palette' option within the Node-RED editor.
console.log("Executing installation command:\n  npm i node-red-node-pi-gpio\n");

// After installation, restart Node-RED if prompted or if nodes do not appear in the palette.
console.log("Installation complete. If nodes are not visible, restart Node-RED (e.g., 'node-red-start').\n");

// Step 2: Configure a basic flow in the Node-RED editor (usually accessible at http://localhost:1880).
console.log("--- Node-RED Flow Configuration Guide ---");
console.log("1. Drag an 'rpi gpio in' node from the palette onto your flow canvas.");
console.log("   - Double-click the 'rpi gpio in' node: Select a BCM GPIO number (e.g., 4) and configure pull-up/down resistors if needed.");
console.log("2. Drag a 'debug' node onto the canvas.");
console.log("   - Connect the output of the 'rpi gpio in' node to the input of the 'debug' node.");
console.log("   - When the state of GPIO 4 changes, you will see '0' or '1' in the debug sidebar.");
console.log("3. Drag an 'inject' node onto the canvas.");
console.log("   - Double-click the 'inject' node: Set 'Payload' to a number (e.g., 1 for digital high, or 50 for 50% PWM).");
console.log("4. Drag an 'rpi gpio out' node onto the canvas.");
console.log("   - Double-click the 'rpi gpio out' node: Select a BCM GPIO number (e.g., 17) and choose 'Digital output' or 'PWM output' mode.");
console.log("5. Connect the output of the 'inject' node to the input of the 'rpi gpio out' node.");
console.log("   - Clicking the 'inject' node's button will now set the state of GPIO 17.");
console.log("6. Click the 'Deploy' button in the Node-RED editor to activate your flow.");

// Note: On non-Raspbian systems, additional Python library and Udev rules setup is required. (Refer to warnings for details).

view raw JSON →