OLinuXimo A20 LIME2 : use GPIO

Started by abriotde, June 10, 2025, 07:02:25 PM

Previous topic - Next topic

abriotde

I have an OLinuXimo-A20-LIME2 card PC. I would like to use GPIO but I don't understand how could I physically connect them. In the manual, all GPIO are listed. I know with one to use, but male pins on the card are to thin for standard jumper wires (https://www.olimex.com/Products/Breadboarding/JUMPER-WIRES/JW-200x40-FM/). I can solder it, it's to thin...

LubOlimex

There are a few options:

1) You can use the LIME2-SHIELD:

https://www.olimex.com/Products/OLinuXino/A20/LIME2-SHIELD/open-source-hardware

2) You can get one or more A20-OLinuXino-LIME2-UEXT adapter(s) - this adapts 0.05" LIME pins of the GPIO/LCD connectors to breadboard-friendly 0.1" step connectors. Notice that it comes WITHOUT CABLES!!!

https://www.olimex.com/Products/OLinuXino/A20/A20-OLinuXino-LIME2-UEXT/open-source-hardware

Cables:

https://www.olimex.com/Products/Components/Cables/Ribbon/CABLE-40-40-10CM/

https://www.olimex.com/Products/Components/Cables/Ribbon/CABLE-IDC40-15cm/

3) You can purchase matching female connectors FEMALE-YAV36P-2x20. This will still require soldering at the female connectors but your board will be safe:

https://www.olimex.com/Products/Components/Connectors/FEMALE-YAV36P-2x20/
Technical support and documentation manager at Olimex

abriotde

Yes, I bought the LIME2-SHIELD, and know I manage to blink a LED... with Shell with this code:

PIN_NUM=53
gpio_init () {
echo "PIN_NUM=${PIN_NUM}"
# echo $PIN_NUM > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio${PIN_NUM}/direction
}
gpio_set () {
val=$1
echo "GPIO set $val"
echo $val > /sys/class/gpio/gpio${PIN_NUM}/value
}
gpio_get () {
echo -n "GPIO = "
cat /sys/class/gpio/gpio${PIN_NUM}/value
}
gpio_init
gpio_get
while true; do
gpio_set 1
gpio_get
sleep 1
gpio_set 0
gpio_get
sleep 1
done

But with C, this code seam to do nothing:

int main() {
sunxi_gpio_init();
unsigned int pin = SUNXI_GPB(21);
sunxi_gpio_set_cfgpin(pin, SUNXI_GPIO_OUTPUT); // Set PB21 as outputtput
sunxi_gpio_pullup(pin, SUNXI_PULL_DOWN); // Enable pull-up on PB21
sunxi_gpio_pullup(pin, SUNXI_PULL_UP); // Enable pull-up on PB21
int i = 0;
while( 1 ) {
printf("Write 1;\n");
sunxi_gpio_output(pin, 1); // Set PB21 high
sleep(1);
printf("Write 0;\n");
sunxi_gpio_output(pin, 0); // Set PB21 low
sleep(1);
}
return 0;
}

I used the lime2-shield doc to convert PIN 53 to B21 but maybe is it wrong?

But in python, it's worst: It's crash with "PermissionError: [Errno 1] Operation not permitted" even in root while overwise, I run in olimex user. And Python init() code, should call sunxi_gpio_init(), the one witch not crash on C...

from pyA20Lime2.gpio import gpio
from pyA20Lime2.gpio import port
from pyA20Lime2.gpio import connector

gpio.init()

abriotde

I have test return code from init() in C code, and it's the open of /dev/mem the problem... Not trivial.

https://askubuntu.com/questions/1467092/dev-mem-and-even-dev-port-cant-open-even-as-root

LubOlimex

#4
Unfortunately, we no longer maintain the customized Python packages like pyA20Lime2. These should be considered abandon-ware. Probably parts or logic in them can be used as basis or inspiration for own work. These packages were made for the Armbian releases, as soon as we switched to mainline Olimage images, we dropped support. The packages are not supposed to work with Olimage out-of-the-box and had never been tested under Olimage. There are few paths forward:

- Adapt the packages for your use, sources can be found at our GitHub;
- Use sysfs to accomplish the same;
- Find similar Python package for the Allwinner A20 chip.

For C code and more refer to "8.6. How to toggle a GPIO pin via sysfs" on page 26 of this document:

https://github.com/OLIMEX/OLINUXINO/blob/master/DOCUMENTS/OLIMAGE/Olimage-guide.pdf
Technical support and documentation manager at Olimex

abriotde

I found the cause of the problem : we can't open /dev/mem. To open this we need to set CONFIG_STRICT_DEVMEM to n witch needs to re-compile Linux kernel and witch is quite complex and unsecure.

So I prefer to stay with sysfs.

I good solution should be to enable the use of all done for Arduino (Witch is open-hardware too). For Raspberry PI (Witch is not), there is https://github.com/WiringPi/WiringPi.git to implement basic Arduino function, in order to use all Arduino solutions.

I had a look to wiringPi/wiringPi.c :

* It need Kernel 5.1, Current Olimage use (5.10.180-olimex), so it's OK

* Some features needs Kernel 6.6.47, but it seem optional...

* There is a detection of Raspberry PI version (piBoard() function), maybe should we had a detection of Olimex?

Is there something done to adapt or a Olimex version of that?

abriotde

I tested with WiringPi... and it run, but do not work... But it work like pyA20Lime2 : with open() in /dev/mem.
To work, we just have to add "O_SYNC | O_CLOEXEC" to open() parameters.
Then mmap() fail, but again, if we change addr_start parameter from 0x1c20000 to 0x20200000, it "work".

In fact I suppose, that I miss-use WiringPi. Maybe is it an other port number witch I should use. Maybe is it an other parmater witch is wrong, because it is design for Raspberry PI. (addr_start for mmap()? Port number? An other parameter?).

I tried some configurations but without success for the moment.