Jump to content

Recommended Posts

Posted

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! :)

Posted

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.

Posted

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

  Quote

 

echo 137 > /sys/class/gpio/export

but that gives me

  Quote

 

-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.

Posted
  On 2/26/2016 at 10:47 PM, Jack Bizon said:

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.

Posted

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! :)

Posted

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?

Posted

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

Posted
  On 2/28/2016 at 8:13 PM, Jack Bizon said:

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! :)

Posted

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. :D

 

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. :)

Posted

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:

 

 

  Reveal hidden contents

 

 

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.

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines