An easy way to find the package providing a given file is apt-file; you can also do much the same thing online from here. First you need to install apt-file:
> sudo apt install apt-file
> apt-file search "sdl-config"
What do you mean by "hang"? I had problems with my headless pi that every 2-3 days I could not connect to it. It was working ok but I could not ping nor ssh to it.
Turned out to be a problem with the power management in the wifi dongle:
Once I turned of the power management features as ...
Here's a writeup for the hack we came up with in the comment stream:
Most fortunately, we're able to take advantage of the limited scope of this request:
I don't care that sound doesn't work on pygame. The application works perfectly just this annoying 6 line error message shows. I just want to get rid of the messages
We don't know why exactly ALSA is ...
some of the errors here, and I hope someone can help explain why these errors occur
That's literally just the tip of an iceberg. By "literally", I mean system log messages are classified into 8 levels of priority (see man logger or man 3 syslog), and, depending on configuration (see /etc/rsyslog.conf; it might also just be syslog.conf), the highest one or ...
The problem wasn't anything to do with Python, but rather that my pi user settings were different from my root user settings, so that the former went through the chosen USB audio device, but I couldn't get the latter to change from default settings. I only noticed this via Python because I would run my python script using sudo.
The non-accepted answer from ...
As pygame rely on SDL system, we have to define the audio driver for SDL. This can be done with environnement variables.
You can define it in your python script, but this must be done before you init pygame.
You may also define the env.var. SDL_AUDIODEV in the same manner, if you ...
I finally made this work.
Check your alsa.conf and .asoundrc file, only one of them needs to be configured with your audio setup.
I setup my audio in both files which caused the confusion, once I restored alsa.conf to default, the problem is gone.
Graphics output on the Pi is usually displayed via the X Window System (aka X11, or simply X). You can confirm this by plugging a compatible TV/monitor into the Pi's HDMI-out. If you want to view from your laptop some kind of VNC software is the easiest route. (RealVNC is installed on recent Pi images by default.)
Your error (and the documentation) says it all: pygame.mixer has no attribute my_Sound.
It does, however, have an attribute named Sound, which you have in your posted code. However, you error line shows you using my_Sound instead of Sound.
Moreover, your pygame.init should be a function call, that means it needs (). So it should be:
All in ...
Turns out an audio jack has to be connected when the python script is running in order for the USB sound card to be working. Strange, but works for what I'm trying to do. When configured to use the internal 3.5 mm minijack port this is not needed.
To answer my own Question at least to a small extend:
VLC seems to offer a something similar to pygame but with the advantage that (to my knowledge) no screen is needed and it plays pretty much every data Format.
Here a quick link: https://linuxconfig.org/how-to-play-audio-with-vlc-in-python
As for the code, Iam still greatful for every advice, especially ...
This is what @archdata found for his solution and added it to his question. I have moved it from there into this answer to respect the sites policy for answering. @archdata wrote:
This is now working. I have updated the code above to match what works for my project. The trick to running it is found here How do I let an SDL app (not running as root) use the ...
The PyGame library treats keypad keys different from normal keys. For instance, the normal enter key is defined as pygame.K_RETURN while the keypad enter key is pygame.K_KP_ENTER, so you should replace K_RETURN with K_KP_ENTER in your code. You can find a full list of the key codes here.
When you run your script "manually", you are running the script as the username under which you're logged in. When you "auto-start" the script with cron you are invoking the script as a different user.
Best guess: It seems to me that your problem may be that your "manual" user has access permission to the fonts, but your "cron" user does not. Alternatively,...
This worked for me.
sudo apt-get install python-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev
Taken from https://stackoverflow.com/questions/7652385/where-can-i-find-and-install-the-dependencies-for-pygame
Pygame is not a framework where button, frame and windows are already defined. It is a more low level access to the framebuffer.
To use pygame with the framebuffer you should write something into it. Basically, your program only declares the screen (which is initially black) and... do nothing else.
You should use blit to write/place texts and images to the ...
Well... even if your script has no mention of any sound stuff, pygame could very well include sound-related stuff inside and that's why you are seeing those messages. If you want to avoid those messages from showing up on the terminal, you can just redirect output so that you don't get it at all: python my-script.py &> /dev/null and voila! No output on ...
I found this thread.
I tested the solution between two of my personal computers, both running Linux.
To find out the value of $DISPLAY, use a keyboard hooked directly to the pi. Then in the terminal type echo $DISPLAY
The value will probably be :0.0
Then once you ssh into the pi, type
(but replace the :0.0 with whatever value the echo $...
I must confess that I know nothing about image processing from the Pi camera and I've only played around a little bit with Python. Yet some things look suspicious about your code.
You seem to be creating a socket connection, sending one image (still frame) down the pipe, closing the socket, then repeat. You don't want to be doing it this way. Too much ...
Pygame can be used to play music.
See Making Games With Pygame (.pdf)
For a simple example:
# instantiate pygame
# select track
pygame.mixer.music.load("./directory/01 Track name.mp3")
# play music (on loop)
# stop music
This is technically not an answer, but more of a work around. I have completely given up on SimpleCV. I don't know if there is an error in SimpleCV, pygame, or if it is just all over my head. I have found that if I use pygame to take the picture and reinitialize it every minute, I never get a segmentation fault.
import numpy as np
Ok, I'm not sure if this is the proper way to fix this, but I found that the script ended before the audio has a chance to play. So to fix that I added:
to the script and it works fine now. So the full script looks like so:
sound = pygame.mixer.Sound(os....
Thank you @goldilocks for your comments on this, to clarify what I was doing: the pi was booting to the cli and here there was a script in init.d to run the python/pygame script. I wasn't using the X server at all.
From your comments I've looked into using X server without the windows manager (which I had no idea about), using these sources:
This Xclients ...
I had a similar problem with pygame. However, I found that my issue was completely unrelated. This may be the case for you as well.
The problem is likely not a product of an issue with the pygame.midi, so much as it lies with the fact that your raspberry pi may be configured to forward its audio output to the HDMI cable connection.
I found that a fix can ...
You will probably want to have a "calibration" procedure that directs the user to manipulate all the joystick controls that are not simple "up"-"down" buttons. You will need to ask the user to take each control to the extremes that each one has and have the code notice what values are detected at those extremes - on some systems (old PC analogue joysticks ...
Have a look at the following.
def stopgo_func(gpio, level, tick):
global state_color1, state_color2
if level == 0:
state_color1 = green
elif level == 1:
state_color2 = red
pi = pigpio.pi() # Connect to Pi.
cb = pi.callback(...