UNPKG

node-red-contrib-automation-hat

Version:

Node-RED nodes for the Pimoroni Automation HAT, pHAT and HAT Mini

213 lines (191 loc) 11.7 kB
<!-- Copyright 2018 Martin Rowan <martin@rowannet.co.uk> Initial implementation Copyright 2016 Pimoroni Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <script type="text/javascript"> RED.nodes.registerType("rpi-automation-hat in",{ category: "Raspberry Pi", paletteLabel: "Automation HAT Inputs", color: '#c6dbef', defaults: { name: { value: "" }, input: { value: true }, analog: { value: true }, threshold: { value: 0.01 }, adc4_threshold: { value: 0.01 } }, inputs:0, outputs:1, icon: "rpi.png", label: function() { return this.name||"Automation HAT"; }, labelStyle: function() { return this.name?"node_label_italic":""; } }); RED.nodes.registerType("rpi-automation-hat out",{ category: "Raspberry Pi", paletteLabel: "Automation HAT Outputs", color: '#c6dbef', defaults: { name: { value: "" }, }, inputs:1, outputs:0, icon: "rpi.png", label: function() { return this.name||"Automation HAT"; }, labelStyle: function() { return this.name?"node_label_italic":""; } }); RED.nodes.registerType("rpi-automation-hat reader",{ category: "Raspberry Pi", paletteLabel: "Automation HAT Reader", color: '#c6dbef', defaults: { name: { value: "" }, input: { value: true }, analog: { value: true } }, inputs:1, outputs:1, icon: "rpi.png", label: function() { return this.name||"Automation HAT"; }, labelStyle: function() { return this.name?"node_label_italic":""; } }); </script> <script type="text/x-red" data-template-name="rpi-automation-hat in"> <div class="form-row"> <label><i class="fa fa-arrow-right"></i> Outputs</label> <label style="width: auto" for="node-input-input"><input style="vertical-align: top; width: auto; margin-right: 5px;" type="checkbox" id="node-input-input"> Input events</label> <div style="padding-left: 125px; margin-top: -5px; color: #bbb;">24V tolerant inputs 1, 2, and 3</div> </div> <div class="form-row"> <label></label> <label style="width: auto" for="node-input-analog"><input style="vertical-align: top; width: auto; margin-right: 5px;" type="checkbox" id="node-input-analog"> Analog events</label> <div style="padding-left: 125px; margin-top: -5px; color: #bbb;">0 - 25.85V analog inputs 1, 2 and 3<br>0 - 3.3V analog input 4 (HAT only)</div> </div> <div class="form-row"> <label></label> <label style="width: auto" for="node-input-threshold"><input style="width: 50px; margin-right: 5px;" type="text" id="node-input-threshold"> ADC1 - 3 threshold (Volts)</label> <div style="padding-left: 125px; margin-top: -5px; color: #bbb;">Voltage change to trigger output</div> </div> <div class="form-row"> <label></label> <label style="width: auto" for="node-input-adc4_threshold"><input style="width: 50px; margin-right: 5px;" type="text" id="node-input-adc4_threshold"> ADC4 threshold (Volts)</label> <div style="padding-left: 125px; margin-top: -5px; color: #bbb;">Voltage change to trigger output</div> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name"> </div> </script> <script type="text/x-red" data-help-name="rpi-automation-hat in"> <p>Raspberry Pi Automation HAT input node.</p> <p>This node sends readings from the various inputs on Automation HAT, grouped into two sets; input events and analog events.</p> <p><b>Input Events</b></p> <p>Input events are generated by the three 24V tolerant protected inputs on Automation HAT/pHAT. A message will be sent every time an input changes.</p> <p>The <code>topic</code> is set to <code>automationhat/input.&lt;channel&gt;</code> and the <code>payload</code> is an number that's either:</p> <ul> <li><code>1</code> : indicating the input is HIGH.</li> <li><code>0</code> : indicating the input is LOW.</li> </ul> <p><b>Analog Events</b></p> <p>Analog events are generated by the three 0 - 25.85V analog (ADC1 - 3) inputs on Automation HAT/pHAT. A fourth 0 - 3.3V analog input (ADC4) is available (HAT only). A message will be sent when the analog value changes by an amount greater than or equal to the threshold, default 0.01V (10mV).</p> <p>Note: 100mV is the maximum resolution of the analog readings.</p> The <code>topic</code> is set to <code>automationhat/analog.&lt;channel&gt;</code> and the <code>payload</code> measured voltage:</p> <p>For example, a topic of <code>automationhat/analog.2</code> and a payload of <code>3.303</code> would indicate that 3.303v is present on ADC 2.</p> </script> <script type="text/x-red" data-template-name="rpi-automation-hat out"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name"> </div> </script> <script type="text/x-red" data-help-name="rpi-automation-hat out"> <p>Raspberry Pi Automation HAT output node.</p> <p>This node controls the various outputs on Automation HAT, grouped into three sets; digital outputs, relays and lights.</p> <p><b>Digital Outputs</b></p> <p>The three outputs on Automation HAT are 24V tolerant, sinking outputs. That means you should connect them between your load and ground. They act like a switch down to ground, toggling your load on and off. The outputs are driven by a ULN2003A Darlington Array driver.</p> <p>Digital outputs are controlled by sending a message with the topic <code>output.&lt;channel&gt;</code> where channel is a number from 1 to 3 (corresponding to the numbers on the Automation HAT/pHAT board) or a name from "one" to "three" if you prefer.</p> <p>The <code>payload</code> of the message should be set to:</p> <ul> <li><code>1</code> or <code>on</code> or <code>enable</code> or <code>true</code> : to turn the output on.</li> <li><code>0</code> or <code>off</code> or <code>disable</code> or <code>false</code> : to turn the output off.</li> <li><code>toggle</code> : to toggle the output between each state.</li> </ul> <p><b>Relays</b></p> <p>The relays on Automation HAT supply both NO (Normally Open) and NC (Normally Closed) terminals. You can use them to switch a single load, or alternate between two. The relays should be placed between the voltage supply and your load. The relays can switch a maximum load of 24V 2A per relay.</p> <p>Relay outputs are controlled by sending a message with the topic <code>relay.&lt;channel&gt;</code> where channel is a number from 1 to 3 (corresponding to the numbers on the Automation HAT/pHAT board) or a name from "one" to "three" if you prefer.</p> <p>The <code>payload</code> of the message should be set to:</p> <ul> <li><code>1</code> or <code>on</code> or <code>enable</code> or <code>true</code> : to switch the relay contacts so that COM is connected to NO.</li> <li><code>0</code> or <code>off</code> or <code>disable</code> or <code>false</code> : to switch the relay contacts so that COM is connected to NC.</li> <li><code>toggle</code> : to toggle the relay from its previous state.</li> </ul> <p><b>Lights (excludes pHAT)</b></p> <p>Automation HAT includes three user-controllable lights: POWER, COMMS and WARN. <p>Lights are controlled by sending a message with the topic <code>light.&lt;channel&gt;</code> where channel is the light named on the board "power", "comms", or "warn".</p> <p>The <code>payload</code> of the message should be set to:</p> <ul> <li><code>1</code> or <code>on</code> or <code>enable</code> or <code>true</code> : to enable the automatic lights.</li> <li><code>0</code> or <code>off</code> or <code>disable</code> or <code>false</code> : to disable the automatic lights (lights already illuminated will remain lit).</li> <li><code>toggle</code> : to toggle the light from its previous state.</li> </ul> <p><b>Additional Commands (excludes pHAT)</b></p> <p>By default the Automation HAT will trigger indicator lights on each input/output automatically.</p> <p>This behaviour can be controlled by sending a message with the topic <code>auto_lights</code></p> <p>The <code>payload</code> of the message should be set to:</p> <ul> <li><code>1</code> or <code>on</code> or <code>enable</code> or <code>true</code> : to turn the light on.</li> <li><code>0</code> or <code>off</code> or <code>disable</code> or <code>false</code> : to turn the light off.</li> </ul> </script> <script type="text/x-red" data-template-name="rpi-automation-hat reader"> <div class="form-row"> <label><i class="fa fa-arrow-right"></i> Outputs</label> <label style="width: auto" for="node-input-input"><input style="vertical-align: top; width: auto; margin-right: 5px;" type="checkbox" id="node-input-input"> Input events</label> <div style="padding-left: 125px; margin-top: -5px; color: #bbb;">24V tolerant inputs 1, 2, and 3</div> </div> <div class="form-row"> <label></label> <label style="width: auto" for="node-input-analog"><input style="vertical-align: top; width: auto; margin-right: 5px;" type="checkbox" id="node-input-analog"> Analog events</label> <div style="padding-left: 125px; margin-top: -5px; color: #bbb;">0 - 25.85V analog inputs 1, 2 and 3<br>0 - 3.3V analog input 4 (HAT only)</div> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name"> </div> </script> <script type="text/x-red" data-help-name="rpi-automation-hat reader"> <p>Raspberry Pi Automation HAT reader node.</p> <p>Any input provided to this node triggers the inputs on Automation HAT to be read. The output is grouped into two sets; input events and analog events.</p> <p><b>Input Events</b></p> <p>Input events are generated by the three 24V tolerant protected inputs on Automation HAT/pHAT. The <code>topic</code> is set to <code>automationhat/input.&lt;channel&gt;</code> and the <code>payload</code> is an number that's either:</p> <ul> <li><code>1</code> : indicating the input is HIGH.</li> <li><code>0</code> : indicating the input is LOW.</li> </ul> <p><b>Analog Events</b></p> <p>Analog events are generated by the three 0 - 25.85V analog (ADC1 - 3) inputs on Automation HAT/pHAT. A fourth 0 - 3.3V analog input (ADC4) is available (HAT only).</p> <p>The <code>topic</code> is set to <code>automationhat/analog.&lt;channel&gt;</code> and the <code>payload</code> is the voltage measured:</p> <p>Note: 100mV is the maximum resolution of the analog readings.</p> <p>For example, a topic of <code>automationhat/analog.2</code> and a payload of <code>3.303</code> would indicate that 3.303V is present on Analog 2.</p> </script>