npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rpi-softspi

v1.0.5

Published

Software SPI implementation to use any Raspberry Pi pins as a SPI interface

Downloads

201

Readme

SoftSPI

Codacy Badge Coverage Status npm npm npm

This library contains a javascript class, which implements the SPI (Serial Peripheral Interface Bus) for a Raspberry Pi. In contrast to other libraries it is a software implementation. So it does not use the hardware SPI of the Raspberry Pi and you can choose any pin of the GPIO for the needed logic signals of SPI.

Motivation

I wanted to control some components with my Raspberry Pi, which are using SPI. But a couple of clients (e.g. WS2801 led stripe) do not support a client select. So I needed a software SPI and didn't find one for javascript. Now here is.

Precondition

The library is implemented in ECMAScript 2015, so your project should support at least this version.

Installation

Install it via npm:

$ npm install rpi-softspi

Usage

Start with importing the module via:

var SoftSPI = require("rpi-softspi")

Create an instance for your client device specifying the used pins and needed configurations for the communication in an options object:

let client = new SoftSPI({
   clock: 15,     // pin number of SCLK
   mosi: 11,      // pin number of MOSI
   miso: 13,      // pin number of MISO
   client: 16,    // pin number of CS
   clientSelect: rpio.LOW, // trigger signal for the client
   mode: 0,                // clock mode (0 - 3)
   bitOrder: SoftSPI.MSB   // 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: null,
   miso: null,
   mosi: null,
   client: null,
   clientSelect: rpio.LOW,
   mode: 0,
   bitOrder: SoftSPI.MSB
}

Clock modes are:

| Mode | Polarity | Phase | | :---: | :---: | :---: | | 0 | 0 | 0 | | 1 | 0 | 1 | | 2 | 1 | 0 | | 3 | 1 | 1 |

Start the communication:

client.open()

The SoftSPI is in an invalid state till you open the communication. If it is invalid you cannot transfer data.

Close the communication:

client.close()

Once you close the communication the SoftSPI changes again to invalid state.

Read (only) a number of bytes from the client:

let bytes = client.read(5)
// bytes[0] = first byte

Write data (only) to the client:

client.write([0xff, 0x01, 0xab]) //supply any data

Transfer data to and from the client:

let bytes = client.transfer([0xff, 0x01, 0xab])

The number of returned bytes is the same number of bytes you have supplied

Example

We assume the connected client wants the numbers 1234 and continues to count by returning 5678.

var SoftSPI = require("rpi-softspi")

let client = new SoftSPI({
   clock: 15,     // pin number of SCLK
   mosi: 11,      // pin number of MOSI
   miso: 13,      // pin number of MISO
   client: 16,    // pin number of CS
})

client.open()
let send = [1, 2, 3, 4]
let answer = client.transfer(send)
// Count: 1,2,3,4...5,6,7,8
console.log("Count: " + send.toString() + "..." + answer.toString())
client.close()

API

Check out the documentation for details.

License

MIT

Additional Information

Find a description on Wikipedia - Serial Peripheral Interface Bus or with the keywords SPI as well as Serial Peripheral Interface.