michal Posted January 24, 2017 Share Posted January 24, 2017 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. Link to comment Share on other sites More sharing options...
martinayotte Posted January 24, 2017 Share Posted January 24, 2017 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" 1 Link to comment Share on other sites More sharing options...
martinayotte Posted January 24, 2017 Share Posted January 24, 2017 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 More sharing options...
martinayotte Posted January 24, 2017 Share Posted January 24, 2017 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. 1 Link to comment Share on other sites More sharing options...
msev Posted January 26, 2017 Share Posted January 26, 2017 Its good that digital pins will work as is out of the box! Is there somewhere a tutorial on how to enable i2c in fex . Sorry for my noobness... Link to comment Share on other sites More sharing options...
martinayotte Posted January 26, 2017 Share Posted January 26, 2017 Although it is not really a tutorial, the FEX guide is here : http://linux-sunxi.org/Fex_Guide Link to comment Share on other sites More sharing options...
msev Posted January 26, 2017 Share Posted January 26, 2017 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 More sharing options...
martinayotte Posted January 26, 2017 Share Posted January 26, 2017 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 More sharing options...
Ribster Posted January 26, 2017 Share Posted January 26, 2017 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 More sharing options...
jernej Posted January 26, 2017 Share Posted January 26, 2017 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 More sharing options...
martinayotte Posted January 26, 2017 Share Posted January 26, 2017 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. Right, I've forgot about that since I don't use Legacy since years ... Link to comment Share on other sites More sharing options...
renaudrenaud Posted January 29, 2017 Share Posted January 29, 2017 I2C is working on pi zero. At the airport right now but tonight or tomorrow I can give you information if you want. I use it to manage an LCD I2C 16*2. Link to comment Share on other sites More sharing options...
ShadowArm Posted January 29, 2017 Share Posted January 29, 2017 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 More sharing options...
martinayotte Posted January 29, 2017 Share Posted January 29, 2017 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 More sharing options...
ShadowArm Posted January 29, 2017 Share Posted January 29, 2017 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 More sharing options...
martinayotte Posted January 29, 2017 Share Posted January 29, 2017 Good ! Don't forget that I2C needs some PullUps on the bus if your device doesn't provide it already. Link to comment Share on other sites More sharing options...
gailu Posted February 12, 2017 Share Posted February 12, 2017 @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 I used spidev_test.c from https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c EDIT: I was using spidev0.0 It was my mistake loopback is working fine with spidev1.0 Link to comment Share on other sites More sharing options...
martinayotte Posted February 12, 2017 Share Posted February 12, 2017 Yes, spidev0.0 is dedicated to on-board SPI Flash. Link to comment Share on other sites More sharing options...
jbuzar Posted February 12, 2017 Share Posted February 12, 2017 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 More sharing options...
zador.blood.stained Posted February 13, 2017 Share Posted February 13, 2017 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 More sharing options...
jbuzar Posted February 13, 2017 Share Posted February 13, 2017 Thanks, I managed to get spidev device appear by adding additional spidev bindings to dts. Link to comment Share on other sites More sharing options...
m12lrpv Posted February 27, 2017 Share Posted February 27, 2017 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. 1 Link to comment Share on other sites More sharing options...
billybangleballs Posted March 1, 2017 Share Posted March 1, 2017 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 1 Link to comment Share on other sites More sharing options...
Johhny Blue Posted March 4, 2017 Share Posted March 4, 2017 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 More sharing options...
Basavarakj Posted March 17, 2017 Share Posted March 17, 2017 Please help me for orange pi with wiringpi library SPI and I2C communication. if possible send some examples. Link to comment Share on other sites More sharing options...
nopnop2002 Posted March 28, 2017 Share Posted March 28, 2017 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 More sharing options...
martinayotte Posted March 28, 2017 Share Posted March 28, 2017 See this commit : https://github.com/nvl1109/orangepi_PC_gpio_pyH3/commit/1bb13a6bfaa13c05efc5bd1dd685ecda14b95358 Link to comment Share on other sites More sharing options...
nopnop2002 Posted March 28, 2017 Share Posted March 28, 2017 6 hours ago, martinayotte said: See this commit : https://github.com/nvl1109/orangepi_PC_gpio_pyH3/commit/1bb13a6bfaa13c05efc5bd1dd685ecda14b95358 OK i understoood. Link to comment Share on other sites More sharing options...
arjun Posted April 1, 2017 Share Posted April 1, 2017 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. Link to comment Share on other sites More sharing options...
martinayotte Posted April 1, 2017 Share Posted April 1, 2017 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) 1 Link to comment Share on other sites More sharing options...
Recommended Posts