adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.13k stars 1.22k forks source link

Exceptions in adafruit_matrixportal.matrix.Matrix constructor crash MatrixPortal M4 #9674

Open danielmader opened 2 months ago

danielmader commented 2 months ago

CircuitPython version

Adafruit CircuitPython 9.1.4 on 2024-09-17; Adafruit Matrix Portal M4 with samd51j19

Code/REPL

from adafruit_matrixportal.matrix import Matrix

# default pinout:
# R1 - G1
# B1 - GND
# R2 - G2
# B2 - B
# A - D
# C - E
# CLK - LAT
# /OE - E
matrix = Matrix(width=64, height=32)

# alternate pinout:
# R1 - G1
# B1 - GND
# R2 - G2
# B2 - E
# A - B
# C - D
# CLK - LAT
# /OE - GND
addr_pins = [board.MTX_ADDRA, board.MTX_ADDRD, board.MTX_ADDRC, board.MTX_ADDRE, board.MTX_ADDRB] 
matrix = Matrix(width=64, height=32, alt_addr_pins=addr_pins)   
display = matrix.display

Behavior

The used RGB matrix from WaveShare has a different pinout. Changing the relevant pins using a list for alt_addr_pins results in a hard crash:

Adafruit CircuitPython 9.1.4 on 2024-09-17; Adafruit Matrix Portal M4 with samd51j19
>>> 
soft reboot

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Hard fault: memory access or instruction error.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.

Description

No response

Additional information

No response

dhalbert commented 1 month ago

@danielmader There are actually two problems going on here:

  1. You are specifying a matrix of height 32, but you're specifying 5 address lines. That is one too many. See the documentation here about how many address lines are used: https://docs.circuitpython.org/en/latest/shared-bindings/rgbmatrix/index.html#rgbmatrix.RGBMatrix
  2. A ValueError is thrown to tell you about that problem. However, when the VM restarts, there is a hard memory error, and, it goes into safe mode. The memory error is because RGBMatrix does not clean up sufficiently before the ValueErro is thrown.

So we need to fix problem 2, and you should try one less address line, due to problem 1.

danielmader commented 1 month ago

@dhalbert Thank you for giving this issue attention!

I understand issue 1. However, I am still clueless how I can specify the different pinouts from the male plug of the MatrixPortal M4 board to the female socket of the WaveShare RGB matrix. I thought, the only way to do so is to pass the full list of address lines in the order of the pins.

Pinout MatrixPortal M4 vs  WaveShare RGB

dhalbert commented 1 month ago

I thought, the only way to do so is to pass the full list of address lines in the order of the pins.

You should only list as many address pins as are needed -- in this case, four pins. The alt address pins are just substituted for the ones that would be chosen by the library. With an Adafruit matrix the pins used would be [board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC, board.MTX_ADDRD]. That is the default chosen by adafruit_matrixportal based on the given parameters.

The screenshot you gave above for the Waveshare display is not the one I found: https://www.waveshare.com/rgb-matrix-p2.5-64x32.htm.

image

The one you show does not have a D line, but the screenshot I am showing above does. Assuming mine is correct:

It looks like the Waveshare board has the B on Adafruit'sD line, and the E line on Adafruit's B line. The D line is Adafruit's E line. So try [board.MTX_ADDRA, board.MTX_ADDRD, board.MTX_ADDRC, board.MTX_ADDRB].

danielmader commented 1 month ago

Thanks again, and yes, you were fully right about me posting a wrong pinout. I've taken it for this post only from an older version of the wiki without checking, please excuse.

Unfortunately, your suggestion still yields a broken display, at least when I use the higher-level class adafruit_matrixportal.matrix.Matrix instead of your suggested rgbmatrix.RGBMatrix:

from adafruit_matrixportal.matrix import Matrix
[...]
addr_pins = [
    board.MTX_ADDRA, 
    board.MTX_ADDRD, 
    board.MTX_ADDRC,
    board.MTX_ADDRB
]
matrix = Matrix(width=64, height=32, alt_addr_pins=addr_pins)
display = matrix.display

I've posted this as a question to the Adafruit forum, too. Maybe the discussion should be continued there: https://forums.adafruit.com/viewtopic.php?t=213775

dhalbert commented 1 month ago

Maybe the discussion should be continued there: https://forums.adafruit.com/viewtopic.php?t=213775

I"ll follow up there for the pin order.

dhalbert commented 1 month ago

The core issue here to address is that exception failures in the RGBMatrix constructor do not clean up properly, and cause crashes. Moving this forward to 9.x.x.

dhalbert commented 1 month ago

It turns out this diagram has several errors: image I am going to get that fixed!

The schematic is correct, of course: image The E jumper is explained here: https://learn.adafruit.com/adafruit-matrixportal-m4/pinouts#address-e-line-jumper-3072815

The pin-out of the Waveshare panel is the same as the Adafruit panels. Pinouts of our panels are discussed here: https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/new-wiring. Note you have to look for the 64x32 ones.

So you don't need to shuffle the address pins. I think these problems may be power-related, and will discuss that in the forums post.

jepler commented 1 day ago

I want to look into the safe mode reset in particular; I don't know about all the rest.