# @redplc/node-red-gpio

[![platform](https://img.shields.io/badge/platform-Node--RED-red)](https://nodered.org)
[![platform](https://img.shields.io/badge/platform-redPlc-ffa500)](https://flows.nodered.org/node/@redplc/node-red-redplc/)
[![platform](https://img.shields.io/badge/platform-Raspberry--Pi-ff69b4)](https://www.raspberrypi.com/)

Node-RED nodes for Raspberry Pi GPIO using with [redPlc](https://www.npmjs.com/package/@redplc/node-red-redplc/) nodes.<br>

<a href="https://www.buymeacoffee.com/iiot2ka" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-red.png" height="41" width="174"></a><br>

## Installation
Install with Node-Red Palette Manager or npm command:
```
cd ~/.node-red
npm install @redplc/node-red-gpio
```

Report any issues [here](https://github.com/redplc/redplc/issues) with name *@redplc/node-red-gpio*.

## Detail
- This node uses the gpio character devices interface (V2) from the Linux operating system
- The interface to hardware is implemented in C++ as add-on module
- This library works on Raspberry Pi with 32bit or 64bit OS
- Works on Raspberry Pi 3, 4, 5
- Not yet tested on the Raspberry Pi 2


## Nodes
- **gpio-in**: Reads GPIO inputs and store in boolean array.
- **gpio-out**: Sets GPIO outputs from boolean array.

## Usage
- Install [redPlc](https://www.npmjs.com/package/@redplc/node-red-redplc/) nodes.
- Use redPlc s-inject node for trigger update.
- Connect to first output on s-inject node.
- Daisy chain nodes in series.
- For logical operations use redPlc nodes. 
- Data is exchanged with global context variable arrays.
- Array index is equal gpio number for easy handling.
- Select different gpio pins for input and output.
- For open inputs select pull down/up resistors.
- Check with raspi-config for alternate functions on GPIO.

## Array Index Mapping

|Index|Funct.|Pin|Pin|Funct.|Index|
|:--|:---- |:-:|:-:|:-----|:--|
||**3V3**|1|2|**5V**||
|2|GPIO02|3|4|**5V**||
|3|GPIO03|5|6|**GND**||
|4|GPIO04|7|8|GPIO14|14|
||**GND**|9|10|GPIO15|15|
|17|GPIO17|11|12|GPIO18|18|
|27|GPIO27|13|14|**GND**||
|22|GPIO22|15|16|GPIO23|23|
||**3V3**|17|18|GPIO24|24|
|10|GPIO10|19|20|**GND**||
|9|GPIO09|21|22|GPIO25|25|
|11|GPIO11|23|24|GPIO08|8|
||**GND**|25|26|GPIO07|7|
|||27|28|||
|5|GPIO05|29|30|**GND**||
|6|GPIO06|31|32|GPIO12|12|
|13|GPIO13|33|34|**GND**||
|19|GPIO19|35|36|GPIO16|15|
|26|GPIO26|37|38|GPIO20|20|
||**GND**|39|40|GPIO21|21|

## Example
The example shows the logic behind redPlc.<br>
Please install this and @redplc/node-red-redplc Node.<br>
Connect switches to GPIO21, GPIO20 and GPIO16 with common to ground.<br>
LEDs with series resistors can be connected to the outputs GPIO12, GPIO13, GPIO19 and GPIO26.<br>
Please note the maximum output current of the GPIO pins.<br>