Jump to content
  • 0

Orange Pi Zero, Python GPIO Library


Rafał Wolak
 Share

Question

Hello i'm begginer in programing, but i'm learning slowly. I need use gpio pins in my Orange Pi Zero, but i can't find any library that work with my board. Google is not very usefull for me. I was using RPi.GPIO on my RPi projects, but this library don't work on OPi Zero. Can anyone link to working library for python? I need use only 6 output pins.

Link to comment
Share on other sites

Recommended Posts

  • 0

Hi Martin,

I have built and installed the GPIO library on my Orange Pi Zero that you suggested. But unfortunately I noticed that STATUS_LED pin is wrongly mapped after the install. I tried to build and install the library once again after the modification of the mapping.h but after the initialization of led >>>  led1 = port.STATUS_LED and print out >>> print led1 I am getting a wrong pin (15) instead of PA17. How shall I fix this problem? Thanks, Michal

Yes, you have to tweak mapping.h and rebuild the library. If you still having issue, do an "rm -rf build" and then redo an "python setup.py install"

Link to comment
Share on other sites

When discussing a problem make sure to provide full logs!

  • 0

Michal so some pins work (for which the mapping is correct)?  Like pins 3, 5, 7 ,11, 13 and 15?  So with this lib I can do digital high and low?

 

I2c is not connected to this library right, it works standalone? Martinayotte which library would be good to test i2c (do you know if it works on opizero)?

 

Thanks guys for help!

 

Yes the I2C and SPI is part of the library if you clone the git version. but be aware that I2C need to be enabled in the DT or FEX, depending of Legacy/Mainline kernels.

Link to comment
Share on other sites

  • 0

 

Hi msev, all pins except pin 5 work. On pin 5 I am getting the following error:

File "blink_led.py", line 20, in <module>
    led = port.PA5
AttributeError: 'module' object has no attribute 'PA5'
Yes, with this lib I am able to set GPIO pins high and low. Even more, I can read GPIO pins values - HIGH and LOW.

Effectively, there is no PA5 in the mapping.h, simply because PA5 is on Serial Debug UART0_RX.

Link to comment
Share on other sites

  • 0

So which PB's and  which number inside here i should use :) < >

[twi0_para]

twi0_used = 1
twi0_scl = port:PB00<2><default><default><default>
twi0_sda = port:PB01<2><default><default><default>
Link to comment
Share on other sites

  • 0

I must admit I'm not fluent with FEX, since I don't use Legacy any more since over 2 years.

But yes, the number 2 is the MUX for TWI. But pins are not the ones from H3 (PBx don't exist on H3), they should be PA11/PA12 instead.

Be aware that you also need to remove those 2 pins from the GPIOs list and reduce GPIOs count accordingly.

Link to comment
Share on other sites

  • 0

msev, just try it. Get the pinning out from the orange pi zero and try what works.

If you cannot get things to work, you can always provide stuff you tried with examples and then you can be helped in a specific way.

Link to comment
Share on other sites

  • 0

Be aware that you also need to remove those 2 pins from the GPIOs list and reduce GPIOs count accordingly.

 

There is no need to do that, unless you load sunxi-gpio driver but AFAIK nobody use it, even Allwinner removed it from newer BSP kernels.

Link to comment
Share on other sites

  • 0

Yes the I2C and SPI is part of the library if you clone the git version. but be aware that I2C need to be enabled in the DT or FEX, depending of Legacy/Mainline kernels.

Hi,

 

I'm quite new to all this stuff and I tried to find out how to get i2c working with my Orange PI Zero. Is there some guide how to enable the i2c in DT?

Link to comment
Share on other sites

  • 0

The I2C buses are already present in the DT, but "disabled" by default.

You can decompile DTB into DTS, after having done a backup of the DTB, edit it to enabling the buses by changing status "disabled" by "okay", and then recompile DTB for edited DTS.

 

Or you could use DT Overlay, similar to the following :

// Enable the i2c interface
/dts-v1/;
/plugin/;

/ {
    compatible = "allwinner,sun8i-h3";

    fragment@0 {
	target-path = "/aliases";
	__overlay__ {
            /* Path to the i2c controller nodes */
            i2c0 = "/soc@01c00000/i2c@01c2b000";
            i2c1 = "/soc@01c00000/i2c@01c2b400";
        };
    };
    fragment@1 {
        target = <&i2c0>;
        __overlay__ {
            status = "okay";
        };
    };
    fragment@2 {
        target = <&i2c1>;
        __overlay__ {
            status = "okay";
        };
    };
};
Link to comment
Share on other sites

  • 0

 

The I2C buses are already present in the DT, but "disabled" by default.

You can decompile DTB into DTS, after having done a backup of the DTB, edit it to enabling the buses by changing status "disabled" by "okay", and then recompile DTB for edited DTS.

Thanks! After some Googling and your help I now think I managed to get it working. Atleast i2cdetect now gives me an output instead of an error.

Link to comment
Share on other sites

  • 0

@martinayotte

 

I am facing issue with SPI on Oranage Pi Zero / Ubuntu Xenial. When searched on forum I found your post stating that you have run SPI loopback test successfully on OPi Zero. I am running SPI loopback test and my results are same (all zeros) if I connect MOSI/MISO pin or do NOTconnect them. So I doubt that SPI is fine at least for me. Can you please let me know what is the expected output for loopback test. My test results are

 

spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
 
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00
 
 
EDIT: I was using spidev0.0 It was my mistake loopback is working fine with spidev1.0
Link to comment
Share on other sites

  • 0

I have problem getting SPI work on Orange Pi Zero nightly build Armbian_5.26.170213_Orangepizero_Ubuntu_xenial_dev_4.10.0.7z.

I decompiled sun8i-h2plus-orangepi-zero.dtd, changed status of spi1 from "disabled" to "okay", disabled UART3 and  led_pins@0 as they share pins, compiled dtb and copied to /boot/dtb. After reboot I did "modprobe spidev" and I still do not see any spi devices in /dev.

Do I do something wrong or is there something different in kernel 4.10.0?

Link to comment
Share on other sites

  • 0

I have problem getting SPI work on Orange Pi Zero nightly build Armbian_5.26.170213_Orangepizero_Ubuntu_xenial_dev_4.10.0.7z.

I decompiled sun8i-h2plus-orangepi-zero.dtd, changed status of spi1 from "disabled" to "okay", disabled UART3 and  led_pins@0 as they share pins, compiled dtb and copied to /boot/dtb. After reboot I did "modprobe spidev" and I still do not see any spi devices in /dev.

If you for some reason selected nightly image with dev kernel, then please ask Google for spidev devicetree bindings or overlays. You need to add extra nodes to the DT and it was discussed already too many times to write it again.

Link to comment
Share on other sites

  • 0

For the orange pi zero use this fork

 

https://github.com/nvl1109/orangepi_PC_gpio_pyH3

 

The original won't work.

 

That fork has the correct mappings for all of the pins. For a quick test try setting pins PA16 or PA15 and see if it works.

 

if you get

AttributeError: 'module' object has no attribute 'PA16'

then you've picked up the wrong module.

 

Link to comment
Share on other sites

  • 0

My Opi0 arrived yesterday, and I immediately installed the "debian_server_For_OrangePizero_v0_9_2.img", default OS.

But after it overheated and crashed during the night, I installed "Armbian_5.25_Orangepizero_Debian_jessie_default_3.4.113.img", instead.

 

After setting up the networking etc. I thought I'd have a go at flashing an led or two and clicking a couple of relays. So I installed the "https://github.com/nvl1109/orangepi_PC_gpio_pyH3", mentioned by m12lrpv.

 

The only problem I encountered was, "fatal error: Python.h: No such file or directory", but "sudo apt-get install python-dev" cured that and it appears to have worked.

 

Running "python orangepi_PC_gpio_pyH3/examples/blink_led.py" makes a little red led on the Opi0 board start flashing, which I assume was the general idea. I've not tried anything more exciting yet, I thought I'd share the good news first :)

Link to comment
Share on other sites

  • 0

Hi All.

I have 4 buttons connected to my gpio on my OPI zero and it all works fine.I use python to get the status.

What I would like to do is make each button have 2 or 3 functions, ie: if press for 1 second or less, perform short.sh, if 2-4 seconds, perform medium.sh and if  greater than 4 second perform long.sh

I have attached my current python code.

Can this be done with this version of gpio for OPI zero?

Thanks in advance for any suggestions.

JB

4button.py

Link to comment
Share on other sites

  • 0
On 2017/2/27 at 7:24 PM, m12lrpv said:

For the orange pi zero use this fork

 

https://github.com/nvl1109/orangepi_PC_gpio_pyH3

 

The original won't work.

 

That fork has the correct mappings for all of the pins. For a quick test try setting pins PA16 or PA15 and see if it works.

 

 

What is different from the original?

The original is also accessible to PA15 PA16.

 

 

Link to comment
Share on other sites

  • 0

I received my OPI Zero today, and am completely new to this.

I'd ordered it because raspberry pi zeros aren't available here and wanted to start small. But GOD what was i thinking? NO documentation, examples, libraries, this thing is a nightmare.

I can't even blink an led using the OrangePi Zero and haven't found any tutorials.

You guys get the point right? I'm very frustrated and would greatly appreciate if you could please make a tutorial outlining everything that needs to be done for blink LED after installing armbian(I got that right, phew).

Please. :D

 

Link to comment
Share on other sites

  • 0

After installing the above python library, simply run this python script :



#!/usr/bin/python

import time
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

gpio.init()

gpio.setcfg(port.STATUS_LED, gpio.OUTPUT)
while True:
    gpio.output(port.STATUS_LED, gpio.HIGH)
    time.sleep(0.25)
    gpio.output(port.PA1, gpio.LOW)
    gpio.output(port.STATUS_LED, gpio.LOW)
    time.sleep(0.25)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...