Banana Pi BPI-M4 gpio

Hello,

I was looking how to get BPI-M4 gpios to work. i couldn’t find support for it. Any help ?

Best Regards

Hi,

following are two library/utilities to help you work with GPIO on the banana pis.

For a command line WiringPi2 do

$ git clone https://github.com/BPI-SINOVOIP/BPI-WiringPi2
$ cd BPI-WiringPi2/
$ sudo apt-get update && sudo apt-get install build-essential
$ sudo ./build

This allows you among others to see the current status of you GPIO

$ sudo gpiodetect
gpiochip0 [1f02c00.pinctrl] (32 lines)
gpiochip1 [1c20800.pinctrl] (256 lines)
$ sudo gpio readall
 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 | 227 |   8 |   SDA.1 | ALT5 | 0 |  3 || 4  |   |      | 5v      |     |     |
 | 226 |   9 |   SCL.1 | ALT5 | 0 |  5 || 6  |   |      | 0v      |     |     |
 | 230 |   7 | GPIO. 7 | ALT3 | 0 |  7 || 8  | 0 | ALT3 | TxD     | 15  | 32  |
 |     |     |      0v |      |   |  9 || 10 | 0 | ALT3 | RxD     | 16  | 33  |
 | 231 |   0 | GPIO. 0 | ALT3 | 0 | 11 || 12 | 0 | ALT3 | GPIO. 1 | 1   | 35  |
 | 234 |   2 | GPIO. 2 | ALT3 | 0 | 13 || 14 |   |      | 0v      |     |     |
 | 235 |   3 | GPIO. 3 | ALT3 | 0 | 15 || 16 | 0 | ALT3 | GPIO. 4 | 4   | 34  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | ALT3 | GPIO. 5 | 5   | 100 |
 |  98 |  12 |    MOSI | ALT3 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |  99 |  13 |    MISO | ALT3 | 0 | 21 || 22 | 0 | ALT3 | GPIO. 6 | 6   | 64  |
 |  97 |  14 |    SCLK | ALT3 | 0 | 23 || 24 | 0 | ALT3 | CE0     | 10  | 96  |
 |     |     |      0v |      |   | 25 || 26 | 0 | ALT3 | CE1     | 11  | 66  |
 |  68 |  30 |   SDA.0 | ALT3 | 0 | 27 || 28 | 0 | ALT3 | SCL.0   | 31  | 67  |
 |  71 |  21 | GPIO.21 | ALT3 | 0 | 29 || 30 |   |      | 0v      |     |     |
 |  37 |  22 | GPIO.22 | ALT3 | 0 | 31 || 32 | 0 | ALT3 | GPIO.26 | 26  | 39  |
 |  36 |  23 | GPIO.23 | ALT3 | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  38 |  24 | GPIO.24 | ALT3 | 0 | 35 || 36 | 0 | ALT3 | GPIO.27 | 27  | 361 |
 | 364 |  25 | GPIO.25 | ALT3 | 0 | 37 || 38 | 0 | ALT3 | GPIO.28 | 28  | 359 |
 |     |     |      0v |      |   | 39 || 40 | 0 | ALT3 | GPIO.29 | 29  | 360 |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+

as well as allow you to get or set pins via gpioget/gpioset

For a python library RPi.GPIO do

$ git clone https://github.com/BPI-SINOVOIP/RPi.GPIO
$ cd RPi.GPIO/
$ sudo apt-get update && sudo apt-get install python3-dev
$ sudo python3 setup.py install

(note this banana pi version is based on an older release)

For documentation see:

https://sourceforge.net/p/raspberry-gpio-python/wiki/Examples/

Hallo,

Thank you for replying, i installed the RPI.GPIO as you mentioned. And the installation went successfully. when i run a python3 code that uses the RPI.GPIO it gives me this error :

BPI: gpioLayout(-1) Traceback (most recent call last): File “gpio.py”, line 9, in import RPi.GPIO as GPIO File “/usr/local/lib/python3.5/dist-packages/RPi/GPIO/init.py”, line 23, in from RPi._GPIO import * RuntimeError: This module can only be run on a Raspberry Pi!

how i can fix this ?

Best regards,

Hi,

I tried on my bananapi (which is actually an M64) and it worked fine using following example:

example.py
$ vim example.py
import RPi.GPIO as gpio
import time

gpio.setmode(gpio.BCM)
gpio.setup(18, gpio.OUT)

flag = True

while True:
    if flag == True:
        gpio.output(18, gpio.LOW)
        print("set gpio.18 to 0")
        time.sleep(4)
        flag = False

    else:
        gpio.output(18, gpio.HIGH)
        print("set gpio.18 to 1")
        time.sleep(4)
        flag = True

which output:

output
$ sudo python3 example.py
BPI: gpioLayout(27)
BPI: name[bpi-m64] gpioLayout(27)
enter to sunxi_setup
sunxi_gpio_function
example.py:5: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  gpio.setup(18, gpio.OUT)
sunxi_setup_gpio
sunxi_set_pullupdn
gpio = 18, value = 0
gpio = 35, value = 0
gpio(35) bank(1) num(3)
set gpio.18 to 0
gpio = 18, value = 1
gpio = 35, value = 1
gpio(35) bank(1) num(3)
set gpio.18 to 1
gpio = 18, value = 0
gpio = 35, value = 0
gpio(35) bank(1) num(3)
set gpio.18 to 0
...

Are you sure you used the github version that I wrote in my exmaple and not the ‘official’ one?

Unfortunately I not have an M4 board at hand…

Ahh I see the issue.

I just check and there is indeed no source for bpi-m4.h in the folder, seems nobody has updated the tools with the latest version yet. Creating a bpi-m4.h is probably not the issue, as it mainly defines the pin numbers on the physical board to the gpio ids. But would need a bit of insight on the board detection part of c_gpio_bpi.c.

I will try to do it, but it will be end of this week till I get to this.

@sinovoip1/@sinovoip can you have a look this please and add support for M4 to RPi.GPIO?