mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add SPIdev choice to mcpxxxx node
This commit is contained in:
parent
eae67c7a6c
commit
23ba609653
@ -37,6 +37,8 @@ select the channel dynamically. If so then the payload must be a value from 0 to
|
|||||||
|
|
||||||
You can also select device id 0 or 1 (CE0 or CE1) depending on how you have wired up your device. Defaults to CE0.
|
You can also select device id 0 or 1 (CE0 or CE1) depending on how you have wired up your device. Defaults to CE0.
|
||||||
|
|
||||||
|
And you can also select the SPI bus number 0 or 1 depending on how you have wired up your device. Defaults to 0 for spidev0.
|
||||||
|
|
||||||
Outputs a numeric `msg.payload` with a range of 0 to 1023, where 0 = 0V and 1023 = 3.3V (assuming you use the default 3.3V voltage reference).
|
Outputs a numeric `msg.payload` with a range of 0 to 1023, where 0 = 0V and 1023 = 3.3V (assuming you use the default 3.3V voltage reference).
|
||||||
|
|
||||||
**Hint**: use a `range` node to adjust the values to the range you want.
|
**Hint**: use a `range` node to adjust the values to the range you want.
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-pi-mcp3008",
|
"name" : "node-red-node-pi-mcp3008",
|
||||||
"version" : "0.1.1",
|
"version" : "0.2.0",
|
||||||
"description" : "A Node-RED node to read from the MCP3008 Analogue to Digital Converter",
|
"description" : "A Node-RED node to read from the MCP3008 Analogue to Digital Converter",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"mcp-spi-adc": "^1.0.0"
|
"mcp-spi-adc": "^2.0.3"
|
||||||
},
|
},
|
||||||
"repository" : {
|
"repository" : {
|
||||||
"type":"git",
|
"type":"git",
|
||||||
|
@ -33,6 +33,13 @@
|
|||||||
<option value=1>CE1</option>
|
<option value=1>CE1</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-bus"><i class="fa fa-toggle-on"></i> SPI bus</label>
|
||||||
|
<select type="text" id="node-input-bus" style="width:150px;">
|
||||||
|
<option value=0>0</option>
|
||||||
|
<option value=1>1</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name"/>
|
<input type="text" id="node-input-name" placeholder="Name"/>
|
||||||
@ -61,7 +68,8 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
dev: {value:"3008"},
|
dev: {value:"3008"},
|
||||||
pin: {value:0, required:true},
|
pin: {value:0, required:true},
|
||||||
dnum: {value:0}
|
dnum: {value:0},
|
||||||
|
bus: {value:0}
|
||||||
},
|
},
|
||||||
inputs: 1,
|
inputs: 1,
|
||||||
outputs: 1,
|
outputs: 1,
|
||||||
|
@ -19,14 +19,15 @@ module.exports = function(RED) {
|
|||||||
this.pin = n.pin || 0;
|
this.pin = n.pin || 0;
|
||||||
this.interval = n.interval || 1000;
|
this.interval = n.interval || 1000;
|
||||||
this.dnum = parseInt(n.dnum || 0);
|
this.dnum = parseInt(n.dnum || 0);
|
||||||
|
this.bus = parseInt(n.bus || 0);
|
||||||
this.dev = n.dev || "3008";
|
this.dev = n.dev || "3008";
|
||||||
var node = this;
|
var node = this;
|
||||||
var cb = function (err) { if (err) { node.error("Error: "+err); } };
|
var cb = function (err) { if (err) { node.error("Error: "+err); } };
|
||||||
var opt = { speedHz:20000, deviceNumber:node.dnum };
|
var opt = { speedHz:20000, deviceNumber:node.dnum, busNumber:node.bus };
|
||||||
var chans = parseInt(this.dev.substr(3));
|
var chans = parseInt(this.dev.substr(3));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.statSync("/dev/spidev0."+node.dnum);
|
fs.statSync("/dev/spidev"+node.bus+"."+node.dnum);
|
||||||
if (mcp3xxx.length === 0) {
|
if (mcp3xxx.length === 0) {
|
||||||
for (var i=0; i<chans; i++) {
|
for (var i=0; i<chans; i++) {
|
||||||
if (node.dev === "3002") { mcp3xxx.push(mcpadc.openMcp3002(i, opt, cb)); }
|
if (node.dev === "3002") { mcp3xxx.push(mcpadc.openMcp3002(i, opt, cb)); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user