!!! A NEW, more advanced repo, (based on this one) is: here:
- It can handle +2 chip types: MCP23008 and PCF8575.
- It has better configuration possibilities via Node-red GUI. (eg. I2C addr A0 A1 A2)
- Auto limiting the MCPxxx chip's output problems on 7. + 15. pins.
- Has a "Legacy" checkbox to use this node's behaviour for backward compatibility.
- Working IRQ! (Tested.)
... see full list of change logs of his excellent work.
- About Node-Red link...
- Link for the MCP chip itself
- Chip specs. PDF
- Link for the PCF chip itself
- Chip specs. PDF
- Node-RED node
- Github source
- NR. Forum discussion
It uses the config node "mcp_pcf_chip" for all reading and writing on i2c bus
More about I2C...
- Each pin (8 or 16 in total) can be individually selected to be an input or output
- You can place as many Nodes to your flows as many pins you use, or
- you can also set 1-1 node only pro 0-7 or 8-15 and control via
msg.pin
andmsg.state
ifmsg.payload=-1
- 4 states are showed of a node:
On=green
Off=grey
Uninitialised=yellow
Error=red
Requires 'i2c-bus' module. link...
( It gets automatically installed, except if you want to use it directly from function nodes. )
WARNING: input interrupts part of this component is experimental.
- it reads inputs non-stop, can be set milisec value (a bit higher CPU usage)
- it might starts multiple timers that interfere with each other? (Needs investigation.)
- to minimize state-refresh problem there is secondary "de-bounce" timer
-
Each node has a global Main-Chip, that can be configured with "I2C bus number" + "Chip Address". (The PCF8574(A) chips are showed currently with an Address multiplied by 2. Like: 0x21 * 2 = 0x42 )
-
Interval: is used to determine how frequently all inputs are polled. ( Reads all 8+8 ports from bank A+B. )
! Should be minimum 20ms, because a read process of 16 pins takes 12-14ms on a Raspberry Pi 4. -
Bit: is a number from 0 to 15 reflecting the pin (0-7 at FCP8574 chips) If "All0" or "All1" is recieved, the bit becames: -1 in logs.
-
Pull Up: engages the low power pull up resistor. More: https://en.wikipedia.org/wiki/Pull-up_resistor
(Inputs only.) -
Debounce: is a timer where the state must remain at the new level for the specified time (millisec)
(Inputs only.)
( It will filter out too short changes, like sparkles. ) -
Invert is a software-override for both Input + Output pins. It will show and act the opposite way of On/Off.
0>>1 , 1>>0
( For example some relay boards are "closing = pulling" if they get GND instead of 5V on their pins,
so they need to be negated with resistors. In those cases the chip must get 0x00 to "turn on". ) -
Start All Outputs High: when node-red is started and first chip gets inicialized, it will send a 0xFFFF signal to all pins, so they
- After disconnected of cable or USB-I2C adapter the readouts can not properly restore unless restarting the whole flow.
- Multiple Main-chip-setup-nodes can be set to same Address, causing conflicts. (No pre-error or pre-warning happens.)
- -- fixed 2022-03-26
- It changes the On-Off state visually of the Node while it's not that node changed when using direct-msg-control
- Sending "All0" or "All1" to an MCP node turns on only 0-7 pins, if Bit of Nodes are only set to 0-7. Solution: Set Bit of the node at setup to 8-15 to turn ALL!
- Don't even allow already selected bits to be selected again (not just error reporting about)
- When a node is deleted or disabled - remove from ids (array in chip) --- half done at 2022-03-19 version
- Block RW operations happening at the same time... (rework everything to Async / await and atomic flags)
- Analize further how interrupts are dealt with in C code and write it in s/mcp23017)
- Don't allow to create multiple main chips with the same address (MCP + PCF can be on the same address accidentally)
Thanks to Mike Wilson for the original v0.1 node: MCP23017chip
by László Szakmári (www.pizzaprogram.hu)
- Better Logging options at chip node:
log2consol : default True ; (If changed to False, it will not put log messages to node-red-log)
logTimer : default False; _(If changed to True, it will create lot's of interrupt and timed-red logs!)
Max lines of logs are set to 1000 lines.
(After that no more logs are added, so it will not overfill Node-RED's log system.)
It can be changed by editing the: var logMaxLines = 1000; inside
mcp-pcf-aio.js
file at 50. line. Added require("worker_threads") dependency;
by László Szakmári (www.pizzaprogram.hu)
- Changed INTerrupt CONrol of the MCP chips: (EXPERIMENTAL! Testing needed.)
INTCON=1 << If any of A or B input IO-bank pin changed, both INTA and INTB is triggered
by László Szakmári (www.pizzaprogram.hu)
- Changed Interrupt initialization of the MCP chips: (EXPERIMENTAL! Testing needed.)
MIRROR=1 << If any of A or B input IO-bank pin changed, both INTA and INTB is triggered
ODR=1 << Not only "Active-Low" state, but both "High/Low" input changes are triggered
by László Szakmári (www.pizzaprogram.hu)
-
WARNING! Naming of commands and msg values changed !!! (No more Capital beginnings.)
"All0"
->"all0"
"All1"
->"all1"
msg.AllStatesRaw
->msg.allStatesRaw
... also fixed name convention at source code, likeOnOFF
->on_off
Read more here -
If read-interval is set to 0 it will clear any running timer.
by László Szakmári (www.pizzaprogram.hu)
-
BUG Fix: Too long read time caused a (.warning) error instead of increasing the timer interval x2.
-
Enh.: If the last read time is shorter than interval, it resumes the timer at original interval.
by László Szakmári (www.pizzaprogram.hu)
-
PCF chips show now correct Address -at Main-Chip setup. Fixed.
-
Fixed "interval too short" auto-increase happaning if "interrupt-triggered" read occures
- Added examples
by László Szakmári (www.pizzaprogram.hu)
- Changed
msg.pin
andmsg.state
to lower case.
by László Szakmári (www.pizzaprogram.hu)
-
you can set 1-1 node only pro 0-7 or 8-15 and control via
msg.Pin=
andmsg.State=
ifmsg.Payload=-1
-
fixed
consol.warning
bug if Timer set = 0ms.
by László Szakmári (www.pizzaprogram.hu)
- Fixed bug: on input change payload was always "true".
by László Szakmári (www.pizzaprogram.hu)
-
FIRST OFFICIAL RELEASE
-
Enhanced html help of the node
-
fixed bugs (like: partial Deploy did not clear prev. instances from context)
by László Szakmári (www.pizzaprogram.hu)
-
Added PCF8574 + PCF8574A chip support. Both In + Out.
-
Fixed Naming of PFC... to PCF... (the original code was spelled wrong!).
-
Detailed Logging to consol can be turned on/off with
const log2consol = False;
andtimerLog = false;
-
Fixed Input Bugs. Now stable.
-
Fixed bug if same chip had both in+out pins mixed.
-
Fixed crashing of Node-red if chip or I2C bus was suddenly removed from system.
-
Inject (Interrupt) trigger adds extra values to msg. [] ... see help
-
New Github upload. (PFC false-named one got deleted)
by László Szakmári (www.pizzaprogram.hu)
-
!!! IMPORTANT CHANGE: -- [ x ] Inverse is now affecting Output too ! (Some relay boards are functioning "the opposite way", turning ON if pin is Low.)
-
Changed Bus open/close behaviour. Separate open before/after each read/write operation block. (This way no more non-stop opened bus > no more NodeRed crash if unexpected disconnect.)
-
Fixed other NR crashes: Added Error handling (try - catch) for each i2c bus operation.
Each operation has it's own value to report proper error text. (Like: "Bus opening failed", ... etc) (But execution time increased from 8ms to 12ms on Raspberri 4) -
Fixed 16pin array initialization (16x null)
-
Added multiple/same pin initialization error handling. (Highlander: "There Can Be Only One" :-D )
-
Added lots of comments and constants to JS file (like IOCON, IODIR_A, etc...)
-
Changed icon to a chip-like one. (font-awesome/fa-ticket)
-
Faster initialisation: if set to output >> skips pullup & invert writes.
-
Prevents the input-timer to run if the previous function is still running.
-
+2 states of a node and color change of Off: On=green Off=grey Uninitialised=yellow Error=red
-
Does not starting input-timer, if there are no input nodes available.
-
Auto-increasing read-interval if < 15ms or if reading took too long.
-
If error occured during read-timer >> changing interval to 5 sec >> if normal again >> changing back
-
Dokument + Code changes: -- Pretty print of JS code (inline) -- All local variables start now with _underline -- Many comments + constants + references added to code -- Fixed help in mcp_pcf_chip.html file
-
Fixed input
-
Add input trigger to handle interrupts. If msg.payload = True >> and succesfully read
msg.immediateReadSuccess = true. If any error:Result = false
-
Limit debounce timeing to max = interval - 20ms
-
debounce is not starting if =0
- Node name changed from MCP23017chip to current ,mcp_pfc_aio v2.1.0 ( AIO = All in One IO = Input Output )