GPIO Python or shell

Hello, how to use GPIO from python or shell?

shell ist described here:

maybe you have to use the kernel from github

Thanks, i used kernel from github, but GPIO from shell dosn’t work.

I have not tried yet…on which point is the problem (sysfile exists? Writable? Set but nothing happens?)

Have you read the comments below (some gpio not ready): For GPIO22/GPIO23/GPIO24, we need to set EINTx_BOND_DIS to 1.

Using that functions you must call:

mt_gpio_mode pin mode #no idea,what mode is,maybe pwm,digital or similar

mt_gpio_dir pin dir #dir seems to be in or out

And then write/read the pin with “mt_gpio_out pin value” / “mt_gpio_in pin”

@garywang is that right? Can you explain mode?

i use gpio scheme https://bananapi.gitbooks.io/banana-pi-bpi-r2-open-source-smart-router/content/bpi-r2-gpio-pin-define.html and i have enable gpio 23, but command echo “mode 23 1” > /sys/devices/platform/1000b000.pinctrl/mt_gpio not work, but work echo “mode 25 1” > /sys/devices/platform/1000b000.pinctrl/mt_gpio for pin 16

pin16 is gpio 23, see garys comment, i’ve posted (22-24 not ready yet)…please use another gpio, e.g. 17 (pin11) or 18 (pin 12)

tried with GPIO 18 = Pin12 (seems not working)

have an led with resistor on pin 12 and gnd next to it (pin 14) led stays off

root@bpi-iot-ros-ai:~# echo "dir 12 1">/sys/devices/platform/1000b000.pinctrl/mt_gpio
root@bpi-iot-ros-ai:~# echo "out 12 1">/sys/devices/platform/1000b000.pinctrl/mt_gpio
root@bpi-iot-ros-ai:~# cat /sys/devices/platform/1000b000.pinctrl/mt_gpio
gpio base is 233, total num is 279
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R1] [R0] )
...
  12: 1 0 1 1-1-1-1-1 0
...

As i see, dir will not be written…

Edit: currently dir is inverted… further debugging in https://github.com/BPI-SINOVOIP/BPI-R2-bsp/issues/17

got GPIO working, infos here

3 Likes

all work fine! But i doesn’t detect press button on GPIO 200

You have changed direction to “in” instead of “out”?

Yes, but in kernel 4.4.70 GPIO200 not in list /sys/devices/platform/1000b000.pinctrl/mt_gpio

have you tried the mem-patch? else i have no idea (you can try also 4.14)…maybe @garywang

To get the Pin status, please run command echo “start 200" > /sys/devices/platform/1000b000.pinctrl/mt_gpio, and then cat /sys/devices/platform/1000b000.pinctrl/mt_gpio

cat /sys/devices/platform/1000b000.pinctrl/mt_gpio | grep 200 200: 0 1 0 0-1-1-1-1 0

if button pressed, values not changed

33

hello Gary,

Whats the way to use GPIO 206 as PWM ? Can you write me the Commands for e.g. 50Hz/ 1KHz PWM´s please.

Thanks a lot, René

Hi Rene

Please set the GPIO206 as PWM. image

Please follow below command to configure PWM: echo 3 >/sys/class/pwm/pwmchip0/export echo 200000 >/sys/class/pwm/pwmchip0/pwm3/period echo 100000 >/sys/class/pwm/pwmchip0/pwm3/duty_cycle
echo 1 >/sys/class/pwm/pwmchip0/pwm3/enable

Please refer to link: https://github.com/BPI-SINOVOIP/BPI-R2-bsp/issues/3

I’m not sure what happened on your board, Please make sure GPIO200 is as GPIO mode, and in input state. And maybe you need the command “pullsel 200 1” or “pullsel 200 0” to validate the PIN input state.

@Rene

Remember the access to gpio in 4.14 is different to 4.4

You can download a 4.4 compiled kernel from my gdrive

i know … but is pwm also possible with 4.14 ?

Please say me what is right run GPIO mode on pin 200?