Skip to content

Instantly share code, notes, and snippets.

@dglaude
Last active April 1, 2017 19:07
Show Gist options
  • Save dglaude/54a02a89aaba32abeda65866c11f7e01 to your computer and use it in GitHub Desktop.
Save dglaude/54a02a89aaba32abeda65866c11f7e01 to your computer and use it in GitHub Desktop.
Inspiring LED and other APA on [Pocket]CHIP

I wanted to see if I could drive an stick of APA102 LEDs from my PocketCHIP.

Waiting for the result and delivery of the Kickstarter http://rasp.io/inspiring I made some test with other stick:

Option 1) Pimoroni mote stick countain 16 such APA102 LEDs, fitted with a micro USB. To properly connect that you may need:

1a) A mote stick (https://shop.pimoroni.com/products/mote)

1b) A mote module cable of your prefered size (https://shop.pimoroni.com/products/mote-module-cable)

1c) A micro USB breakout board from Adafruit (https://shop.pimoroni.com/products/adafruit-usb-micro-b-breakout-board)

1d) A stick of 0.1" header (https://shop.pimoroni.com/products/break-away-headers) to fit (or solder) on the PocketCHIP header

1e) 5 female to female jumper-jerky cable (https://shop.pimoroni.com/products/jumper-jerky)

Option 2) Pimoroni Blinkt! stick that countain 8 APA102 LEDs on a female Raspberry Pi header.

To properly connect that you may need:

1a) A Blinkt! (https://shop.pimoroni.com/products/blinkt)

1e) 5 female to female jumper-jerky cable (https://shop.pimoroni.com/products/jumper-jerky)

To connect any of those to your PocketCHIP header, you may want to fit or solder a stick of 0.1" header (https://shop.pimoroni.com/products/break-away-headers). Mine is working without soldering, just because of friction and because the pin are not 100% in a line.

There are basically two way to control APA102.

I) Same cable as below but bit banging GPIO rather than an hardware SPI interface

II) Using an SPI bus with four wires: Ground, 5V, Clock, MOSI (Master Out Slave In) On PocketCHIP for "Clock" is "SPI:SCK" and for "MOSI" is "SPI:SI".

To use GPIO with Python on the [Pocket]CHIP, you may want to use a library similar to the one for Raspberry Pi. Here is what I used:

  • Preparation

sudo apt-get update sudo apt-get install git build-essential python3-dev python3-pip flex bison chip-dt-overlays -y

  • Installing CHIP_IO

git clone https://github.com/xtacocorex/CHIP_IO.git cd CHIP_IO/ sudo python3 setup.py install cd ..

  • Installing spidev (if required)

git clone https://github.com/doceme/py-spidev.git cd py-spidev sudo python3 setup.py install cd ..

  • Create a spi interface (if required)

To control the spi interface of the CHIP, you need a device interface. You can use the following and compare the output to verify if it is present (should not)

$ ls /dev/spi* /dev/spidev32766.0

If not you can write the folowing python script and execute

$ cat spime.py import CHIP_IO.OverlayManager as OM OM.load("SPI2")

sudo python3 spime.py

Then verify again if the spi device is present (hopefully it should be there).

  • Modify Blink! library to use CHIP_IO

Change import RPi.GPIO as GPIO By import CHIP_IO.GPIO as GPIO

Decide on wich GPIO to use and adapt the library for those, I use this:

DAT = "GPIO2" CLK = "GPIO1"

If my pull request (pimoroni/blinkt#52) has not been accepted yet, you will need to make those change:

Replace GPIO.setup([DAT,CLK],GPIO.OUT) By GPIO.setup(DAT,GPIO.OUT) GPIO.setup(CLK,GPIO.OUT)

  • Run any example from Blinkt!

Install the modified Blinkt! library or copy the modified blinkt.py to the example folder.

  • Working with inspiring apa library (not released yet)

If you have SPI working on working on your PocketCHIP, then only one modification is required:

spi.open(32766,0) # using device /dev/spidev32766.0

Without modification, root is required to run the exemple, you can try the following:

sudo python3 apa.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment