Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uraimo/1b2733677524b94a35da to your computer and use it in GitHub Desktop.
Save uraimo/1b2733677524b94a35da to your computer and use it in GitHub Desktop.
Using the Pimoroni Unicorn Hat python library with a Nulsom 8x8 Led matrix

The Nulsom rainbow matrix is compatible with the Pimoroni unicorn hat Raspberry Pi library but needs a few modifications. Tested on a Raspberry 2.

Connections

Connect the matrix 5V and GND to the Raspberry, connect the DI pin to P18.

Modifications

Install the unicorn hat library with \curl -sS get.pimoroni.com/unicornhat | bash.

Clone the repo from https://github.com/pimoroni/unicorn-hat, and modify as follow:

diff --git a/python/UnicornHat/unicornhat.py b/python/UnicornHat/unicornhat.py
index 3e6dde9..f088aeb 100644
--- a/python/UnicornHat/unicornhat.py
+++ b/python/UnicornHat/unicornhat.py
@@ -25,6 +25,7 @@ _rotation = 0
 Store a map of pixel indexes for
 translating x, y coordinates.
 """
+"""
 map = [
     [7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 ],
     [8 , 9 , 10, 11, 12, 13, 14, 15],
@@ -35,6 +36,18 @@ map = [
     [55, 54, 53, 52, 51, 50, 49, 48],
     [56, 57, 58, 59, 60, 61, 62, 63]
 ]
+"""
+map = [
+    [56, 48, 40, 32 , 24 , 16 , 8 , 0 ],
+    [57, 49, 41, 33, 25, 17, 9, 1],
+    [58, 50, 42, 34, 26, 18, 10, 2],
+    [59, 51, 43, 35, 27, 19, 11, 3],
+    [60, 52, 44, 36, 28, 20, 12, 4],
+    [61, 53, 45, 37, 29, 21, 13, 5],
+    [62, 54, 46, 38, 30, 22, 14, 6],
+    [63, 55, 47, 39, 31, 23, 15, 7]
+]


def _clean_shutdown():

In python/UnicornHat/ install the modified unicornhat library with:

sudo ./setup.py install

That's all. Verify that everything is working launching the Pimoroni demo in Pimoroni/unicornhat with:

sudo ./demo.py
@uraimo
Copy link
Author

uraimo commented Sep 26, 2016

The Unicorn Hat lib has been modified, so the above diff has changed a bit, now they've added multiple defaults for every Hat they sell, let's add a new matrix for the Nulsom Rainbow Matrix that will be the default:

diff --git a/library/UnicornHat/unicornhat.py b/library/UnicornHat/unicornhat.py
index 3bc2b29..c7276ad 100644
--- a/library/UnicornHat/unicornhat.py
+++ b/library/UnicornHat/unicornhat.py
@@ -58,6 +58,17 @@ PHAT = [
     [31, 23, 15, 7]
 ]

+NULSOM = [
+    [56, 48, 40, 32 , 24 , 16 , 8 , 0 ],
+    [57, 49, 41, 33, 25, 17, 9, 1],
+    [58, 50, 42, 34, 26, 18, 10, 2],
+    [59, 51, 43, 35, 27, 19, 11, 3],
+    [60, 52, 44, 36, 28, 20, 12, 4],
+    [61, 53, 45, 37, 29, 21, 13, 5],
+    [62, 54, 46, 38, 30, 22, 14, 6],
+    [63, 55, 47, 39, 31, 23, 15, 7]
+]
+
 AUTO = None

 def set_layout(pixel_map = AUTO):
@@ -70,7 +81,7 @@ def set_layout(pixel_map = AUTO):
     """
     global _map
     if pixel_map is None:
-        pixel_map = PHAT # Assume PHAT
+        pixel_map = NULSOM # Assume PHAT
         try:
             product = open("/proc/device-tree/hat/product","r").read().strip()
             if product[:11] == "Unicorn HAT":

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