GPIOS in Python

Hi, everybody. I am novice with python and ubuntu. I want to program the GPIO of a khadas Vim 1, exists a library like RPi.GPIO or you can help me, doing a dummies tutorial of python, gpios, and vim.
Thank you everybody.

Hello @angelfraek,

Python GPIO is not supported now, but it’s in our development plan…

Thanks.

Hello,
Has any update been made in this field ? :grinning:

Can you try this?

https://github.com/frank180/RPi.GPIO-Khadas

@numbqq
I’m trying the GPIO on vim3. But saw the “Segmentation fault” error.

Here is some information that might be useful to you.
$ python3 --version

Python 3.7.5

$ sudo python3 testVIM3_ModeBCM_phy15.py

Test with RPI GPIO
Segmentation fault

$ pip3 show RPi.GPIO | grep Version

Version: 0.6.3.post1

@h_m_h We have a new version for it, we will release this month.

Thanks a lot :smile: please let us know when it’s ready.

1 Like

@numbqq thanks for sharing GitHub link of khadas wiringpi (https://github.com/khadas/WiringPi-Python)

I build and install wiringpi with the following commands:

git clone --recursive https://github.com/khadas/WiringPi-Python.git
cd WiringPi-Python
sudo python3 setup.py install

Then I will see the error message failed: Bad file descriptor during wiringpi initialization (wiringPiSetup)

in python3
 
>>> import wiringpi
>>> wiringpi.wiringPiSetup()  
err : wiringPiSetup: mmap (GPIO) failed: Bad file descriptor
 

Yes, you also need to update the kernel if you want to use this version.

Please wait our release this month.

Thanks.

1 Like

Keen to use wiringpi form python, just tried it with recent ubuntu kernel and its seg faulting, any progress?

some worked examples in python would be great!

You need to use the 4.9 kernel.

Please check this docs:

1 Like

need to use gpio’s form wiring pi on vim1, using this image VIM1_Ubuntu-server-bionic_Linux-4.9_arm64_EMMC_V20191231.img with apt upgrade, but still getting

Oops: Unable to determine board revision from /proc/cpuinfo
-> No “Revision” line
-> You’d best google the error to find out why.

I guess using pip3 install wiringpi is not the right thing to do to get your version, please advise what we should use?

I just tried cloning GitHub - yan-wyb/WiringPi: WiringPi for Khadas boards and using ./build, still get the following

import wiringpi
wiringpi.wiringPiSetup()
Oops: Unable to determine board revision from /proc/cpuinfo
→ No “Revision” line
→ You’d best google the error to find out why.

You don’t need to install WiringPi manually.

Just with frash install of VIM1_Ubuntu-server-bionic_Linux-4.9_arm64_EMMC_V20191231.img and simply upgrade the system, after that you can use the WiringPi.

1 Like

just tested that on a fresh board and that works, but… I’m using a docker container to host the application, I need to get wiringpi into that container so how can install the right wiringpi in a container?

Also looking at the gpio readall command on the host is there more docuemntation on the ALTx modes that are shown here for example

| 29 | P/U | | 0 | ALT4 | PIN.H7 | 10 | 423 |

29 - 32 for example are in ALT3 or ALT4, what does that mean?

thanks

I’ve removed wiringpi from my docker setup to see what issues it raised, it shows that the stock pip3 install of wiringpi lets me access the i2c ports just fine so that does not validate the gpio setup.

So I need a wiringpi install method for docker containers on VIM1, ideas?

david

I haven’t tried to use WiringPi in the Docker container, but the WiringPi depends on some devide note, so you need to add such devices to the container.

I have a quick attemption on my side to run WiringPi in a Ubuntu 20.04 container, here are some instructions:

  • Start docker container (Ubuntu 20.04) with --device param.
$ docker run -it --device=/dev/gpiomem:/dev/gpiomem --device=/dev/gpiomem-ao:/dev/gpiomem-ao --cap-add SYS_ADMIN ubuntu
root@f5de15e232a2:/#
  • Install WiringPi in the docker container:
root@f5de15e232a2:/# wget https://dl.khadas.com/repos/vim3/pool/main/w/wiringpi/python3-wiringpi_3.11-1_arm64.deb
root@f5de15e232a2:/# wget https://dl.khadas.com/repos/vim3/pool/main/w/wiringpi/wiringpi_3.11-1_arm64.deb
root@f5de15e232a2:/# apt install -f
root@f5de15e232a2:/# gpio readall
 +------+-----+----------+------+---+----+---- Model  Khadas VIM3 --+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 |      |     |       5V |      |   |    |       |  1 || 21 |       |    |   |      | GND      |     |      |
 |      |     |       5V |      |   |    |       |  2 || 22 | P/U   |    | 1 | ALT1 | PIN.A15  | 6   |  475 |
 |      |     |   USB_DM |      |   |    |       |  3 || 23 | P/U   |    | 1 | ALT1 | PIN.A14  | 7   |  474 |
 |      |     |   USB_DP |      |   |    |       |  4 || 24 |       |    |   |      | GND      |     |      |
 |      |     |      GND |      |   |    |       |  5 || 25 | P/U   |    | 1 | ALT0 | PIN.AO2  | 8   |  498 |
 |      |     |   MCU3V3 |      |   |    |       |  6 || 26 | P/U   |    | 1 | ALT0 | PIN.AO3  | 9   |  499 |
 |      |     |  MCUNRST |      |   |    |       |  7 || 27 |       |    |   |      | 3V3      |     |      |
 |      |     |  MCUSWIM |      |   |    |       |  8 || 28 |       |    |   |      | GND      |     |      |
 |      |     |      GND |      |   |    |       |  9 || 29 | P/D   |    | 0 | ALT0 | PIN.A1   | 10  |  461 |
 |      |  18 |     ADC0 |      |   |    |       | 10 || 30 | P/D   |    | 1 | ALT0 | PIN.A0   | 11  |  460 |
 |      |     |      1V8 |      |   |    |       | 11 || 31 | P/D   |    | 0 | ALT0 | PIN.A3   | 12  |  463 |
 |      |  19 |     ADC1 |      |   |    |       | 12 || 32 | P/D   |    | 0 | ALT0 | PIN.A2   | 13  |  462 |
 |  506 |   1 | PIN.AO10 | ALT3 | 0 |    |   P/U | 13 || 33 | P/D   |    | 0 | ALT1 | PIN.A4   | 14  |  464 |
 |      |     |     GND3 |      |   |    |       | 14 || 34 |       |    |   |      | GND      |     |      |
 |  433 |   2 |   PIN.H6 | ALT1 | 0 |    |   P/D | 15 || 35 | P/D   |    | 0 | ALT3 | PWM-F    | 15  |  432 |
 |  434 |   3 |   PIN.H7 | ALT1 | 1 |    |   P/D | 16 || 36 |       |    |   |      | RTC      |     |      |
 |      |     |      GND |      |   |    |       | 17 || 37 | P/D   |    | 0 | IN   | PIN.H4   | 16  |  431 |
 |  497 |   4 |  PIN.AO1 | ALT0 | 1 |    |   P/U | 18 || 38 |       |    |   |      | MCU-FA1  |     |      |
 |  496 |   5 |  PIN.AO0 | ALT0 | 1 |    |   P/U | 19 || 39 | P/D   |    | 0 | IN   | PIN.Z15  | 17  |  426 |
 |      |     |      3V3 |      |   |    |       | 20 || 40 |       |    |   |      | GND      |     |      |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+

Fot more information about the docker usage please refer the the official documentation.

3 Likes

will RPi.GPIO come to khadas vim1