Extra
January 19, 2022, 3:33pm
#1
Hello,
I’m using an Rpi 4 with Manjaro Gnome and python to try a get a button to work.
I went to create a test script for my button, so when I push it it prints a message to the screen but I get module errors.
Here’s what I did. I downloaded python-raspberry-gpio and python-gpiozero from the add/remove software (Manjaro App Store) But when I try:
import RPi.GPIO as GPIO
I get an error saying there is no module RPI.GPIO
Why is that and how can I fix it?
Thanks in advance.
P.S
I also tried everything here with no luck.
This was the code I used (I found it off the internet)
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 10 to be an input pin and set initial value to be pulled low (off)
while True: # Run forever
if GPIO.input(10) == GPIO.HIGH:
print("Button was pushed!")
Dulbi
January 20, 2022, 10:21am
#2
Have you try AUR (en) - python-rpi-gpio ?
I used to use it even the project is not too reactive
Strit
January 20, 2022, 2:57pm
#3
The latest stable release of the RPi.GPIO python module is 0.7.0 , which was released almost 2 years ago.
The AUR package that @Dulbi linked above is indeed newer, but it’s an alpha release, so be aware of that.
Dulbi
January 20, 2022, 5:08pm
#4
The one which comes with the AUR package is 0.7.1a4 and almost 1 year old (2021-03-01).
According to the Change Log, you get a
Better RPi board + peri_addr detection (issue 190 / 191)
As I said it was not too reactive and you can wait a long time before HW detection change on the code when new device appears. But, I used to used it and AFAIK it worked.
Extra
January 20, 2022, 5:26pm
#5
So I did:
git clone https://aur.archlinux.org/python-rpi-gpio.git
cd python-rpi-gpio
makepkg -si
And got:
Error: Failure while downloading https://sourceforge.net/code-snapshots/hg/r/ra/raspberry-gpio-python/code/raspberry-gpio-python-code-08048dd1894a6b09a104557b6eaa6bb68b6baac5.zip
Aborting....
Am I doing something wrong?
Dulbi
January 20, 2022, 5:52pm
#6
Why don’t you use pamac to install it ?
pamac install python-rpi-gpio
You’re right the source was not available (sourceforce cache retention ?). If I use the sourceforge web interface and generate the snapshot and get the same. Now, it seems to be ok:
https://sourceforge.net/code-snapshots/hg/r/ra/raspberry-gpio-python/code/raspberry-gpio-python-code-08048dd1894a6b09a104557b6eaa6bb68b6baac5.zip
Could you please try again ?
Extra
January 20, 2022, 5:56pm
#7
Is there an alternative I can use then?
Dulbi
January 20, 2022, 5:58pm
#9
Could you please try again ?
Extra
January 20, 2022, 6:00pm
#10
Did the makepkg -si
again and got Error: One or more files did not pass the validity check!
Dulbi
January 20, 2022, 6:03pm
#11
The sha256sum is wrong it’s
7f0b64e206ba2bd222e08c0558e9fb910be041c11a7970443a90ef8b42e7344a
you cand edit the PKGBUILD with this value or ‘SKIP’
Extra
January 20, 2022, 6:05pm
#12
How would I do that? I’m kinda new at this.
Thanks for the help by the way. It’s much appreciated.
Dulbi
January 20, 2022, 6:07pm
#13
If you git clone the repo, just use a text editor (nano or vi) to edit the PKGUILD file with this new entry.
If you use pamac, the command with prompt if you want to edit it directly.
Extra
January 20, 2022, 6:13pm
#14
Thanks. It worked. I’ll I’ll try importing it in my python script and see how that goes.
1 Like
Extra
January 20, 2022, 6:27pm
#15
Well good news, there’s no import error. I just have to run my python script as root.
Now I’m trying to figure out if it’s my button that’s not working or my script, because when I push the button, nothing happens.
Dulbi
January 20, 2022, 10:59pm
#16
Good to know.
Did you enable SPI? I guess that the protocol needed for that pin SPI0: MOSI (GPIO10) ?
lsmod | grep spi_
Extra
January 24, 2022, 3:03pm
#17
No. How do I enable SPI0? (Or another pin for that matter. Still can’t get them to work)
Dulbi
January 24, 2022, 4:15pm
#18
What did you get from “lsmod” ?
I guess you can add the following line to /boot/config.txt
dtparam=spi=on
And reboot.
Please, check with lsmod after the reboot.
Edit: spaces removed
Extra
January 24, 2022, 4:35pm
#19
This is what I got from lsmod after adding dtparam = spi = on to the boot config text:
Module Size Used by
rfcomm 53248 4
snd_seq_dummy 16384 0
snd_hrtimer 16384 1
snd_seq 86016 7 snd_seq_dummy
snd_seq_device 20480 1 snd_seq
cmac 16384 2
algif_hash 20480 1
algif_skcipher 20480 1
af_alg 32768 6 algif_hash,algif_skcipher
bnep 28672 2
hci_uart 49152 1
btbcm 24576 1 hci_uart
bluetooth 479232 33 hci_uart,btbcm,bnep,rfcomm
ecdh_generic 16384 1 bluetooth
ecc 32768 1 ecdh_generic
evdev 24576 7
joydev 28672 0
zram 28672 1
zsmalloc 36864 1 zram
brcmfmac 323584 0
brcmutil 24576 1 brcmfmac
sha256_generic 16384 0
sha256_arm64 28672 0
cfg80211 868352 1 brcmfmac
bcm2835_isp 32768 0
bcm2835_codec 49152 0
rfkill 36864 8 bluetooth,cfg80211
bcm2835_v4l2 45056 0
bcm2835_mmal_vchiq 40960 3 bcm2835_codec,bcm2835_v4l2,bcm2835_isp
v4l2_mem2mem 40960 1 bcm2835_codec
videobuf2_vmalloc 20480 1 bcm2835_v4l2
videobuf2_dma_contig 24576 2 bcm2835_codec,bcm2835_isp
videobuf2_memops 20480 2 videobuf2_vmalloc,videobuf2_dma_contig
videobuf2_v4l2 32768 4 bcm2835_codec,bcm2835_v4l2,v4l2_mem2mem,bcm2835_isp
videobuf2_common 61440 5 bcm2835_codec,videobuf2_v4l2,bcm2835_v4l2,v4l2_mem2mem,bcm2835_isp
videodev 311296 6 bcm2835_codec,videobuf2_v4l2,bcm2835_v4l2,videobuf2_common,v4l2_mem2mem,bcm2835_isp
v3d 81920 3
mc 61440 6 videodev,bcm2835_codec,videobuf2_v4l2,videobuf2_common,v4l2_mem2mem,bcm2835_isp
snd_bcm2835 28672 2
rpivid_mem 16384 0
raspberrypi_hwmon 16384 0
gpu_sched 45056 1 v3d
crct10dif_ce 20480 1
vc_sm_cma 36864 2 bcm2835_mmal_vchiq,bcm2835_isp
uio_pdrv_genirq 16384 0
nvmem_rmem 16384 0
uio 24576 1 uio_pdrv_genirq
sch_fq_codel 20480 7
binfmt_misc 24576 1
crypto_user 16384 0
fuse 135168 3
ip_tables 32768 0
x_tables 40960 1 ip_tables
ipv6 536576 140
vc4 282624 14
snd_soc_core 237568 1 vc4
snd_compress 20480 1 snd_soc_core
snd_pcm_dmaengine 20480 1 snd_soc_core
snd_pcm 139264 4 snd_bcm2835,snd_compress,snd_soc_core,snd_pcm_dmaengine
snd_timer 36864 3 snd_seq,snd_hrtimer,snd_pcm
snd 98304 13 snd_seq,snd_seq_device,snd_bcm2835,snd_timer,snd_compress,snd_soc_core,snd_pcm
drm_kms_helper 253952 3 vc4
syscopyarea 16384 1 drm_kms_helper
sysfillrect 16384 1 drm_kms_helper
sysimgblt 16384 1 drm_kms_helper
fb_sys_fops 16384 1 drm_kms_helper
drm 565248 11 gpu_sched,drm_kms_helper,v3d,vc4
drm_panel_orientation_quirks 24576 1 drm
backlight 20480 1 drm
cec 73728 1 vc4
Dulbi
January 24, 2022, 7:35pm
#20
not good.
Could you please show us the result of the following command
dmesg | grep -i spi
0n0w1c
January 24, 2022, 8:20pm
#21
Dulbi:
dtparam = spi = on
No spaces. dtparam=spi=on