Thonny as root

Had the glowbit matrix working very well. Fired it up today and getting an error that
module ‘glowbit’ has no attribute ‘matrix8x8’ in response to the usual test code

import glowbit
matrix = glowbit.matrix8x8()
matrix.demo()

Thought it may be Thonny not opening in root, so tried sudo Thonny to get
sudo: Thonny: command not found

Any thoughts?
Can the glowbit module run under other IDE, like Mu?
I’m new at this…

2 Likes

Hi David,

Welcome!!

You shouldn’t have to run Thonny as root, just to confirm are all of the libraries and dependencies installed?
I’m not overly familiar with Mu but as long as it has Python3 support and the libraries can be accessed you should be good to use it as well!

I haven’t had the chance to tinker around with the matrices yet but I’m sure the Core guys can help out once they’re back in the office!

1 Like

Hi David,

Welcome to the forum!!

It sounds as if the glowbit.py library might be corrupt.

To hopefully fix the error you can paste the following in the terminal:

cd /home/pi/<THE NAME OF YOUR PROJECT FOLDER HERE>
wget https://github.com/CoreElectronics/CE-GlowBit-Python/raw/main/glowbit/glowbit.py

If you’re not familiar with the terminal take a look at Core’s guide! Basics: Getting Started with the Terminal on Raspberry Pi - Tutorial Australia

Would it also be possible to paste in the output of the following? (this can be run by entering it from the REPL or pasted into the main.py code)

import glowbit
print(dir(glowbit))

Liam

Thanks Liamx2.

I remain in a world of pain!

I have uninstalled then reinstalled rpi-ws281x as well as glowbit.

I am getting a different error:

import glowbit

matrix = glowbit.matrix8x8()

Can’t open /dev/mem: Permission denied

Traceback (most recent call last):

File “”, line 1, in

File “/home/pi/.local/lib/python3.9/site-packages/glowbit.py”, line 1494, in init

self.strip.begin()

File “/home/pi/.local/lib/python3.9/site-packages/rpi_ws281x/rpi_ws281x.py”, line 131, in begin

raise RuntimeError(‘ws2811_init failed with code {0} ({1})’.format(resp, str_resp))

RuntimeError: ws2811_init failed with code -5 (mmap() failed)

I have run the terminal command suggested, then re-run the above, same error.

print(dir(glowbit))

[‘_SYSNAME’, ‘builtins’, ‘cached’, ‘doc’, ‘file’, ‘loader’, ‘name’, ‘package’, ‘spec’, ‘array’, ‘colourFunctions’, ‘colourMaps’, ‘gc’, ‘glowbit’, ‘glowbitMatrix’, ‘matrix4x4’, ‘matrix8x8’, ‘micropython’, ‘os’, ‘petme128’, ‘ptr32’, ‘rainbow’, ‘rp2’, ‘stick’, ‘time’, ‘triangle’, ‘ws’]

Surprised that all was perfectly well two days ago…Thanks for any suggestions!

Best, David

PS the terminal command sticks the glowbit.py file in the Home/Pi directory - is that where it should be??

Best, David

Hi David,

From the looks of things, the rpi_ws281x.py library is needing low level access to memory, hence complaining about a lack of access to dev/mem

Taking steps from here:

There are four ways to give your program access to /dev/mem

  1. Run your script as root, but it is dangerous, for the root can do anything in the system.
  2. Using sudo to run you application, such as sudo your_python.py .
  3. You could run this command sudo chmod 777 /dev/men , open the right to all users. Also likely a bad idea
  4. Add you to the group kmem who own /dev/mem, with the command sudo usermod -g kmem yourID

Give 2 or 4 a go, and see if that fixes your issue. We may have to update our guides!
-James

1 Like

Hi James,
I tried 3, but this just changed the error message:
Can’t open /dev/mem: Operation not permitted
Traceback (most recent call last):
** File “/home/pi/Python programs/CE-GlowBit-Python-main/test.py”, line 3, in **
** matrix = glowbit.matrix8x8()**
** File “/home/pi/.local/lib/python3.9/site-packages/glowbit.py”, line 1494, in init**
** self.strip.begin()**
** File “/home/pi/.local/lib/python3.9/site-packages/rpi_ws281x/rpi_ws281x.py”, line 131, in begin**
** raise RuntimeError(‘ws2811_init failed with code {0} ({1})’.format(resp, str_resp))**
RuntimeError: ws2811_init failed with code -5 (mmap() failed)

I don’t know what to put for ‘yourID’, but given 3 failed, I’m not sure this would help.

I could either get another memory card with NOOBS and start all over again, or put glowbit in the box and forget about it.

David

Hi David,

YourID is just your linux username, so likely pi if you haven’t changed it

-James

Sorry James, but I just don’t think it works.

I tried suggestion 4 which made no difference.

I then reinstalled the OS from Recovery mode, ran all the updates, reinstalled the two glowbit libraries as per the Youtube videos, and same error:

matrix=glowbit.matrix8x8()

Can’t open /dev/mem: Permission denied

Traceback (most recent call last):

File “”, line 1, in

File “/home/pi/.local/lib/python3.9/site-packages/glowbit.py”, line 1494, in init

self.strip.begin()

File “/home/pi/.local/lib/python3.9/site-packages/rpi_ws281x/rpi_ws281x.py”, line 131, in begin

raise RuntimeError(‘ws2811_init failed with code {0} ({1})’.format(resp, str_resp))

RuntimeError: ws2811_init failed with code -5 (mmap() failed)

Maybe the software is no longer compatible with the updated OS??

Hi @David197028, the Glowbit guide says " Note: When running from the Raspberry Pi you will need to run Thonny as root. To do this, open a terminal and run sudo thonny."

I had the same issue and it was resolved by doing the above.
This leads to my issue, how do you run a Python script at startup if it requires root privs?
Any tips appreciated.

In #3 above, should the command end in /dev/mem and not /dev/men?
I have the same issue and the error I get is “Can’t open /dev/mem: Operation not permitted”

Thanks, Tariq - it has been over a year, but I’m pretty sure that I followed those instructions carefully.
In any case, I moved on to the pico, and it works fine there!