The library is implemented in ECMAScript 2015, so your project should support at least this version.
Install it via npm:
$ npm install rpi-softspi
Start with importing the module via:
var SoftSPI =
Create an instance for your client device specifying the used pins and needed configurations for the communication in an options object:
let client =clock: 15 // pin number of SCLKmosi: 11 // pin number of MOSImiso: 13 // pin number of MISOclient: 16 // pin number of CSclientSelect: rpioLOW // trigger signal for the clientmode: 0 // clock mode (0 - 3)bitOrder: SoftSPIMSB // bit order in communication
At least you have to specify the clock pin, all other can be left unspecified to use the default configuration
This is the default configuration:
default =clock: nullmiso: nullmosi: nullclient: nullclientSelect: rpioLOWmode: 0bitOrder: SoftSPIMSB
Clock modes are:
Start the communication:
The SoftSPI is in an invalid state till you open the communication. If it is invalid you cannot transfer data.
Close the communication:
Once you close the communication the SoftSPI changes again to invalid state.
Read (only) a number of bytes from the client:
let bytes = client// bytes = first byte
Write data (only) to the client:
client //supply any data
Transfer data to and from the client:
let bytes = client
The number of returned bytes is the same number of bytes you have supplied
We assume the connected client wants the numbers
1234and continues to count by returning
var SoftSPI =let client =clock: 15 // pin number of SCLKmosi: 11 // pin number of MOSImiso: 13 // pin number of MISOclient: 16 // pin number of CSclientlet send = 1 2 3 4let answer = client// Count: 1,2,3,4...5,6,7,8consoleclient
Check out the documentation for details.
Find a description on Wikipedia - Serial Peripheral Interface Bus or with the keywords SPI as well as Serial Peripheral Interface.