var rpio = require('rpio'); | |
rpio.spiBegin(); | |
//rpio.spiChipSelect(0); /* Chip select: use CE0 (default) */ | |
//rpio.spiSetCSPolarity(0, rpio.LOW) /* Commonly chip enable (CE) pins are active low, and this is the default. */ | |
//rpio.spiSetClockDivider(256) /* MCP3008 max is ~1MHz, 256 == 0.98MHz */ | |
//rpio.spiSetDataMode(0); | |
// Prepare TX buffer [trigger byte = 0x01] [channel 0 = 0x80 (128)] [placeholder = 0x01] | |
var sendBuffer = new Buffer([0x01, (8 + 0 << 4), 0x01]); | |
// Send TX buffer to SPI MOSI and recieve RX buffer from MISO | |
var recieveBuffer = rpio.spiTransfer(sendBuffer, sendBuffer.length); | |
// Extract value from output buffer. Ignore first byte. | |
var junk = recieveBuffer[0], | |
MSB = recieveBuffer[1], | |
LSB = recieveBuffer[2]; | |
// Ignore first six bits of MSB, bit shift MSB 8 positions and | |
// finally add LSB to MSB to get a full 10 bit value | |
var value = ((MSB & 3) << 8) + LSB; | |
console.log('ch' + ((sendBuffer[1] >> 4) - 8), '=', value); | |
rpio.spiEnd(); |
This comment has been minimized.
This comment has been minimized.
nick-jonas
commented
Feb 3, 2016
I'm getting the same error as @jamms Any ideas? |
This comment has been minimized.
This comment has been minimized.
Could you please post the code executed before the Or if you used my example without alternation maybe you could verify which version of rpio-lib you have installed? |
This comment has been minimized.
This comment has been minimized.
nick-jonas
commented
Feb 4, 2016
@mikaelleven I'm using your code unaltered, and with rpio 0.9.7 installed |
This comment has been minimized.
This comment has been minimized.
ghost
commented
Feb 11, 2016
got the exactly same error with this script here:
|
This comment has been minimized.
This comment has been minimized.
PrasadBapatla
commented
Mar 22, 2016
looks like the signature of the spiTransfer() has changed. the rxBuffer is now an argument, not a return value var rpio = require('rpio'); var rxBuffer = newBuffer(8); for (var i = 0; i <= 7; i++) { |
This comment has been minimized.
jamms commentedDec 24, 2015
Hi, I've been trying some node.js experiments on my RPI for the ADC3008 and came across your very interesting blog about it. The issue I have though is that I am not getting the same output with the code examples you have made. When I run 'sudo node spi_example.js' I get this back:
/home/pi/jperkin/node_modules/rpio/lib/rpio.js:446
return binding.spi_transfer(txbuf, rxbuf, len);
^
TypeError: Incorrect arguments
at TypeError (native)
at rpio.spiTransfer (/home/pi/jperkin/node_modules/rpio/lib/rpio.js:446:17)
at Object. (/home/pi/jperkin/spi_example.js:13:26)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
at startup (node.js:141:18)
at node.js:980:3
I don't suppose you have any ideas about this?
Thanks,
jamms