pub package Build Status

rpi_spi is a Dart package for using SPI on the Raspberry Pi.


  • The Spi library provides the API for accessing devices using the SPI protocol

  • The RpiSpi library provides implementation of the SPI protocol on the Raspberry Pi derived from the WiringPi library.


Be sure to enable SPI on the Raspberry Pi using

    sudo raspi-config

RpiSpi uses a native library written in C. For security reasons, authors cannot publish binary content to pub.dartlang.org, so there are some extra steps necessary to compile the native library on the RPi before this package can be used. These two steps must be performed when you install and each time you upgrade the rpi_spi package.

  1. Activate the rpi_spi package using the pub global command.
    pub global activate rpi_spi
  1. From your application directory (the application that references the rpi_spi package) run the following command to build the native library
    pub global run rpi_spi:build_lib

pub global activate makes the Dart scripts in the rpi_spi/bin directory runnable from the command line. pub global run rpi_spi:build_lib runs the rpi_spi/bin/build_lib.dart program which in turn calls the build_lib script to compile the native librpi_spi_ext.so library for the rpi_spi package.


  • example.dart demonstrates instantiating and accessing a SPI device.

  • mcp3008.dart demonstractes how the SPI API is used to interact with a MCP3008 analog to digital converter

Connect the following pins on the Raspberry Pi to the following pins on the Adafruit MCP3008. Pi pins 13 and 15 are connected to MCP3008 input #0 for both for the example and as a predictable test input. The other connected Pi pins are for controlling the MCP3008 and reading it's output values via the SPI API.

Rpi PinMCP3008
PIN #13 to 4.7K resistor to --->PIN #1 (CH0)
PIN #15 to 10K resistor to --->PIN #1 (CH0)
PIN #17 (3.3V)PIN #16 (VDD) & PIN #15 (VREF)
PIN #19 (SPI0 MOSI)PIN #11 (DIN)
PIN #23 (SIP0 SCLK)PIN #13 (CLK)
PIN #24 (SPI0 CS0)PIN #10 (CS/SHDN)
PIN #25 (GND)PIN #9 (DGND) & PIN #14 (AGND)