Program compilation issue (in Thonny)

Post Reply
eninede
Posts: 1
Joined: Sat Mar 18, 2023 1:17 am
languages_spoken: english
ODROIDs: ODROID c2
Has thanked: 0
Been thanked: 0
Contact:

Program compilation issue (in Thonny)

Post by eninede »

Hello everyone!
I'm new to the linux, odroid and forum world ;) and probobly becouse of that I have a problem in changing the state of one single pin value in Thonny (python).

I have install everything like it says in https://wiki.odroid.com/odroid-xu4/appl ... o/rpi.gpio

The code of a program look like this:

import RPi.GPIO as GPIO
LedPinW = 4

def setup():
GPIO.setup(GPIO.BCM)
GPIO.output(LedPinW, GPIO.HIGH)
setup()

but the effect is a Thonny message:

"ModuleNotFoundError: No module named 'RPi'"

Why should I do to make the program working right?

User avatar
odroid
Site Admin
Posts: 40816
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 3098 times
Been thanked: 1709 times
Contact:

Re: Program compilation issue (in Thonny)

Post by odroid »

Is the example code in the wiki page working?

BTW, which OS image and kernel version do you use?
As far as I know, the GPIO python example might work only on the old stock image.
https://wiki.odroid.com/odroid-c2/os_images/ubuntu/v4.1

User avatar
meveric
Posts: 12027
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4, GoA v1.1, H2+, HC4, GoS
Has thanked: 82 times
Been thanked: 652 times
Contact:

Re: Program compilation issue (in Thonny)

Post by meveric »

eninede wrote:
Sat Mar 18, 2023 1:38 am
Hello everyone!
I'm new to the linux, odroid and forum world ;) and probobly becouse of that I have a problem in changing the state of one single pin value in Thonny (python).

I have install everything like it says in https://wiki.odroid.com/odroid-xu4/appl ... o/rpi.gpio

The code of a program look like this:

import RPi.GPIO as GPIO
LedPinW = 4

def setup():
GPIO.setup(GPIO.BCM)
GPIO.output(LedPinW, GPIO.HIGH)
setup()

but the effect is a Thonny message:

"ModuleNotFoundError: No module named 'RPi'"

Why should I do to make the program working right?
It's missing the python module RPi.GPIO which exists on several different git repositories with adaptations for ODROIDs.
For example: https://github.com/jfath/RPi.GPIO-Odroid

Sadly these versions are often very Kernel specific and do not run on all Images/Kernels.

More modern Kernel tend to use gpiod a new way to interact with gpios, where you already have command line tools with the OS itself after installing gpiod package.
Example from my ODROID N2:

Code: Select all

root@odroid-bullseye64:~# gpioinfo 
gpiochip0 - 85 lines:
	line   0:      unnamed       unused   input  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused   input  active-high 
	line   4:      unnamed       unused   input  active-high 
	line   5:      unnamed       unused   input  active-high 
	line   6:      unnamed       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
	line   8:      unnamed       unused   input  active-high 
	line   9:      unnamed       unused   input  active-high 
	line  10:      unnamed       unused   input  active-high 
	line  11:      unnamed       unused   input  active-high 
	line  12:      unnamed       unused   input  active-high 
	line  13:      unnamed       unused   input  active-high 
	line  14:      unnamed       unused   input  active-high 
	line  15:      unnamed  "PHY reset"  output   active-low [used open-drain]
	line  16:      unnamed       unused   input  active-high 
	line  17:      unnamed       unused   input  active-high 
	line  18:      unnamed       unused   input  active-high 
	line  19:      unnamed       unused   input  active-high 
	line  20:      unnamed       unused   input  active-high 
	line  21:      unnamed "regulator-hub_5v" output active-high [used]
	line  22:      unnamed "regulator-usb_pwr_en" output active-high [used]
	line  23:      unnamed       unused   input  active-high 
	line  24:      unnamed "regulator-vcc_5v" output active-high [used open-drain]
	line  25:      unnamed       unused   input  active-high 
	line  26:      unnamed       unused   input  active-high 
	line  27:      unnamed       unused   input  active-high 
	line  28:      unnamed       unused   input  active-high 
	line  29:      unnamed       unused   input  active-high 
	line  30:      unnamed       unused   input  active-high 
	line  31:      unnamed       unused   input  active-high 
	line  32:      unnamed       unused   input  active-high 
	line  33:      unnamed       unused   input  active-high 
	line  34:      unnamed       unused   input  active-high 
	line  35:      unnamed       unused   input  active-high 
	line  36:      unnamed       unused   input  active-high 
	line  37:      unnamed      "reset"  output   active-low [used]
	line  38:      unnamed       unused   input  active-high 
	line  39:      unnamed       unused   input  active-high 
	line  40:      unnamed       unused   input  active-high 
	line  41:      unnamed       unused   input  active-high 
	line  42:      unnamed       unused   input  active-high 
	line  43:      unnamed       unused   input  active-high 
	line  44:      unnamed       unused   input  active-high 
	line  45:      unnamed       unused   input  active-high 
	line  46:      unnamed       unused   input  active-high 
	line  47:      unnamed         "cd"   input   active-low [used]
	line  48:      unnamed       unused   input  active-high 
	line  49:     "PIN_44"       unused   input  active-high 
	line  50:     "PIN_46"       unused   input  active-high 
	line  51:     "PIN_45"       unused   input  active-high 
	line  52:     "PIN_47"       unused   input  active-high 
	line  53:     "PIN_26"       unused   input  active-high 
	line  54:      unnamed       unused   input  active-high 
	line  55:      unnamed       unused   input  active-high 
	line  56:      unnamed       unused   input  active-high 
	line  57:      unnamed       unused   input  active-high 
	line  58:      unnamed       unused   input  active-high 
	line  59:      unnamed       unused   input  active-high 
	line  60:     "PIN_42"       unused   input  active-high 
	line  61:     "PIN_32"       unused   input  active-high 
	line  62:      "PIN_7"       unused   input  active-high 
	line  63:     "PIN_27"       unused   input  active-high 
	line  64:     "PIN_28"       unused   input  active-high 
	line  65:     "PIN_16"       unused   input  active-high 
	line  66:     "PIN_18"       unused   input  active-high 
	line  67:     "PIN_22"       unused   input  active-high 
	line  68:     "PIN_11"       unused   input  active-high 
	line  69:     "PIN_13"       unused   input  active-high 
	line  70:     "PIN_33"       unused   input  active-high 
	line  71:     "PIN_35"       unused   input  active-high 
	line  72:     "PIN_15"    "onewire"  output  active-high [used open-drain]
	line  73:     "PIN_19"       unused   input  active-high 
	line  74:     "PIN_21"       unused   input  active-high 
	line  75:     "PIN_24"       unused   input  active-high 
	line  76:     "PIN_23"       unused   input  active-high 
	line  77:      "PIN_8"       unused   input  active-high 
	line  78:     "PIN_10"       unused   input  active-high 
	line  79:     "PIN_29"       unused   input  active-high 
	line  80:     "PIN_31"       unused   input  active-high 
	line  81:     "PIN_12"       unused   input  active-high 
	line  82:      "PIN_3"       unused   input  active-high 
	line  83:      "PIN_5"       unused   input  active-high 
	line  84:     "PIN_36"       unused   input  active-high 
here you can see info about the different GPIOs and can interact with them as easily as:

Code: Select all

root@odroid-bullseye64:~# gpioset 0 69=1
root@odroid-bullseye64:~# gpioset 0 69=0
Which would switch the GPIO mode automatically to output mode, write the value 1 into the GPIO or write the value 0 to the GPIO.
In this case the first 0 is the number of the gpiochip (gpiochip0) 69 is the line (so physical PIN 13) and =1 or =0 is the value you write to the pin, either high or low.
Attaching a LED to pin 13 would result in turning the LED on and off in this example.

There are other commands available as well:
gpiodetect gpiofind gpioget gpioinfo gpiomon gpioset

But once again, this depends on the Kernel (and Image) you use.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

Post Reply

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 1 guest