What's best way to determine Pimoroni product from MicroPython?

What’s the best way to determine which Pimoroni product a MicroPython program is running on? I was thinking of adapting the code in Instructables: Battery-Powered Digital Picture Frame Using Pimoroni Inky Frame for the new, smaller 4 inch Inky Frame.

If there’s not a general approach I’ll probably just use get_bounds() like pimoroni-pico/inky_frame_placekitten.py at main · pimoroni/pimoroni-pico · GitHub to retrieve the resolution of the Inky Frame’s screen - is that a reasonable approach?

If you’re trying to pick which display to use to initialize the the pico graphic library I don’t think that will work, since the initalizer sets the size.

if you’re just looking to determine which one it is after initialization, then that would work fine.

AFAICT the only difference between the two is the display itself, so unless there’s some identifier in the board builtin library, the only hope for the first case would be to directly query the display through SPI? I’m still new to the hardware game, so unsure what information it might pass back. I’m afraid you’ll need a more experienced mind than mine to direct you there.

I was curious since I have a project or two that could use automated selection of imports so I peeked at the SPI class in the adafruit library, didn’t see anything obviously useful.

however, assuming you have both, or can ask someone who owns one of the other ones, I’d try

import board
print( board.board_id )


import os
print( os.uname().machine )

one of those might give a different name for each device, and I think would be the canonical way to determine which it is.

but as I mentioned before, if you’re just wanting to know after it’s already initialized, grabbing the dimensions is perfectly acceptable (especially since I’m guessing you’re using it to size the images sent), and potentially saves an import

For the specific case of the Inky Frames there’s a hardware difference between 5.7" and 4" shown on schematic, latter has a 10k pull up on SWITCH_LATCH and a note saying

Pull-up on SWITCH_LATCH is used to detect the display size (4.0")

I’d imagine a battle between weak (50-80) internal pull down and that 10k is used to distinguish between the two. That doesn’t sound like a very flexible approach for future variations but it’s better than nothing.

Deserves a bit more testing but this seems to work to differentiate between the three models of the Inky Frame. I’d prefer it was in a library and reviewed to ensure it’s safe wrt raising what might be the select line on the PSRAM.

### Do a pull down test of I2C_INT / PSRAM_CS (GP3)
i2c_int_psram_cs_input = Pin(IF_I2C_INT_PSRAM_CS_PIN, Pin.IN, pull=Pin.PULL_DOWN)
i2c_int_psram_cs_state = i2c_int_psram_cs_input.value()
### Reset the pin to input for I2C_INT or to output for PSRAM_CS
if i2c_int_psram_cs_state:
    _ = Pin(IF_I2C_INT_PSRAM_CS_PIN, Pin.IN, pull=None)
    _ = Pin(IF_I2C_INT_PSRAM_CS_PIN, Pin.OUT, value=0)

### Do a pull down test of SR_LATCH (GP9)
sr_latch_input = Pin(inky_frame.SR_LATCH, Pin.IN, pull=Pin.PULL_DOWN)
sr_latch_state = sr_latch_input.value()
### Reset the pin state to a low output
_ = Pin(inky_frame.SR_LATCH, Pin.OUT, value=0)

if sr_latch_state:
    from picographics import DISPLAY_INKY_FRAME_4 as DISPLAY  ### 4.0"
elif not i2c_int_psram_cs_state:
    from picographics import DISPLAY_INKY_FRAME_7 as DISPLAY  ### 7.3"
    from picographics import DISPLAY_INKY_FRAME as DISPLAY    ### 5.7"
1 Like