Skip to content

TypeError: 'bytearray' object does not support item assignment #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chris-schmitz opened this issue Apr 3, 2018 · 10 comments
Closed

Comments

@chris-schmitz
Copy link

I'm new to both python and coding for arduino micro controllers so please bear with me if I missed something obvious.

I'm trying to use the trellis python library on a adafruit trinket M0. I read over the readme and installed the dependency list and installed the adafruit bus device lib directory on my trinket. I also double checked my boot_out.txt file on the trinket and confirmed that I'm a 2.0+ version of circuit python:

Adafruit CircuitPython 2.2.4 on 2018-03-07; Adafruit Trinket M0 with samd21e18

To start out I tried copy/pasting the readme demo code into my main.py file:

import time
import busio
from board import SCL, SDA
from adafruit_trellis import Trellis

# Create the I2C interface
i2c = busio.I2C(SCL, SDA)

# Create a Trellis object for each board
trellis = Trellis(i2c)  # 0x70 when no I2C address is supplied

# Turn on every LED
print('Turning all LEDs on...')
trellis.led.fill(True)
time.sleep(2)

# Turn off every LED
print('Turning all LEDs off...')
trellis.led.fill(False)
time.sleep(2)

The trellis was unresponsive, so I screened into the trinket to watch the output. When I did I received the following error message:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
main.py output:
Traceback (most recent call last):
  File "main.py", line 10, in <module>
  File "adafruit_trellis.py", line 155, in __init__
  File "adafruit_trellis.py", line 111, in fill
  File "adafruit_trellis.py", line 202, in show
TypeError: 'bytearray' object does not support item assignment

I've not dug yet into the adafruit_trellis.py file yet to wrap my head around what's going on. I wanted to post the issue here first to see if there's an obvious thing I'm missing.

Thanks!!

@tannewt
Copy link
Member

tannewt commented Apr 3, 2018

Thanks for the awesome bug report @chris-schmitz ! I think it is a bug.

Hopefully @sommersoft can look at it a bit later today.

@sommersoft
Copy link
Collaborator

To echo @tannewt, thank you for the detailed report. I can definitely look into this later today.

@chris-schmitz
Copy link
Author

No problem at all :) Let me know if there's anything else I can do to help you dig in.

@sommersoft
Copy link
Collaborator

@chris-schmitz, ID'd what was causing this. May take a few days, but the fix will be available soon. If you're comfortable with using mpy-cross locally, you can grab the update from the commit.

Thank you again for putting in the issue. And, thank you for using it! Sorry we had the hiccup; that's all on me for not testing on a non-express board before pushing it out.

@chris-schmitz
Copy link
Author

Nice :D I'm not familiar with mpy-cross(def still green to python), but this sounds like a perfect opportunity to learn it :)

Thank you again for putting in the issue. And, thank you for using it! Sorry we had the hiccup; that's all on me for not testing on a non-express board before pushing it out.

No problem and no worries at all. If it helps make the library better it's worth the effort! I'm just excited that I'll be able to use python for my project! I wrote out some of the logic using cpp and while it's been a good experience, I'd def much prefer using python for it.

@chris-schmitz
Copy link
Author

@sommersoft
So here's what I did:

  • I read up on how to use mpy-cross
  • pulled down the micropython repository
  • ran the make file for mpy-cross
  • moved it to one of my bin folders
  • cloned your trellis repository
  • checked out your commit for the fix
  • ran mpy-cross on the trellis py file to generate the mpy file
  • moved it to my trinket
  • screened in

And I got this error:

Traceback (most recent call last):
  File "main.py", line 4, in <module>
ValueError: Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info.

After reading the link (and some of micropython's repo issues) it seems like I have the wrong version of mpy-cross for the original trellis python file.

Does this sound right? If so, what version of python did you write the original version of the library in?

I'm also cool with waiting for the pull request to be merged in so if you don't have time to help on this question no worries, figuring out mpy-cross (and python dev in general) personal exploration. I can go back and dig more later (just ran out of time at lunch today).

@chris-schmitz
Copy link
Author

Aww yeah!!!

trellis-via-python-yay

@sommersoft The fix from the pull request def fixed my issue!

I'll def pull in the new version of the mpy file once the PR's been approved for this repository, but for now I'm unsuck, moving forward with my project, and have learned a bit of python tooling along the way.

Thanks for the help! It's super appreciated!

@sommersoft
Copy link
Collaborator

@chris-schmitz sweet!!! Glad it's working for you! And keep us updated on your project (on Discord, or maybe Show & Tell Live on Wednesdays?).

@chris-schmitz
Copy link
Author

Def will do. Hmm, I hadn't thought about the show and tell. Maybe I'll try to hop on soon :)

@chris-schmitz
Copy link
Author

@sommersoft thanks again for resolving this issue. I had to set the project aside for a bit because I'm trying to wrap up a project at work and it took up a bit of my free build time, but I'm starting to get back to it and making progress. I've been using circuit python to help me learn python in general and I'm loving it so far.

Thanks for the help. I'm def getting there! https://vimeo.com/265899480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants