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?

hello @sinovoip, can you help with the GPIO issue on the M4? The boards are now practically useless without output. :expressionless:

For those so inclined, you can look into “Controlling GPIOs from the shell (Linux’ sysfs interface for GPIOs)”. So, basically you’d write a script for your hardware which manipulates the files which control the GPIOs. It requires sudo access, but there are ways around that also.

Hi, I am having problems using GPIO through /sys/class/gpio/ at BPI-M4 (raspbian 4.9). The signal output works, but after I set echo “in”> direction, cat <value gives 1, although nothing is connected to it. This happens with all the pins, I tried GPIO4 (physical 33), 2, 41, 40. On the BPI-M64 board with raspbian 4.4, everything worked as it should. Can someone tell me what’s the matter?

Send the sequence of commands.

Assuming all code is correct, my hypothesis is that there are internal pull-up resistors on digital I/O pins which ensure valid logic levels. You would have to drive the pin high or low then read the input.

Test this: Tie the GPIO pin to a 330ohm resistor to ground. Configure the GPIO to input then read it. It should be 0 if configured correctly.

I have already tried raising and lowering the register after echo “out”> direction, it is work correct. But after that echo “in”> direction sets 1 again on the pin. I’ll try to use a resistor, but in bpi-m64 everything works without resistors. I see different options in the gpio exported folder (device, power? a.o.), can they influence the situation?

It works with the resistor as it should, maybe the trace of revisions should it be soldered on the board for all gpio?

Not necessary to solder anything. You just need to be aware of the internal design of the device AND if the pins were assigned for other functions.

The internal pull-up resistor is more common for lower power dissipation but the port would read as 1. Based on your last response, it now seems that the processor for the M64 used pull-down resistors because digital inputs should never be left floating between valid voltage levels.

I still do not understand how, I use gpio without soldering resistors. My project has a 433 hertz signal receiver board, it sets trigger 1 on its five pins. I checked all the gpio pins (green), they are not busy with any processes, they all become 1 with echo “in”>. With the M64 board, at each boot I initialize the pins for reception with a script beforehand and everything works fine. On the m4 board, when connecting 433 boards on all pins, it is always 1 after initialization and I can’t work with it.

Were you able to confirm that you read 0 when you connect the GPIO pin to ground (through a resistor)? If you confirmed this, then it is a matter of configuring you hardware correctly.

The outputs of your board should drive the inputs of the M4.

When are you guys going to update the bpi-m4.h to WiringPi2 File, please i need it as soon as possible