Jack Bizon Posted February 26, 2016 Share Posted February 26, 2016 Hi everyone, I need to ask about GPIO pins. I have Cubieboard2 with Armbian (Jessie, Legacy) and I cannot export any GPIO pin as described here http://linux-sunxi.org/GPIO#Accessing_the_GPIO_pins_through_sysfs_with_mainline_kernel, chapter " Accessing the GPIO pins through sysfs with mainline kernel". I was able to play with GPIO this way on Cubian nicely but since Cubian is more or less dead without much support I moved to Armbian. I am able to export only pins with adress 1 or 2 as these are in the script.bin. I quite suspect that I need to change script.fex from GIT, convert to script.bin and replace original one on my Cubieboard. Am I correct? And next thing is that I do not understand what this thingy on sunxi-wiki means: "Device Drivers ---> GPIO Support ---> /sys/class/gpio/... (sysfs interface)" and how to achieve it. Thanks much for help! Link to comment Share on other sites More sharing options...
Igor Posted February 27, 2016 Share Posted February 27, 2016 This example shows how PH18 is translated to gpio242. PH18 this would be ( 8 - 1) * 32 + 18 = 224 + 18 = 242 (since 'h' is the 8th letter). After you have successfully exported the pin you can access it through /sys/class/gpio/gpio*NUMBER* (in case of PH18 it's /sys/class/gpiogpio242). With /sys/class/gpio/gpio*NUMBER*/direction you can set the pin to out or in using If you recalculate numbers properly, according to the schema described there, it should work. It's tested / proven unless we broke something in last build. Forget about script.bin in mainline kernel. It's there only that you can easy switch back to old kernel if wanted. Link to comment Share on other sites More sharing options...
Jack Bizon Posted February 27, 2016 Author Share Posted February 27, 2016 Thanks for your reply Igor. Well I'm trying PE9 and that gives me (5-1)*32+9=4*32+9=128+9=137, so then I try echo 137 > /sys/class/gpio/export but that gives me -bash: echo : write error : Invalid argument If i try with 1 instead of 137 everything is OK. I tried all possible variants of echo, tee, pipelining commands but I still get the invalid argument error on exporting everything else than 1 and 2. I'm not a linux pro, more like newbie, so i guess it's something stupid. And also, I'm connected through serial line console using PL2303. Could that play any role? Thanks for reply. Link to comment Share on other sites More sharing options...
tkaiser Posted February 27, 2016 Share Posted February 27, 2016 Armbian (Jessie, Legacy [...] chapter " Accessing the GPIO pins through sysfs with mainline kernel". Using 3.4 kernel and trying to follow tutorials for mainline kernel will not work. Try to read from here on http://linux-sunxi.org/GPIO#Accessing_the_GPIO_pins_through_sysfs_on_sunxi-3.4 And since you're using Jessie it should work to do a apt-get install sunxi-tools to get the necessary tools. In case you're still stuck it might be a good idea to post the GPIO configuration from script.bin after translated through bin2fex. 1 Link to comment Share on other sites More sharing options...
Jack Bizon Posted February 27, 2016 Author Share Posted February 27, 2016 I tought it have to do something with kernel. As I need 3.4 kernel, then I had to modify script.bin. I took script.bin from Cubian and from Armbian, merged gpio_para sections together and voilà ... GPIO works nicely on armbian same way as on cubian. I need to do some minor tweaks but I can migrate app to armbian in matter of minutes now. Thanks for your help guys! 1 Link to comment Share on other sites More sharing options...
tkaiser Posted February 28, 2016 Share Posted February 28, 2016 Would be fine if you post your fex modifications here with comments which changes were necessary because of what. In case your changes are bug fixes or general improvements why not letting us include them in the distro? Link to comment Share on other sites More sharing options...
Jack Bizon Posted February 28, 2016 Author Share Posted February 28, 2016 I will be happy to do so! However this is maybe quite specific for cubieboard1/2. I used this Cubian fex https://github.com/mmplayer/sunxi-boards/blob/master/sys_config/a20/cubieboard2_argon.fexand took whole section [gpio_para] and matched it to armbian fex from here https://github.com/igorpecovnik/lib/blob/master/config/cubieboard2.fex. If we take a look onto section [gpio_para] the in armbian there is only this [gpio_para] gpio_used = 1 gpio_num = 2 gpio_pin_1 = port:PH20<1><default><default><1> gpio_pin_2 = port:PH21<1><default><default><1> but in cubian we can see this [gpio_para] gpio_used = 1 gpio_num = 67 gpio_pin_1 = port:PG03<1><default><default><1> gpio_pin_2 = port:PB19<1><default><default><1> gpio_pin_3 = port:PB18<1><default><default><1> gpio_pin_4 = port:PG06<1><default><default><1> gpio_pin_5 = port:PG05<1><default><default><1> gpio_pin_6 = port:PG04<1><default><default><1> gpio_pin_7 = port:PG01<1><default><default><1> gpio_pin_8 = port:PG02<1><default><default><1> gpio_pin_9 = port:PG00<1><default><default><1> gpio_pin_10 = port:PH14<1><default><default><1> gpio_pin_11 = port:PH15<1><default><default><1> gpio_pin_12 = port:PI06<1><default><default><1> gpio_pin_13 = port:PI05<1><default><default><1> gpio_pin_14 = port:PI04<1><default><default><1> gpio_pin_15 = port:PG11<1><default><default><1> gpio_pin_16 = port:PG10<1><default><default><1> gpio_pin_17 = port:PG09<1><default><default><1> gpio_pin_18 = port:PG08<1><default><default><1> gpio_pin_19 = port:PG07<1><default><default><1> gpio_pin_20 = port:PE08<1><default><default><1> gpio_pin_21 = port:PE07<1><default><default><1> gpio_pin_22 = port:PE06<1><default><default><1> gpio_pin_23 = port:PE05<1><default><default><1> gpio_pin_24 = port:PE04<1><default><default><1> gpio_pin_25 = port:PI09<1><default><default><1> gpio_pin_26 = port:PI08<1><default><default><1> gpio_pin_27 = port:PI07<1><default><default><1> gpio_pin_28 = port:PD04<1><default><default><1> gpio_pin_29 = port:PD03<1><default><default><1> gpio_pin_30 = port:PD02<1><default><default><1> gpio_pin_31 = port:PD01<1><default><default><1> gpio_pin_32 = port:PD00<1><default><default><1> gpio_pin_33 = port:PE11<1><default><default><1> gpio_pin_34 = port:PE10<1><default><default><1> gpio_pin_35 = port:PE09<1><default><default><1> gpio_pin_36 = port:PD12<1><default><default><1> gpio_pin_37 = port:PD11<1><default><default><1> gpio_pin_38 = port:PD10<1><default><default><1> gpio_pin_39 = port:PD09<1><default><default><1> gpio_pin_40 = port:PD08<1><default><default><1> gpio_pin_41 = port:PD07<1><default><default><1> gpio_pin_42 = port:PD06<1><default><default><1> gpio_pin_43 = port:PD05<1><default><default><1> gpio_pin_44 = port:PD20<1><default><default><1> gpio_pin_45 = port:PD19<1><default><default><1> gpio_pin_46 = port:PD18<1><default><default><1> gpio_pin_47 = port:PD17<1><default><default><1> gpio_pin_48 = port:PD16<1><default><default><1> gpio_pin_49 = port:PD15<1><default><default><1> gpio_pin_50 = port:PD14<1><default><default><1> gpio_pin_51 = port:PD13<1><default><default><1> gpio_pin_52 = port:PB02<1><default><default><1> gpio_pin_53 = port:PD25<1><default><default><1> gpio_pin_54 = port:PD24<1><default><default><1> gpio_pin_55 = port:PD26<1><default><default><1> gpio_pin_56 = port:PD27<1><default><default><1> gpio_pin_57 = port:PD23<1><default><default><1> gpio_pin_58 = port:PD22<1><default><default><1> gpio_pin_59 = port:PD21<1><default><default><1> gpio_pin_60 = port:PI11<1><default><default><1> gpio_pin_61 = port:PI13<1><default><default><1> gpio_pin_62 = port:PI10<1><default><default><1> gpio_pin_63 = port:PI12<1><default><default><1> gpio_pin_64 = port:PB13<1><default><default><1> gpio_pin_65 = port:PB11<1><default><default><1> gpio_pin_66 = port:PB10<1><default><default><1> gpio_pin_67 = port:PH07<1><default><default><1> On cubieboard there is 67 gpio pins that we can use any way we want. The whole magic was to offset cubian [gpio_para] section by factor of 2 and add it to armbian fex. So the result looks like [gpio_para] gpio_used = 1 gpio_num = 69 gpio_pin_1 = port:PH20<1><default><default><1> gpio_pin_2 = port:PH21<1><default><default><1> gpio_pin_3 = port:PG03<1><default><default><1> gpio_pin_4 = port:PB19<1><default><default><1> gpio_pin_5 = port:PB18<1><default><default><1> gpio_pin_6 = port:PG06<1><default><default><1> gpio_pin_7 = port:PG05<1><default><default><1> gpio_pin_8 = port:PG04<1><default><default><1> gpio_pin_9 = port:PG01<1><default><default><1> gpio_pin_10 = port:PG02<1><default><default><1> gpio_pin_11 = port:PG00<1><default><default><1> gpio_pin_12 = port:PH14<1><default><default><1> gpio_pin_13 = port:PH15<1><default><default><1> gpio_pin_14 = port:PI06<1><default><default><1> gpio_pin_15 = port:PI05<1><default><default><1> gpio_pin_16 = port:PI04<1><default><default><1> gpio_pin_17 = port:PG11<1><default><default><1> gpio_pin_18 = port:PG10<1><default><default><1> gpio_pin_19 = port:PG09<1><default><default><1> gpio_pin_20 = port:PG08<1><default><default><1> gpio_pin_21 = port:PG07<1><default><default><1> gpio_pin_22 = port:PE08<1><default><default><1> gpio_pin_23 = port:PE07<1><default><default><1> gpio_pin_24 = port:PE06<1><default><default><1> gpio_pin_25 = port:PE05<1><default><default><1> gpio_pin_26 = port:PE04<1><default><default><1> gpio_pin_27 = port:PI09<1><default><default><1> gpio_pin_28 = port:PI08<1><default><default><1> gpio_pin_29 = port:PI07<1><default><default><1> gpio_pin_30 = port:PD04<1><default><default><1> gpio_pin_31 = port:PD03<1><default><default><1> gpio_pin_32 = port:PD02<1><default><default><1> gpio_pin_33 = port:PD01<1><default><default><1> gpio_pin_34 = port:PD00<1><default><default><1> gpio_pin_35 = port:PE11<1><default><default><1> gpio_pin_36 = port:PE10<1><default><default><1> gpio_pin_37 = port:PE09<1><default><default><1> gpio_pin_38 = port:PD12<1><default><default><1> gpio_pin_39 = port:PD11<1><default><default><1> gpio_pin_40 = port:PD10<1><default><default><1> gpio_pin_41 = port:PD09<1><default><default><1> gpio_pin_42 = port:PD08<1><default><default><1> gpio_pin_43 = port:PD07<1><default><default><1> gpio_pin_44 = port:PD06<1><default><default><1> gpio_pin_45 = port:PD05<1><default><default><1> gpio_pin_46 = port:PD20<1><default><default><1> gpio_pin_47 = port:PD19<1><default><default><1> gpio_pin_48 = port:PD18<1><default><default><1> gpio_pin_49 = port:PD17<1><default><default><1> gpio_pin_50 = port:PD16<1><default><default><1> gpio_pin_51 = port:PD15<1><default><default><1> gpio_pin_52 = port:PD14<1><default><default><1> gpio_pin_53 = port:PD13<1><default><default><1> gpio_pin_54 = port:PB02<1><default><default><1> gpio_pin_55 = port:PD25<1><default><default><1> gpio_pin_56 = port:PD24<1><default><default><1> gpio_pin_57 = port:PD26<1><default><default><1> gpio_pin_58 = port:PD27<1><default><default><1> gpio_pin_59 = port:PD23<1><default><default><1> gpio_pin_60 = port:PD22<1><default><default><1> gpio_pin_61 = port:PD21<1><default><default><1> gpio_pin_62 = port:PI11<1><default><default><1> gpio_pin_63 = port:PI13<1><default><default><1> gpio_pin_64 = port:PI10<1><default><default><1> gpio_pin_65 = port:PI12<1><default><default><1> gpio_pin_66 = port:PB13<1><default><default><1> gpio_pin_67 = port:PB11<1><default><default><1> gpio_pin_68 = port:PB10<1><default><default><1> gpio_pin_69 = port:PH07<1><default><default><1> And this way i got access to GPIO pins on my Cubieboard2. Then it was fun and games to get running my PHP app that provides API for control of GPIO pins over internet via GET requests. As you can see really simple change. I think it would be fine to include change like this in distro but as my understanding goes, armbian is about being universal and this is pretty specific for A10 and A20 boards Link to comment Share on other sites More sharing options...
tkaiser Posted February 29, 2016 Share Posted February 29, 2016 As you can see really simple change. I think it would be fine to include change like this in distro but as my understanding goes, armbian is about being universal and this is pretty specific for A10 and A20 boards These GPIO settings are board specific so changing it for one board doesn't affect the others. I would prefer to adopt these changes but lack unfortunately both time/resources to try this out (I've a Cubietruck but always used it just as a NAS). It would be great if you could've a look whether Cubieboard 1 and Cubietruck were handled differently in Cubian and report back so we could adopt these changes. It would be also great if you could provide a mini tutorial regarding your PHP <--> GPIO integration! Link to comment Share on other sites More sharing options...
Jack Bizon Posted February 29, 2016 Author Share Posted February 29, 2016 Quick comparison of [gpio_para] sections from FEX file in text diff tool and verdict is: Cubieboard1 and Cubieboard2 two are absolutely the same. Cubietruck is almost the same, difference is in just two pins. gpio_pin_1 = port:PH20<1><default><default><1> gpio_pin_2 = port:PH10<0><default><default><0> ;gpio_pin_1 = port:PG03<1><default><default><1> ;gpio_pin_2 = port:PB19<1><default><default><1> This is the difference. PG03 and PB19 are commented and PH20 and PH10 are used instead. Don't know why however, i can't get my hands on cubietruck. All in all my change can be used for Cubie1 and 2 without any problems and for cubietruck.. well you can see it up ^ ^... just two pins. About the tutorial... I'm thinking the same because it is easy to forget. I'll dive into some detailed how-to during this week or upcoming weekend but little spoiler right now. 1) start with clean armbian install 2) get apache and php working 3) setup FTP access into /var/www/html for sake of convenience 4) create symlink from /var/www/html/gpio into /sys/class/gpio 5) allow user www-data to read/write in /sys/devices/platform/gpio (chmod -R 777 /sys if you are extremely lazy) Now from /var/www/html PHP scripts should be able to set value on GPIO pins using path gpip/gpio<pin_number>/value . More detailed step by step guide is coming. Link to comment Share on other sites More sharing options...
tkaiser Posted February 29, 2016 Share Posted February 29, 2016 Thx for the answer. I let the different fex files parse for 'normal' usage of the specific pins and it seems only PB10/PB11 are free to use and all the other pins share functionality and defining them as GPIO pins would break that: tk@opennms:/var/git/Armbian/lib/config# for fex in cubie*.fex ; do echo -e "\n\n${fex}:\n"; awk -F'<' '{print $1}' /tmp/lala.txt | cut -d':' -f2 | while read ; do OtherUseage="$(grep ${REPLY} $fex | awk -F" " '{print $1}' | tr "\n" " ")"; echo "${REPLY}: ${OtherUseage}"; done; done cubieboard2dual.fex: PG03: csi_vsync sdc_d1 PB19: twi1_sda PB18: twi1_scl PG06: csi_d2 PG05: csi_d1 sdc_d3 PG04: csi_d0 sdc_d2 PG01: csi_ck sdc_cmd PG02: csi_hsync sdc_d0 PG00: csi_pck sdc_clk PH14: lcdd14 csi_reset csi_reset_b smc_vppen kp_in4 PH15: lcdd15 smc_vppp kp_in5 audio_pa_ctrl PI06: sdc_d0 PI05: sdc_clk PI04: sdc_cmd PG11: csi_d7 PG10: csi_d6 PG09: csi_d5 PG08: csi_d4 PG07: csi_d3 PE08: csi_d4 PE07: csi_d3 PE06: csi_d2 PE05: csi_d1 PE04: csi_d0 PI09: sdc_d3 PI08: sdc_d2 PI07: sdc_d1 PD04: lcdd4 PD03: lcdd3 PD02: lcdd2 PD01: lcdd1 PD00: lcdd0 PE11: csi_d7 PE10: csi_d6 PE09: csi_d5 PD12: lcdd12 PD11: lcdd11 PD10: lcdd10 PD09: lcdd9 PD08: lcdd8 PD07: lcdd7 PD06: lcdd6 PD05: lcdd5 PD20: lcdd20 PD19: lcdd19 PD18: lcdd18 PD17: lcdd17 PD16: lcdd16 PD15: lcdd15 PD14: lcdd14 PD13: lcdd13 PB02: lcd_pwm PD25: lcdde PD24: lcdclk PD26: lcdhsync PD27: lcdvsync PD23: lcdd23 PD22: lcdd22 PD21: lcdd21 PI11: spi_sclk PI13: spi_miso tkey_int compass_int PI10: spi_cs0 PI12: spi_mosi PB13: spi_cs1 ctp_wakeup spdif_dout PB11: PB10: PH07: uart_rx lcd_bl_en lcdd7 ms_clk cubieboard2.fex: PG03: csi_vsync sdc_d1 PB19: twi1_sda PB18: twi1_scl PG06: csi_d2 PG05: csi_d1 sdc_d3 PG04: csi_d0 sdc_d2 PG01: csi_ck sdc_cmd PG02: csi_hsync sdc_d0 PG00: csi_pck sdc_clk PH14: lcdd14 csi_reset csi_reset_b smc_vppen kp_in4 PH15: lcdd15 smc_vppp kp_in5 audio_pa_ctrl PI06: sdc_d0 PI05: sdc_clk PI04: sdc_cmd PG11: csi_d7 PG10: csi_d6 PG09: csi_d5 PG08: csi_d4 PG07: csi_d3 PE08: csi_d4 PE07: csi_d3 PE06: csi_d2 PE05: csi_d1 PE04: csi_d0 PI09: sdc_d3 PI08: sdc_d2 PI07: sdc_d1 PD04: lcdd4 PD03: lcdd3 PD02: lcdd2 PD01: lcdd1 PD00: lcdd0 PE11: csi_d7 PE10: csi_d6 PE09: csi_d5 PD12: lcdd12 PD11: lcdd11 PD10: lcdd10 PD09: lcdd9 PD08: lcdd8 PD07: lcdd7 PD06: lcdd6 PD05: lcdd5 PD20: lcdd20 PD19: lcdd19 PD18: lcdd18 PD17: lcdd17 PD16: lcdd16 PD15: lcdd15 PD14: lcdd14 PD13: lcdd13 PB02: lcd_pwm PD25: lcdde PD24: lcdclk PD26: lcdhsync PD27: lcdvsync PD23: lcdd23 PD22: lcdd22 PD21: lcdd21 PI11: spi_sclk PI13: spi_miso tkey_int compass_int PI10: spi_cs0 PI12: spi_mosi PB13: spi_cs1 ctp_wakeup spdif_dout PB11: PB10: PH07: uart_rx lcd_bl_en lcdd7 ms_clk cubieboard.fex: PG03: csi_vsync PB19: twi1_sda PB18: twi1_scl PG06: csi_d2 PG05: csi_d1 PG04: csi_d0 PG01: csi_ck PG02: csi_hsync PG00: csi_pck PH14: lcdd14 csi_reset smc_vppen kp_in4 PH15: lcdd15 smc_vppp kp_in5 audio_pa_ctrl PI06: spi_sclk sdc_d0 PI05: sdc_clk PI04: sdc_cmd PG11: csi_d7 PG10: csi_d6 PG09: csi_d5 PG08: csi_d4 PG07: csi_d3 PE08: csi_d4 PE07: csi_d3 PE06: csi_d2 PE05: csi_d1 PE04: csi_d0 PI09: sdc_d3 PI08: spi_miso sdc_d2 PI07: spi_mosi sdc_d1 PD04: lcdd4 PD03: lcdd3 PD02: lcdd2 PD01: lcdd1 PD00: lcdd0 PE11: csi_d7 PE10: csi_d6 PE09: csi_d5 PD12: lcdd12 PD11: lcdd11 PD10: lcdd10 PD09: lcdd9 PD08: lcdd8 PD07: lcdd7 PD06: lcdd6 PD05: lcdd5 PD20: lcdd20 PD19: lcdd19 PD18: lcdd18 PD17: lcdd17 PD16: lcdd16 PD15: lcdd15 PD14: lcdd14 PD13: lcdd13 PB02: lcd_pwm PD25: lcdde PD24: lcdclk PD26: lcdhsync PD27: lcdvsync PD23: lcdd23 PD22: lcdd22 PD21: lcdd21 PI11: spi_sclk PI13: spi_miso tkey_int compass_int PI10: spi_cs0 gsensor_int2 PI12: spi_mosi tv_en PB13: ctp_wakeup spdif_dout PB11: PB10: PH07: uart_rx lcd_bl_en lcdd7 ms_clk cubietruck.fex: PG03: csi_vsync sdc_d1 PB19: twi1_sda PB18: twi1_scl PG06: csi_d2 PG05: csi_d1 sdc_d3 PG04: csi_d0 sdc_d2 PG01: csi_ck sdc_cmd PG02: csi_hsync sdc_d0 PG00: csi_pck sdc_clk PH14: lcdd14 csi_reset csi_reset_b smc_vppen kp_in4 PH15: lcdd15 smc_vppp kp_in5 audio_pa_ctrl PI06: sdc_d0 PI05: sdc_clk PI04: sdc_cmd PG11: csi_d7 PG10: csi_d6 PG09: csi_d5 PG08: csi_d4 PG07: csi_d3 PE08: csi_d4 PE07: csi_d3 PE06: csi_d2 PE05: csi_d1 PE04: csi_d0 PI09: sdc_d3 PI08: sdc_d2 PI07: sdc_d1 PD04: lcdd4 PD03: lcdd3 PD02: lcdd2 PD01: lcdd1 PD00: lcdd0 PE11: csi_d7 PE10: csi_d6 PE09: csi_d5 PD12: lcdd12 PD11: lcdd11 PD10: lcdd10 PD09: lcdd9 PD08: lcdd8 PD07: lcdd7 PD06: lcdd6 PD05: lcdd5 PD20: lcdd20 PD19: lcdd19 PD18: lcdd18 PD17: lcdd17 PD16: lcdd16 PD15: lcdd15 PD14: lcdd14 PD13: lcdd13 PB02: lcd_pwm PD25: lcdde PD24: lcdclk PD26: lcdhsync PD27: lcdvsync PD23: lcdd23 PD22: lcdd22 PD21: lcdd21 PI11: spi_sclk PI13: spi_miso tkey_int compass_int PI10: spi_cs0 PI12: spi_mosi ap6xxx_lpo PB13: spi_cs1 ctp_wakeup spdif_dout PB11: PB10: PH07: uart_rx leds_pin_4 lcd_bl_en lcdd7 ms_clk But according to http://linux-sunxi.org/Cubieboard/ExpansionPortsthe two aforementioned pins are also used for LCD. Therefore adopting Cubian's settings might break things for our users. Would be great if you could add the link and these informations to your tutorial since it might help other users to decide which pins they use for GPIO experiments. Link to comment Share on other sites More sharing options...
Recommended Posts