Hot answers tagged

7

GIL is a design specification of the Python language, rather than a limitation of the Raspberry Pi [1] (multiprocessing is possible in Python, often with only a few lines of code [2], but multithreading is generally not). The new processor will have no effect on the limitations associated with GIL.


6

As joan's answer has already pointed out the misunderstanding here is likely how to define and use a function in Python. Joan's approach will sure solve the immediate problem and make the program work. I will however address the underlying issue that is not so much related to the Pi but general Python programming. So how to go about defining and using a ...


4

When you have a recursive function like this (one with too much depth potential), you need to convert it into a loop. In this case you have two functions alternating calling each other: while True: watchopen() watchclose() This will loop forever (as does the original version, you are exiting on a signal), but you can also use some kind of state as a ...


3

That's one way of doing it - it will work. The better way is to use GPIO.wait_for_edge(17, GPIO.RISING) which will pause at that line until the button is pressed (on a RISING or FALLING edge). However, BOARD numbering pin 17 is not a GPIO, it's 3V3. You could also use GPIO Zero which is more intuitive (and uses BCM numbering): from gpiozero import Button ...


2

I had the same problem with the mfrc522 library. I also tried to close the bus from my own code (like you) but it didn't work out. So I decided to read the source code and I saw the 'Close' function which closes opened bus (Basically the code was able to close that bus from inside) and then I added that function to the end of the reading function, then ...


2

BerryConda supports raspbian/jessie, with a may/may not warning about other versions of raspbian. jessie was replaced by stretch and now buster, which is required for Pi 4. announcement of buster


2

this error usually happens when you access the RPI via SSH, you could run: export DISPLAY=0:0 or add it to your bashrc if you want it to be perminantly excuted on every therminal run and ssh connection. EDIT (a great suggestion by roger-jones): you can also set the variable by prefixing it to the command: DISPLAY=0:0 python gui.py. If you SSH with ...


2

Make a counter which you will increment in your while(True) loop, and reset to zero in the keypad handler. Once the counter reaches 5s / 0.2s = 25, you will reset the user-entered code to zero before adding new digits to it.


2

You need to replace ventein with GPIO.output(20, 1) and ventaus with GPIO.output(20, 0). You seem to think you have declared them as functions - you have not.


1

Here is a pigpio Python example. You use the same logic in any programming language. In practice you would use GPIO callbacks on level change rather than polling. The time.sleep(0.01) is kind to other programs which want to run. #!/usr/bin/env python import time import pigpio GPIO=4 pi = pigpio.pi() if not pi.connected: exit() count=0 last_state =...


1

I believe this is a simple issue of running the mpg123 command multiple times. sudo apt-get install mpg123 man mpg123 If you want it in python import subprocess subprocess.run(['mpg123','<your options>'])


1

I just tested it with a python script I wrote myself (not the one you used, but thread is thread I guess). So I used python programname.py >> test.txt & to fork the process of and send output to a textfile "test.txt" so it won't block our console (I'm assuming you are using the raspberry without a GUI, if not you can ignore the last command and ...


1

Well, after further searching I found an okish solution thanks to This post from Constantine Samoilenko What he said was to cleanup the GPIO at the end of the loop, and also to reinstantiate the MFRC522 object each time the loop restarts. (this creates much overhead and is therefor just a dirty hack, but hey, we are speaking about python here, processor ...


1

I'm assuming your using Raspbian Stretch with Desktop or Raspbian Buster with Desktop. Edit the autostart file using: sudo leafpad /etc/xdg/lxsession/LXDE-pi/autostart Autostart file should look similar to: @lxpanel --profile LXDE-pi @pcmanfm --desktop --profile LXDE-pi @xscreensaver -no-splash point-rpi Add your 4 Python programs to the end using @...


1

Don't use while True in a tkinter program. Instead move the taking a measurement code into a function and drop the time.sleep call. Then use the tkinter after method to schedule a call to your measurement method once a second (eg: win.after(1000, self.take_measurement) Tkinter MUST process events promptly to handle drawing on screen, mouse and keyboard ...


1

I install opencv again [best link for install this] and i try to install FFmpeg from repository. affter installation of ffmepg i tried to read ipcamera video stream with this script Note : after finshing opencv cmake, FFmpeg subitems most all get YES. self.stream = cv2.VideoCapture("rtsp://user:password@{}:525/stream2".format(ip_camera_address)) And ...


1

if you need run USBcam import cv2 cap = cv2.VideoCapture(0) while(True): ret, frame = cap.read() cv2.imshow('frame',frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() if you need run IPcam import cv2 cap = cv2.VideoCapture('rtsp://username:password@192.168.1.64/1') while(True): ret, ...


1

The relay module you linked (which has limited documentation) states:- 12V 16-Channel Relay interface board, and each one needs 15-20mA Driver Current The Pi GPIO can (safely) sink up to 16mA - and if using all relays would overload an Arduino, and probably the Pi. Of cause this is assuming the Pi could even drive the opto-isolator, but if this has a ...


1

To get the available disk space with python you could use psutil import psutil path = '/' bytes_avail = psutil.disk_usage(path).free gigabytes_avail = bytes_avail / 1024 / 1024 / 1024 print(gigabytes_avail) If you look at the source code of the disk_usage function, you'll see they use os.statvfs(). To use statvfs yourself you could do something like this ...


1

For anyone having the same issues: It turns out that the above code uses too little CPU load and therefore does not shoot up the frequency. When I checked, my CPU was constantly running at 700 Hz. To achieve the required FPS on the above resolution, I changed my cpufreq governor from ondemand to performance. This might not be the only or the best solution, ...


1

For Windows pip install python3-rpi.gpio or pip install RPi.GPIO


1

suid won't work with python scripts Make a setuid wrapper. There are lots of examples in Google, basically you make a small C program which runs setuid(0); system("/your/script");, and set the suid bit on that binary.


1

I managed to successfully run neopixel without root using this: https://github.com/joosteto/ws2812-spi. Before I had to: move LED connection to physical pin 19 add my user to spi group enable SPI interface through raspi-config pip3 install spidev # we will need single function from it wget https://raw.githubusercontent.com/joosteto/ws2812-spi/master/...


1

This is due to the fact that you are computing RMS (Root Mean Square). There is nothing you can do against that and it will always be (unless you opt for a different type of circuit). To have the resulting RMS equal to zero means the signal coming from the CT is a perfect straight line. However there is always a tiny current change on the divider that you ...


Only top voted, non community-wiki answers of a minimum length are eligible