# Adding functionality to the python Glowbit library

**URL:** <https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434>\
**Category:** Projects\
**Created:** [27 June 2023 13:05 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434 "2023-06-27T13:05:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [27 June 2023 13:05 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/1 "2023-06-27T13:05:28Z")

</div>

Hey Guys,

First post here, I’m working on expanding the functions of the Glowbit library to address neopixel’s on the 8x8 and 16x16 matrix’s (also the 8 x 32) that are wired in serpentine fashion.

As I’m impressed with the ease of use the library provides for addressing individual neo pixels to do pixel art. Plus I want to avoid using a WLED controller and JSON calls to address the matrix’s as the Glowbit library is a far more efficient way to address neo pixels on a Raspberry Pi so have decided to expand it.

The reason I’m doing this is so I can use them to have an animated banner for an Arcade I am building. I’ll be doing a video over the changes to the library so others can use it to do pixel art on the Pi and with other Neo Pixel matrix’s

You can find my channel here [Paul's Engineering Space - YouTube](https://www.youtube.com/channel/UCH2nSh9hrdWMLxYe991vKrA)

So Talk Soon, and Please be kind and Subscribe, I could do with the Support!

---

<div class="post-metadata">

**Author:** ![Blayden](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/blayden/32/7535_2.png) [@Blayden](https://forum.core-electronics.com.au/u/Blayden)\
**Post date:** [28 June 2023 04:13 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/2 "2023-06-28T04:13:02Z")

</div>

Hey Paul,

Glad to hear you are finding our library and matrixes to be useful for your project! It sounds like an awesome use of those components and I cant wait to see how it turns out!

Cheers,  
Blayden

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [28 June 2023 23:30 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/3 "2023-06-28T23:30:25Z")

</div>

Hi Paul! Welcome to the forums 😃  
It’s great to hear you’re having a good time with the GlowBit libraries, and we always welcome contributions to the repo.

> [@Celcius1](#):
>
> I’m working on expanding the functions of the Glowbit library to address neopixel’s on the 8x8 and 16x16 matrix’s (also the 8 x 32) that are wired in serpentine fashion

The GlowBit library supports custom mapping already! You just need to provide a _map function_ during initialisation using the `mapFunction` argument, eg:

`matrix = glowbit.matrix4x4(pin = 18, mapFunction = my_map)`

You need to define a map function that accepts arguments `(x,y)` and return the LED index that correlates to those coordinates.

For example, a zig-zag or serpentine 4x4 LED matrix would have the **X-Y → Index** map that looks like this diagram:

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/1/171722920f8ff286b86623ca0995febc7c7ce3e6.jpeg)

and you might choose to initialise this mapping in the following way:

```python
def zig_zag_4x4(x,y):
    if y == 0: return 0 + x
    elif y == 1: return 7 - x
    elif y == 2: return 8 + x
    elif y == 3: return 15 - x
    
matrix = glowbit.matrix4x4(pin = 18, mapFunction = zig_zag_4x4)

```

now the setPixelXY() function ought to map correctly to the physical X-Y LED 🙂

This will work with the existing 4x4 and 8x8 and should give you a flying start on working with other matrix dimensions. GlowBit doesn’t yet have a class for matrices of arbitrary dimensions… We just baked fixed classes for the two products that we produce in an attempt to make things simple for beginners.

Let us know how you go!  
Happy making

* * *

PS the arcade HAT on your channel looks great! Do keep us posted on your progress 😃

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [29 June 2023 13:55 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/4 "2023-06-29T13:55:07Z")

</div>

Thanks for the more detailed explanation, I could not find this in the documentation that came with the library. But I’ll still work on updating the library, my best mate, is giving me a hand, and he knows python very well as my code language of choice is C/C++.

But I might focus my efforts by increasing the flexibility of the class definition so you only need to pass a few key variables.

On another note, I found some assist documents written for use with WLED and in the process of adapting it to work with the Glowbit Library to do pixel art

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [30 June 2023 17:05 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/5 "2023-06-30T17:05:00Z")

</div>

![IMG_2054](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/5/528a78f6da356c6bd32d218ba1807b5d5d83c84f.jpeg)  
 ![IMG_2055](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/6/64d583644ab40ee8bc16479070f705d893611d12.jpeg)

Some pics of the Arcade HAT build So far I’ll have a video dropping in the coming days

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [3 July 2023 18:18 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/6 "2023-07-03T18:18:56Z")

</div>

I have the build video uploaded [Arcade HAT Build - YouTube](https://youtu.be/gaAOq6oEbRY)

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [6 July 2023 10:32 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/7 "2023-07-06T10:32:38Z")

</div>

So I got an offer out of the blue from a Representative of PCBWay, and has offered me free PCB manufacture of my next project, as they were apparently impressed with my Circuit design skills and Soldering. I’m only a small channel at the moment.

What do you guys think?

---

<div class="post-metadata">

**Author:** ![Trent5487676](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/trent5487676/32/4583_2.png) [@Trent5487676](https://forum.core-electronics.com.au/u/Trent5487676)\
**Post date:** [6 July 2023 22:51 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/8 "2023-07-06T22:51:40Z")

</div>

Hi Paul,

I haven’t used PCBWay myself so I can’t speak from personal experience to their PCB milling however I have noticed a few very niche combat robotics youtube channels are getting sponsorship from them lately. Ultimately only you will know if accepting sponsorship is the right fit for what you want to achieve with your channel but it is certainly an interesting opportunity.  
Always good to know someone likes your designs and soldering at the very least 🙂

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [12 July 2023 15:19 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/9 "2023-07-12T15:19:26Z")

</div>

So an update, I was testing the board, and found an error in the board manufacture is affecting its operation and the D Type flip-flops where not functioning as intended, not to mention the 1MHz clock from a 555timer ended up running at 230kHz instead of 1MHz

So considering ATMega328’s are back in stock, I’m adjusting the design to go back to using the MCU and I’m also adding an additional screw header to allow easy connection of neo pixels

I have PCB Way making the new boards for me, but by going back to a MCU I can limit the design to a double sided board

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [13 July 2023 12:57 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/10 "2023-07-13T12:57:44Z")

</div>

I just finished speaking with PCB Way once I have the project working and finialised, it will be available as a kit from there website.

I did ask my representative at PCB Way if core (if they wanted to) wanted to look into stocking the kit, they are welcome to place a bulk order, once it becomes available, or access the details on my github.

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [21 September 2023 09:20 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/11 "2023-09-21T09:20:08Z")

</div>

So I’ve been working on trying to get my banner working on the Arcade but I’m running into a syntax error when i go to run the script in the cmdline, as I will eventually have it running in the background

But I’m having a hard time understanding the syntax error its throwing as im still learning python when my language of choice is C.

Syntax error as follows from the SSH cmdline

```auto
pi@retropie:~/RetroPie/banner $ python banner.py
Traceback (most recent call last):
  File "banner.py", line 1, in <module>
    import glowbit
  File "/home/pi/RetroPie/banner/glowbit.py", line 59
    def wheel(self, pos: int) -> int:
                       ^
SyntaxError: invalid syntax

```

Could I get some feedback as to what error I am running into so I can correct it.

And move forward with writing the script to run the arcade banner. See picture attached of arcade with banner

 ![Arcade with Neopixel Banner](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/d/dec6640c5d4bc250cd1e1ce9be3a7f246c6156d1.jpeg)

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [21 September 2023 09:25 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/12 "2023-09-21T09:25:28Z")

</div>

oh here is my code just incase it helps  
[banner code test.zip](https://forum.core-electronics.com.au/uploads/short-url/5XD6TCnbO27gjkJsdZQf4kdKcDy.zip) (17.5 KB)

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [19 December 2023 04:21 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/13 "2023-12-19T04:21:26Z")

</div>

Hi @Celcius1 - i’m sorry this post seemed to have slipped through the cracks.

Did you ever resolve this?  
try executing `python3 banner.py` instead to guarantee that Python3 is being used instead of Python2.7

you may also need to execute with `sudo` if prompted

---

<div class="post-metadata">

**Author:** ![Celcius1](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@Celcius1](https://forum.core-electronics.com.au/u/Celcius1)\
**Post date:** [19 December 2023 09:16 UTC](https://forum.core-electronics.com.au/t/adding-functionality-to-the-python-glowbit-library/17434/14 "2023-12-19T09:16:56Z")

</div>

Hi Michael,

I never did, been focusing on trying to resolve the controller input, with retropie
