Raspberry Pi Snowman (Help)

Got an idea for a project? Found a cool project you want to share? Post it here!
Post Reply
User avatar
Pentium
Posts: 74
Joined: Thu Jul 13, 2017 7:35 pm
Has thanked: 23 times
Been thanked: 8 times

Raspberry Pi Snowman (Help)

Post by Pentium » Tue Dec 19, 2017 3:35 pm

I was thinking of doing a cute lil project as a decoration for Christmas coming up.
I'm planning to put something on the back of a stuffed snowman or something, and make it so that it's holding a small trumpet.
The idea is that you have to press a tactile switch on the trumpet to make it start playing music, but I'm not too sure on how I can get this done.

I'm not going to mess around with coding, as I suck at it, so my plan is to just have a similar setup as the mintypi with the small usb dac. When you press the button, the circuit will be completed and the sound gets played, but when you let go, it stops. The problem is, how am I going to get an audio track to be played over and over again over usb?
Can anyone tell me?

User avatar
YaYa
Posts: 1719
Joined: Mon Jun 26, 2017 12:42 pm
Location: brittany - France
Has thanked: 871 times
Been thanked: 689 times
Contact:

Re: Raspberry Pi Snowman (Help)

Post by YaYa » Wed Dec 20, 2017 12:04 am

Unfortunately, you’ll still need coding for this.
You must create a little script telling the system to play an audio file as soon as the system is loaded and repeat it for ever.
I don’t know which software or binary you can use, i think omxplayer can do the trick as he plays video also.

Have a read here
https://www.raspberrypi.org/documentation/usage/audio/

There should be an option to tell omxplayer to loop once finished playing the file

A quick google
https://gist.github.com/cpmpercussion/6 ... 950e6bcd13
And
https://www.raspberrypi.org/forums/view ... hp?t=10218
Follow me on instagram Image

User avatar
moooarcuuuus
Posts: 232
Joined: Tue Jul 04, 2017 1:28 am
Has thanked: 2 times
Been thanked: 94 times

Re: Raspberry Pi Snowman (Help)

Post by moooarcuuuus » Wed Dec 20, 2017 1:13 am

Let it play in a endless loop and control the volume. Start with mpeg123 as a cronjob and "amixer set Master 0%" is a simple bash tool. Or kill mpeg123 and start new.

Raspi is overkill. If you use a cheap pro-mini arduino there is no boot time.
Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep, Eat, Sleep... Game Over

User avatar
Pentium
Posts: 74
Joined: Thu Jul 13, 2017 7:35 pm
Has thanked: 23 times
Been thanked: 8 times

Re: Raspberry Pi Snowman (Help)

Post by Pentium » Wed Dec 20, 2017 1:55 pm

YaYa wrote:
Wed Dec 20, 2017 12:04 am
Unfortunately, you’ll still need coding for this.
Whenever I see someone say 'type this command line in', I always get confused:
Should I type the code into the config.txt file? ssh it into the pi?
When wermy made his halloween pumpkin video, he said something about a python script, what did he mean?

User avatar
YaYa
Posts: 1719
Joined: Mon Jun 26, 2017 12:42 pm
Location: brittany - France
Has thanked: 871 times
Been thanked: 689 times
Contact:

Re: Raspberry Pi Snowman (Help)

Post by YaYa » Wed Dec 20, 2017 2:02 pm

A command is an order that you give to the Pi via his command line. Either from the console on the device itself which assume a connected keyboard and screen, either via a ssh console.

A python script is a piece of code written in python, a powerful programming language.
The piece of code result in the creation of a file that you make executable. You can then launch it via a command like a program (infact, it is a program) or you can launch it automatically when the system is loading.

To do this you have several methods. You can edit configuration files and add some text to tell the system what to do and when to do.
This text can be a command, or a piece of code :mrgreen:
Follow me on instagram Image

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Raspberry Pi Snowman (Help)

Post by wermy » Wed Dec 20, 2017 2:51 pm

You can do this with an arduino, do a google for playing a wav file - it's not terribly difficult (and I've done it in a few projects). If a raspi is all you have on hand, though, I'd go the python route. That's become my preferred method for detecting and reacting to button/GPIO input and doing a thing based on that. Very easy to run arbitrary commands with that too (so you could load up whatever sound player program you wanted).
ImageImageImageImage

User avatar
Pentium
Posts: 74
Joined: Thu Jul 13, 2017 7:35 pm
Has thanked: 23 times
Been thanked: 8 times

Re: Raspberry Pi Snowman (Help)

Post by Pentium » Thu Dec 21, 2017 9:14 am

YaYa wrote:
Wed Dec 20, 2017 12:04 am
i think omxplayer can do the trick as he plays video also.
I did some research, and I think I can use Omxplayer to do this, but how can you make it so it plays over usb audio (similar to the mintypi)?
If you change the config file, there is an option to use the headphone jack (local) or hdmi (hdmi), so how do I use it over usb? Also, how do I get a speaker playing through the headphone jack instead of having it play over the headphones?
Thanks for the help!

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Raspberry Pi Snowman (Help)

Post by wermy » Thu Dec 21, 2017 9:23 am

Pentium wrote:
Thu Dec 21, 2017 9:14 am
YaYa wrote:
Wed Dec 20, 2017 12:04 am
i think omxplayer can do the trick as he plays video also.
I did some research, and I think I can use Omxplayer to do this, but how can you make it so it plays over usb audio (similar to the mintypi)?
If you change the config file, there is an option to use the headphone jack (local) or hdmi (hdmi), so how do I use it over usb? Also, how do I get a speaker playing through the headphone jack instead of having it play over the headphones?
Thanks for the help!
There is a parameter you can pass to omxplayer to tell it where to output sound. On mintyPi for the splash screen this works:

Code: Select all

omxplayer -o alsa -b --layer 10000 "/home/pi/mintyPi/minty-splash.mp4"
You shouldn't need the layer parameter, though.
ImageImageImageImage

User avatar
Pentium
Posts: 74
Joined: Thu Jul 13, 2017 7:35 pm
Has thanked: 23 times
Been thanked: 8 times

Re: Raspberry Pi Snowman (Help)

Post by Pentium » Thu Dec 21, 2017 1:18 pm

wermy wrote:
Thu Dec 21, 2017 9:23 am

There is a parameter you can pass to omxplayer to tell it where to output sound. On mintyPi for the splash screen this works:

Code: Select all

omxplayer -o alsa -b --layer 10000 "/home/pi/mintyPi/minty-splash.mp4"
You shouldn't need the layer parameter, though.
So if I use this string of code, the audio will output on the USB sound card?

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Raspberry Pi Snowman (Help)

Post by wermy » Thu Dec 21, 2017 1:51 pm

Pentium wrote:
Thu Dec 21, 2017 1:18 pm
So if I use this string of code, the audio will output on the USB sound card?
Assuming the sound card is set up correctly, yes. As I said that's what I used in the mintyPi for the splash screen, and it uses a usb sound card.
ImageImageImageImage

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest