Accessing BeaglePlay GPIOs and CSI

Hi @gravel,

I have been trying to use the mikrobus pins as gpio also. After installing gpiod using both apt and pip3, I succeeded in running gpioinfo and noted the lines labeled “MIKROBUS_GPIO01_*” were incidentally already labeled as “unused”. Subsequently, I adapted the python script provided above by @toddm (thanks! :slightly_smiling_face:). After attaching an LED and protective circuitry to the mikrobus pin labeled “pwm”, I essentially wrapped the code requesting a line and setting its direction and value inside a function so as to allow myself to naturally cycle through the mikrobus gpio lines one-by-one to see which line number matched the signal name. Here is the code I used, noting that some of the syntax is modified in accordance with the documentation obtained by using, help(gpiod)

import gpiod
import time
def test_line(line_num):
… LED_USR0_PIN = line_num
… gpiochip = gpiod.chip(“gpiochip3”, gpiod.chip.OPEN_BY_NAME)
… mikro_gpio_line = gpiochip.get_line(LED_USR0_PIN)
… config = gpiod.line_request()
… config.consumer = “gpiod_example”
… config.request_type = gpiod.line_request.DIRECTION_OUTPUT
… mikro_gpio_line.request(config, 1)
… mikro_gpio_line.set_value(1)
… time.sleep(0.5)
… mikro_gpio_line.set_value(0)
… time.sleep(0.5)
… mikro_gpio_line.release()

Since the output of gpioinfo had listed the mikrobus gpios as taking up lines 7-14 and 22-25 from gpiochip3, I simply entered sequential integers beginning with 7 into the above function and by my LED flashing observed that ‘PWM’ corresponded to gpio line 11. With respect to your original question, I’d be surprised if ‘CS’ were not among those lines mentioned above… EDIT: ‘CS’ corresponds to line 13 on gpiochip3.

Something that needs be mentioned also is that I am already loading a device tree overlay in /boot/firmware/extlinux/extlinux.conf, which is one of those pre-compiled and included with debian bullseye and is enabled by the following line:

fdtoverlays /overlays/k3-am625-beagleplay-release-mikrobus-set-gpios-all.dtbo

I’m honestly not sure if this .dtbo is entirely necessary as I had previously applied it while toying with the mikrobus pins. It’s also essential to raise the topic of taking sufficient precautions when using the gpio pins with external circuitry, such as a current-blocking diode to prevent accidental loading onto the io pins - eg. via a loose ground connection - which could possibly seriously damage to on-board components.

Good luck and hope this helps :smiley:
N

UPDATE:

I just investigated this further and indeed confirmed that the device tree overlay I used is responsible for availing the mikrobus gpio lines to the user. As mentioned earlier this overlay is found in /boot/firmware/overlays/k3-am625-beagleplay-release-mikrobus-set-gpios-all.dtbo and it came with the monthly release of debian bullseye (minimal) I got from here.