From 23ba609653ea4c080aa41f7acda154dcf78db65b Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 21 Sep 2018 13:53:08 +0100 Subject: [PATCH] Add SPIdev choice to mcpxxxx node --- hardware/mcp3008/README.md | 2 ++ hardware/mcp3008/package.json | 4 ++-- hardware/mcp3008/pimcp3008.html | 10 +++++++++- hardware/mcp3008/pimcp3008.js | 5 +++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/hardware/mcp3008/README.md b/hardware/mcp3008/README.md index 0914d49c..5ab83009 100644 --- a/hardware/mcp3008/README.md +++ b/hardware/mcp3008/README.md @@ -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. +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). **Hint**: use a `range` node to adjust the values to the range you want. diff --git a/hardware/mcp3008/package.json b/hardware/mcp3008/package.json index bf89c672..f9a6a028 100644 --- a/hardware/mcp3008/package.json +++ b/hardware/mcp3008/package.json @@ -1,9 +1,9 @@ { "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", "dependencies" : { - "mcp-spi-adc": "^1.0.0" + "mcp-spi-adc": "^2.0.3" }, "repository" : { "type":"git", diff --git a/hardware/mcp3008/pimcp3008.html b/hardware/mcp3008/pimcp3008.html index 59c2dbcc..3fafb671 100644 --- a/hardware/mcp3008/pimcp3008.html +++ b/hardware/mcp3008/pimcp3008.html @@ -33,6 +33,13 @@ +
+ + +
@@ -61,7 +68,8 @@ name: {value:""}, dev: {value:"3008"}, pin: {value:0, required:true}, - dnum: {value:0} + dnum: {value:0}, + bus: {value:0} }, inputs: 1, outputs: 1, diff --git a/hardware/mcp3008/pimcp3008.js b/hardware/mcp3008/pimcp3008.js index ee5e835f..492f8d6b 100644 --- a/hardware/mcp3008/pimcp3008.js +++ b/hardware/mcp3008/pimcp3008.js @@ -19,14 +19,15 @@ module.exports = function(RED) { this.pin = n.pin || 0; this.interval = n.interval || 1000; this.dnum = parseInt(n.dnum || 0); + this.bus = parseInt(n.bus || 0); this.dev = n.dev || "3008"; var node = this; 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)); try { - fs.statSync("/dev/spidev0."+node.dnum); + fs.statSync("/dev/spidev"+node.bus+"."+node.dnum); if (mcp3xxx.length === 0) { for (var i=0; i