Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

FeatherS2 with RGB matrix
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

FeatherS2 with RGB matrix

by drm1 on Sat Oct 23, 2021 9:21 pm

Now that rgbmatrix is supported on the FeatherS2 (ESP32-S2 board), I think it should be possible to drive a HUB75 RGB matrix.

The library requires certain pins to be on the same port of the microcontroller. But what pins are on what ports for that board? Is there a standard wiring for this board and a 64x32 RGB matrix?

(Old thread:https://forums.adafruit.com/viewtopic.php?f=60&t=174112&p=848775)

Thanks for any advice.

drm1
 
Posts: 8
Joined: Tue Apr 16, 2013 9:19 am

Re: FeatherS2 with RGB matrix

by tannewt on Mon Oct 25, 2021 3:56 pm

I believe the port restriction was lifted for the ESP32-S2 because it has an output matrix for GPIO. If not, I'd go by the GPIO numbering because it matches the internal pin numbering.

tannewt
 
Posts: 2683
Joined: Thu Oct 06, 2016 8:48 pm

Re: FeatherS2 with RGB matrix

by drm1 on Tue Oct 26, 2021 9:37 pm

Thank you for your reply. If that's the case, then it's puzzling that rgbmatrix is throwing an error ("ValueError: rgb_pins[0] is not on the same port as clock"). The origin appears to be a function in RGBMatrix.c, quoted below. Any chance that this does not actually apply to ESP32-S2?



Code: Select all | TOGGLE FULL SIZE
STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_t rgb_pin_count, bool allow_inefficient) {
    uint32_t port = clock_pin / 32;
    uint32_t bit_mask = 1 << (clock_pin % 32);

    if (rgb_pin_count <= 0 || rgb_pin_count % 6 != 0 || rgb_pin_count > 30) {
        mp_raise_ValueError_varg(translate("The length of rgb_pins must be 6, 12, 18, 24, or 30"));
    }

    for (uint8_t i = 0; i < rgb_pin_count; i++) {
        uint32_t pin_port = rgb_pins[i] / 32;

        if (pin_port != port) {
            mp_raise_ValueError_varg(
                translate("rgb_pins[%d] is not on the same port as clock"), i);
        }

        uint32_t pin_mask = 1 << (rgb_pins[i] % 32);
        if (pin_mask & bit_mask) {
            mp_raise_ValueError_varg(
                translate("rgb_pins[%d] duplicates another pin assignment"), i);
        }

        bit_mask |= pin_mask;
    }

    if (allow_inefficient) {
        return;
    }

    uint8_t byte_mask = 0;
    if (bit_mask & 0x000000FF) {
        byte_mask |= 0b0001;
    }
    if (bit_mask & 0x0000FF00) {
        byte_mask |= 0b0010;
    }
    if (bit_mask & 0x00FF0000) {
        byte_mask |= 0b0100;
    }
    if (bit_mask & 0xFF000000) {
        byte_mask |= 0b1000;
    }

    uint8_t bytes_per_element = 0xff;
    uint8_t ideal_bytes_per_element = (rgb_pin_count + 7) / 8;

    switch (byte_mask) {
        case 0b0001:
        case 0b0010:
        case 0b0100:
        case 0b1000:
            bytes_per_element = 1;
            break;

        case 0b0011:
        case 0b1100:
            bytes_per_element = 2;
            break;

        default:
            bytes_per_element = 4;
            break;
    }

    if (bytes_per_element != ideal_bytes_per_element) {
        mp_raise_ValueError_varg(
            translate("Pinout uses %d bytes per element, which consumes more than the ideal %d bytes.  If this cannot be avoided, pass allow_inefficient=True to the constructor"),
            bytes_per_element, ideal_bytes_per_element);
    }
}

drm1
 
Posts: 8
Joined: Tue Apr 16, 2013 9:19 am

Re: FeatherS2 with RGB matrix

by jepler on Thu Oct 28, 2021 10:30 am

I checked the source for the RGB matrix driver and yes -- for esp32-s2 it is a requirement that the clock and data pins all be on a single I/O register. Here is the C code that is used:
Code: Select all | TOGGLE FULL SIZE
#define PEW                                                                    \
  *set = (*data++) << shift; /* Set RGB data high */                           \
  *clear_full = 0;           /* ESP32 MUST sync before 2nd 'set' */            \
  *set = clock;              /* Set clock high */                              \
  *clear_full = rgbclock;    /* Clear RGB data + clock */                      \
  ///< Bitbang one set of RGB data bits to matrix

jepler
 
Posts: 40
Joined: Mon Oct 28, 2013 4:16 pm

Re: FeatherS2 with RGB matrix

by drm1 on Thu Oct 28, 2021 3:31 pm

Thank you for this as well. I have spend some time with the datasheet and technical reference but have not found a list of what GPIOs are on which register. Do you know of a place this is listed for the ESP32-S2?

drm1
 
Posts: 8
Joined: Tue Apr 16, 2013 9:19 am

Re: FeatherS2 with RGB matrix

by jepler on Thu Oct 28, 2021 7:41 pm

In the GPIO numbering, 31 and under are in the first port and 32 and over are in the second port.

You can see how GPIO numbering relates to silk / "board module" naming in this C file, which applies to the Unexpected Maker Feather S2: https://github.com/adafruit/circuitpyth ... rs2/pins.c

jepler
 
Posts: 40
Joined: Mon Oct 28, 2013 4:16 pm

Re: FeatherS2 with RGB matrix

by drm1 on Fri Oct 29, 2021 9:34 am

Thank you.

drm1
 
Posts: 8
Joined: Tue Apr 16, 2013 9:19 am

Re: FeatherS2 with RGB matrix

by drm1 on Fri Nov 05, 2021 11:09 pm

This combination worked for me, in case it's useful to anyone else.


Code: Select all | TOGGLE FULL SIZE
matrix = rgbmatrix.RGBMatrix(
    width=64, height= 32, bit_depth=4,
    rgb_pins=[board.D14, board.D15, board.D16, board.D17, board.D18, board.D19],
    addr_pins=[board.D6, board.D5, board.D11, board.D10],
    clock_pin=board.D13, latch_pin=board.D12, output_enable_pin=board.D9)
display = framebufferio.FramebufferDisplay(matrix)

drm1
 
Posts: 8
Joined: Tue Apr 16, 2013 9:19 am

Re: FeatherS2 with RGB matrix

by squirrel_oak on Tue Nov 30, 2021 11:27 am

Thanks for your work on this. I'm trying to get the ESP-S2 to work with a feathering matrix as well. I'm working with Circuitpython, but I think these pin addresses are what I need to make the Adafruit example code work.

But, i'm still getting error:

Traceback (most recent call last):
File "<stdin>", line 30, in <module>
AttributeError: 'module' object has no attribute 'D19'


Adafruit, please update the featherwing guide for the new ESP32-S2s!

squirrel_oak
 
Posts: 10
Joined: Sun Sep 26, 2021 11:03 am

Re: FeatherS2 with RGB matrix

by drm1 on Tue Nov 30, 2021 4:35 pm

I haven't used it myself, but I do note that the product page says "This wing is only tested/designed to work with the RP2040, SAMD21 M0 and SAMD51 M4 Feathers." That said, if you want to post your code maybe someone here can help.

If that is the only error, perhaps the wing doesn't expose D19 and you need to use another pin, or maybe there is some small typographical error.

drm1
 
Posts: 8
Joined: Tue Apr 16, 2013 9:19 am

Please be positive and constructive with your questions and comments.