UNPKG

ncd-red-mcp4728

Version:

This library provides a class for the mcp4728, it relies on the ncd-red-comm library for communication, and includes a node-red node for the mcp4728. The mcp4728 is a quad, 12-bit voltage output Digital-to-Analog Convertor (DAC) with nonvolatile memory (E

379 lines (364 loc) 16.8 kB
<script type="text/javascript"> RED.nodes.registerType('ncd-mcp4728',{ category: 'NCD', color: '#a6bbcf', defaults: { name: {value: ""}, connection: {value: "", type: "ncd-comm"}, addr: {value: "96"}, output_all: {value: ""}, vr_1: {value: 1, validate: RED.validators.number()}, pd_1: {value: 0, validate: RED.validators.number()}, gx_1: {value: 0, validate: RED.validators.number()}, eeprom_persist_1: {value: ""}, eeprom_startup_1: {value: ""}, eeprom_vr_1: {value: 1, validate: RED.validators.number()}, eeprom_pd_1: {value: 0, validate: RED.validators.number()}, eeprom_gx_1: {value: 0, validate: RED.validators.number()}, eeprom_dac_1: {value: 2048, validate: RED.validators.number()}, vr_2: {value: 1, validate: RED.validators.number()}, pd_2: {value: 0, validate: RED.validators.number()}, gx_2: {value: 0, validate: RED.validators.number()}, eeprom_persist_2: {value: ""}, eeprom_startup_2: {value: ""}, eeprom_vr_2: {value: 1, validate: RED.validators.number()}, eeprom_pd_2: {value: 0, validate: RED.validators.number()}, eeprom_gx_2: {value: 0, validate: RED.validators.number()}, eeprom_dac_2: {value: 2048, validate: RED.validators.number()}, vr_3: {value: 1, validate: RED.validators.number()}, pd_3: {value: 0, validate: RED.validators.number()}, gx_3: {value: 0, validate: RED.validators.number()}, eeprom_persist_3: {value: ""}, eeprom_startup_3: {value: ""}, eeprom_vr_3: {value: 1, validate: RED.validators.number()}, eeprom_pd_3: {value: 0, validate: RED.validators.number()}, eeprom_gx_3: {value: 0, validate: RED.validators.number()}, eeprom_dac_3: {value: 2048, validate: RED.validators.number()}, vr_4: {value: 1, validate: RED.validators.number()}, pd_4: {value: 0, validate: RED.validators.number()}, gx_4: {value: 0, validate: RED.validators.number()}, eeprom_persist_4: {value: ""}, eeprom_startup_4: {value: ""}, eeprom_vr_4: {value: 1, validate: RED.validators.number()}, eeprom_pd_4: {value: 0, validate: RED.validators.number()}, eeprom_gx_4: {value: 0, validate: RED.validators.number()}, eeprom_dac_4: {value: 2048, validate: RED.validators.number()}, }, inputs:1, outputs:1, icon: "serial.png", label: function() { return this.name || "MCP4728"; }, outputLabels: function(i){ if(!this.output_all || i == 5) return 'Device Status'; return 'Channel '+(i+1); }, oneditprepare: function() { $('[type=checkbox]').change(function(){ if($(this).is(':checked')){ $('[data-ischecked='+$(this).attr('id')+']').show(); $('[data-notchecked='+$(this).attr('id')+']').hide(); }else{ $('[data-ischecked='+$(this).attr('id')+']').hide(); $('[data-notchecked='+$(this).attr('id')+']').show(); } }); }, oneditsave: function(){ this.outputs = $('#node-input-output_all').is(':checked') ? 5 : 1; } }); </script> <script type="text/x-red" data-template-name="ncd-mcp4728"> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-connection"><i class="icon-tag"></i> I2C Connection</label> <select id="node-input-connection"></select> </div> <div class="form-row"> <label for="node-input-addr"><i class="icon-tag"></i> Device Address</label> <select id="node-input-addr"> <option value="96">96</option> <option value="97">97</option> </select> </div> <div class="form-row"> <label for="node-input-output_all"><i class="icon-tag"></i> Output all channels</label> <input type="checkbox" id="node-input-output_all" value="1"> </div> <hr /> <h5>Channel 1 Settings</h5> <div class="form-row"> <label for="node-input-vr_1"><i class="icon-tag"></i> Internal Voltage Ref</label> <input type="checkbox" id="node-input-vr_1" checked="checked" value="1"> </div> <div class="form-row"> <label for="node-input-pd_1"><i class="icon-tag"></i> Power Down Mode</label> <select id="node-input-pd_1"> <option value="0">Normal Mode</option> <option value="1">Power Down (1k resistor)</option> <option value="2">Power Down (100k resistor)</option> <option value="3">Power Down (500k resistor)</option> </select> </div> <div class="form-row"> <label for="node-input-gx_1"><i class="icon-tag"></i> Gain</label> <select id="node-input-gx_1"> <option value="0">Gain 1x</option> <option value="1">Gain 2x</option> </select> </div> <h6>EEPROM Settings</h6> <div class="form-row"> <label for="node-input-eeprom_persist_1"><i class="icon-tag"></i> Persistent State*</label> <input type="checkbox" id="node-input-eeprom_persist_1" value="1"><br/> <span><b>* Use this with care, see note in info tab.</b></span> </div> <div data-notchecked="node-input-eeprom_persist_1"> <div class="form-row"> <label for="node-input-eeprom_startup_1"><i class="icon-tag"></i> Startup State</label> <input type="checkbox" id="node-input-eeprom_startup_1" value="1"> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_1"> <label for="node-input-eeprom_vr_1"><i class="icon-tag"></i> Internal Voltage Ref</label> <input type="checkbox" id="node-input-eeprom_vr_1" checked="checked" value="1"> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_1"> <label for="node-input-eeprom_pd_1"><i class="icon-tag"></i> Power Down Mode</label> <select id="node-input-eeprom_pd_1"> <option value="0">Normal Mode</option> <option value="1">Power Down (1k resistor)</option> <option value="2">Power Down (100k resistor)</option> <option value="3">Power Down (500k resistor)</option> </select> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_1"> <label for="node-input-eeprom_gx_1"><i class="icon-tag"></i> Gain</label> <select id="node-input-eeprom_gx_1"> <option value="0">Gain 1x</option> <option value="1">Gain 2x</option> </select> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_1"> <label for="node-input-eeprom_dac_1"><i class="icon-tag"></i> DAC Value (0-4095)</label> <input type="text" id="node-input-eeprom_dac_1"> </div> </div> <hr /> <h5>Channel 2 Settings</h5> <div class="form-row"> <label for="node-input-vr_2"><i class="icon-tag"></i> Internal Voltage Ref</label> <input type="checkbox" id="node-input-vr_2" checked="checked" value="1"> </div> <div class="form-row"> <label for="node-input-pd_2"><i class="icon-tag"></i> Power Down Mode</label> <select id="node-input-pd_2"> <option value="0">Normal Mode</option> <option value="1">Power Down (1k resistor)</option> <option value="2">Power Down (100k resistor)</option> <option value="3">Power Down (500k resistor)</option> </select> </div> <div class="form-row"> <label for="node-input-gx_2"><i class="icon-tag"></i> Gain</label> <select id="node-input-gx_2"> <option value="0">Gain 1x</option> <option value="1">Gain 2x</option> </select> </div> <h6>EEPROM Settings</h6> <div class="form-row"> <label for="node-input-eeprom_persist_2"><i class="icon-tag"></i> Persistent State*</label> <input type="checkbox" id="node-input-eeprom_persist_2" value="1"><br/> <span><b>* Use this with care, see note in info tab.</b></span> </div> <div data-notchecked="node-input-eeprom_persist_2"> <div class="form-row"> <label for="node-input-eeprom_startup_2"><i class="icon-tag"></i> Startup State</label> <input type="checkbox" id="node-input-eeprom_startup_2" value="1"> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_2"> <label for="node-input-eeprom_vr_2"><i class="icon-tag"></i> Internal Voltage Ref</label> <input type="checkbox" id="node-input-eeprom_vr_2" checked="checked" value="1"> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_2"> <label for="node-input-eeprom_pd_2"><i class="icon-tag"></i> Power Down Mode</label> <select id="node-input-eeprom_pd_2"> <option value="0">Normal Mode</option> <option value="1">Power Down (1k resistor)</option> <option value="2">Power Down (100k resistor)</option> <option value="3">Power Down (500k resistor)</option> </select> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_2"> <label for="node-input-eeprom_gx_2"><i class="icon-tag"></i> Gain</label> <select id="node-input-eeprom_gx_2"> <option value="0">Gain 1x</option> <option value="1">Gain 2x</option> </select> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_2"> <label for="node-input-eeprom_dac_2"><i class="icon-tag"></i> DAC Value (0-4095)</label> <input type="text" id="node-input-eeprom_dac_2"> </div> </div> <hr /> <h5>Channel 3 Settings</h5> <div class="form-row"> <label for="node-input-vr_3"><i class="icon-tag"></i> Internal Voltage Ref</label> <input type="checkbox" id="node-input-vr_3" checked="checked" value="1"> </div> <div class="form-row"> <label for="node-input-pd_3"><i class="icon-tag"></i> Power Down Mode</label> <select id="node-input-pd_3"> <option value="0">Normal Mode</option> <option value="1">Power Down (1k resistor)</option> <option value="2">Power Down (100k resistor)</option> <option value="3">Power Down (500k resistor)</option> </select> </div> <div class="form-row"> <label for="node-input-gx_3"><i class="icon-tag"></i> Gain</label> <select id="node-input-gx_3"> <option value="0">Gain 1x</option> <option value="1">Gain 2x</option> </select> </div> <h6>EEPROM Settings</h6> <div class="form-row"> <label for="node-input-eeprom_persist_3"><i class="icon-tag"></i> Persistent State*</label> <input type="checkbox" id="node-input-eeprom_persist_3" value="1"><br/> <span><b>* Use this with care, see note in info tab.</b></span> </div> <div data-notchecked="node-input-eeprom_persist_3"> <div class="form-row"> <label for="node-input-eeprom_startup_3"><i class="icon-tag"></i> Startup State</label> <input type="checkbox" id="node-input-eeprom_startup_3" value="1"> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_3"> <label for="node-input-eeprom_vr_3"><i class="icon-tag"></i> Internal Voltage Ref</label> <input type="checkbox" id="node-input-eeprom_vr_3" checked="checked" value="1"> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_3"> <label for="node-input-eeprom_pd_3"><i class="icon-tag"></i> Power Down Mode</label> <select id="node-input-eeprom_pd_3"> <option value="0">Normal Mode</option> <option value="1">Power Down (1k resistor)</option> <option value="2">Power Down (100k resistor)</option> <option value="3">Power Down (500k resistor)</option> </select> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_3"> <label for="node-input-eeprom_gx_3"><i class="icon-tag"></i> Gain</label> <select id="node-input-eeprom_gx_3"> <option value="0">Gain 1x</option> <option value="1">Gain 2x</option> </select> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_3"> <label for="node-input-eeprom_dac_3"><i class="icon-tag"></i> DAC Value (0-4095)</label> <input type="text" id="node-input-eeprom_dac_3"> </div> </div> <hr /> <h5>Channel 4 Settings</h5> <div class="form-row"> <label for="node-input-vr_4"><i class="icon-tag"></i> Internal Voltage Ref</label> <input type="checkbox" id="node-input-vr_4" checked="checked" value="1"> </div> <div class="form-row"> <label for="node-input-pd_4"><i class="icon-tag"></i> Power Down Mode</label> <select id="node-input-pd_4"> <option value="0">Normal Mode</option> <option value="1">Power Down (1k resistor)</option> <option value="2">Power Down (100k resistor)</option> <option value="3">Power Down (500k resistor)</option> </select> </div> <div class="form-row"> <label for="node-input-gx_4"><i class="icon-tag"></i> Gain</label> <select id="node-input-gx_4"> <option value="0">Gain 1x</option> <option value="1">Gain 2x</option> </select> </div> <h6>EEPROM Settings</h6> <div class="form-row"> <label for="node-input-eeprom_persist_4"><i class="icon-tag"></i> Persistent State*</label> <input type="checkbox" id="node-input-eeprom_persist_4" value="1"><br/> <span><b>* Use this with care, see note in info tab.</b></span> </div> <div data-notchecked="node-input-eeprom_persist_4"> <div class="form-row"> <label for="node-input-eeprom_startup_4"><i class="icon-tag"></i> Startup State</label> <input type="checkbox" id="node-input-eeprom_startup_4" value="1"> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_4"> <label for="node-input-eeprom_vr_4"><i class="icon-tag"></i> Internal Voltage Ref</label> <input type="checkbox" id="node-input-eeprom_vr_4" checked="checked" value="1"> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_4"> <label for="node-input-eeprom_pd_4"><i class="icon-tag"></i> Power Down Mode</label> <select id="node-input-eeprom_pd_4"> <option value="0">Normal Mode</option> <option value="1">Power Down (1k resistor)</option> <option value="2">Power Down (100k resistor)</option> <option value="3">Power Down (500k resistor)</option> </select> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_4"> <label for="node-input-eeprom_gx_4"><i class="icon-tag"></i> Gain</label> <select id="node-input-eeprom_gx_4"> <option value="0">Gain 1x</option> <option value="1">Gain 2x</option> </select> </div> <div class="form-row" data-ischecked="node-input-eeprom_startup_4"> <label for="node-input-eeprom_dac_4"><i class="icon-tag"></i> DAC Value (0-4095)</label> <input type="text" id="node-input-eeprom_dac_4"> </div> </div> </script> <script type="text/x-red" data-help-name="ncd-mcp4728"> <h3>I2C Connection</h3> <p>Configure the connection you want to use to communicate to your I2C device. Native I2C and USB to I2C converters are supported.</p> <h3>Device Address</h3> <p>The mcp4728 exposes a hardware pin to make it easily addressable, on the NCD version this pin is controlled with a jumper which has the following values:</p> <ul> <li><b>Uninstalled</b> 96</li> <li><b>Installed</b> 97</li> </ul> <h3>Output All Channels</h3> <p>By default this device will have 1 output, which will send a payload anytime it detects a status change on the device (or everyime it recieves a message with a topic of "get_status"). Use this option to enable seperate outputs for each channel.</p> <h2>Per-Channel Settings</h4> <h3>Internal Voltage Ref</h3> <p>Uncheck this box to use an external voltage reference. By default the internal reference will be used.</p> <h3>Power Down Mode</h3> <p>Any setting other than Normal Mode will power down the channel, this is useful for battery powered devices.</p> <h3>Gain</h3> <p>Applicable only when internal "Internal Voltage Ref" is selected. If unselected, the device uses a gain of 1.</p> <h2>Per-Channel EEPROM Settings</h2> <h3>Persist Device State</h3> <p>Check this box to write all updates to the internal EEPROM of the chip. This will ensure that on power loss, the chip will return to its previous state.</p> <p><b>All EEPROM is subject to wear, frequent writes to these registers over time may cause it to stop functioning. Check with the chip manufacturer for the average life of the EEPROM</b></p> <h3>Startup State</h3> <p>If you are not using Persist Device State, you can set a startup state for the output in the fields provided here.</p> <h3>Internal Voltage Ref</h3> <p>Same as above</p> <h3>Power Down Mode</h3> <p>Same as above</p> <h3>Gain</h3> <p>Same as above</p> <h3>DAC Value</h3> <p>Same as above</p> <h3>Input values</h3> <p>You can send commands to the device through the use of topics and payloads. To control the output of a DAC, send a message with a payload containing an integer 0-4095 (inclusive), and a topic to select the channel. For example, the following message will set channel 1 to full output:</p> <p><code>{topic: "channel_1", payload: 4095}</code></p> <p>Sending a topic of "all" will set all channels at once</p> <h3>Output Values</h3> <p>Any time the device connects (or node-red restarts), or a new command is sent to the device, an output message will be sent with the current state of the DAC in the payload, this value will be 0-4095 (inclusive).</p> </script>