Feeds

back to article P-P-P-Pick up our PENGUIN-POWERED Pi PIPER of Python

Turning the Raspberry Pi into a music player is old hat, but turning it into a personalised DJ is slightly more difficult if a lot more interesting. The Raspberry Pi, an ARM-powered £20 computer sold as the educationalists' dream, is finding its place as a media player in many tech-aware homes, but installing media player XBMC …

COMMENTS

This topic is closed for new posts.
Anonymous Coward

there's an awful lot of Carter the Unstoppable Sex Machine in that datastore there.

0
0
(Written by Reg staff)

That datastore shouldn't have been there, it got sucked up into the ZIP file and was only a handful of albums I was using for testing.

Not that I'm apologising for Carter, I'm just relieved that the rest of my collection wasn't shared.

Bill.

1
0
Thumb Up

Carter...

There is nothing wrong with Carter USM. Were you at the Brixton Academy earlier on this month for their 'final' live gig? I had a blast there :)

I might see if I can load python onto my NAS and use it to run my music stored on there.

0
0
(Written by Reg staff)

Re: Carter...

The system is happily playing back from a NAS right now, in fact I keep the application there too so I can modify it without having to touch the 'Pi.

The server is mounted by a script executed during boot (sudo update-rc.d myScript defaults), which goes on to run the app itself.

Didn't make it to the gig, much as I'd have loved to.

Bill.

1
0
Silver badge
Thumb Up

Welcome on board!

Thanks for sharing the code - you might want to put it up on Bitbucket, Github so that we can, er, "fix it", for you.

Code is good for a start - it gets something done - but you'll have to get out of the habit of using "global" variables as that is very much frowned upon. Add in support for dispatching, string-templating and you're almost done. Well, there is more but then there always is!

1
0
Anonymous Coward

Re: Welcome on board!

Yes, never use global variables, even when you need them. Find some modern pattern like "singleton" that gives you all the pros and cons of global variables but without the cocktail-party-stopping embarrassment of daring to use a language facility that the ivory tower guys think is "harmful".

You should certainly never use globals just for convenience in a smallish application. Write applications as if they are libraries. Extra work up front *always* pays off in the end.

</sarcasm>

6
2
Silver badge
Stop

Re: Welcome on board!

If Bill didn't want any code review he wouldn't have posted his code.

See post lower down for why global variables are generally not required. The keyword is there so you can use it when you need to but it really is something that you very, very rarely need in Python and has extensive side-effects that you generally don't want. Pointing that out has nothing to do with ivory towers.

FWIW I don't think singletons would be needed here - something for which there isn't a keyword because you don't need them. Moving the functions into the controller class would provide mutable instance variables safely isolated from immutable module constants.

2
0
Silver badge
Thumb Up

Top Notch

Would love to see more "I combined my Raspberry Pi and some keyboard hacking to do THIS" type stories on el reg.

8
0

Re: Top Notch

Takes me back to the days of typing listings out of Sinclair User into my Spectrum.

1
0
Thumb Up

Re: Top Notch

I concur. This takes me back.

In my day we used to DREAM of having a megabyte to play with.

Then our dad would come home and thrash us to sleep with his belt.

3
0
Anonymous Coward

Re: Top Notch

My vote: Raspberry Pi hacking should become part of the Special Projects Bureau's scope.

My current favorite Pi idea (I know some people were looking into it but haven't heard if there has been any success yet) if using one as a web and/or mobile app IR blaster to control all the random kit in your entertainment center. AFAICT, it can do this with just the board... the only challenge seems to be software. Given the meager requirements of that function, it seems like it could coexist with the 'DJ' role described here if not the OpenElec XBMC distro.

Future projects: Logic and control board for GAGA?

2
0
Thumb Up

Speaking of media centers

You could easily add infra red remote control support (and a disco light) to that little pi with my HotPi board, currently on KickStarter :D

http://www.kickstarter.com/projects/582604098/hotpi

1
0

Looks neat, but a couple of things...

- You only need a "global" declaration when you intend to assign to a global variable (and that variable is not mutable, like a list, dictionary, or some custom object).

- Using "urlparse" to decode the URL may be a good idea (especially for "setTrack.cmd" and __substitute).

- If you're not going to use a template language, at least use a library like lxml to generate correct, well-formed XHTML (your expression will also be much clearer using lxml's builder syntax).

You could also probably simplify it a little by using cherrypy (or similar) to handle the HTTP server, and separate your jukebox logic into another class (and get rid of all those globals in the process).

Good luck!

0
0
Bronze badge
Linux

Full Circle Magazine

Somewhere on this site is the omnibus edition of all the "Program in Python" tutorials. I can't find it but here is the link to the first one. Free PDFs

http://fullcirclemagazine.org/issue-27/

0
0
Go

Re: Full Circle Magazine

They're here, split into 4 parts

http://fullcirclemagazine.org/tag/special/

1
0
Thumb Up

Re: Full Circle Magazine

Oh they are superb, thank you.

0
0

Sound quality?

What is the quality of the sound output from the Pi?

0
0

Re: Sound quality?

AIUI the analogue audio output from the Pi (ab)uses the PWM capability in the ARM chip, and only provides the equivalent of a 13-bit D/A converter. Probably best to save the oxygen-free directional-crystal Audiophool cables for another project.

2
0

Re: Sound quality?

I prefer to listen to music through my audio equipment, not listen to my audio equipment through music, but this sounds (haha) a bit lo-fi even for me.

2
0
Anonymous Coward

Re: Sound quality?

If you had the proper receiver... could you output digital via HDMI?

0
0
Bronze badge

Re: Sound quality?

I ordered a couple of Pi's for my brothers' xmas presents. I got to talking about it with one of them and it turns out he already had Pi and was trying to get it to work as a jukebox. He'd run into the same problem with poor quality audio output over the 3.5mm jack. HDMI audio output is perfect, but it would mean buying another cable and converter or of having an amp that accepts HDMI input. I did a bit of research and it turns out that this is a known problem with the headphone jack. There have been some things done on the software/driver side to improve the quality a little bit (basically eliminate nasty crackles and pops when audio output starts/stops). I didn't read any more about it, but it seems that overclocking might be one way to improve the situation (the CPU has to do a lot of the work that a dedicated sound chip should do). I was also curious as to whether buying the MPEG-2 codec license would improve the situation (isn't MP3 a sub-standard within MPEG-2?)

I guess I should really be looking for those answers over on the Pi forums, but I thought I'd just throw out those ideas here in the hopes that maybe someone knows whether they work or not.

Also, thumbs up for the article. I like reading about the Pi here.

1
0

Re: Sound quality?

He could always buy an external USB soundcard which won't be as big or as expensive as a HDMI capable amp. I don't find the sound quality that bad, but then I'm using an x-mini speaker....

1
0
Anonymous Coward

Re: Sound quality?

Use HDMI and decode it using something helf-decent.

0
0

Infringement

Apple will be combing through it to sue you guys for Patent violations on music players!

http://www.theregister.co.uk/Design/graphics/icons/comment/trollface_32.png

0
1

path separators

"the code had to be altered to change the path separator"

The Python 'os' and 'os.path' module have abstractions for things like the path separator, which means that you shouldn't need to change anything once you've coded it up to use the right variables - although generally you shouldn't need to get even that low-level as there are a wealth of helper functions to split, join and otherwise manipulate path names. It's a very useful module to get to know even, or perhaps especially, when you're starting out.

HTH

0
0
Boffin

Re: path separators

Also, Windows is quite happy to use forward-slash as the directory separator - applications such as Windows Explorer or the Command Prompt don't like it, but the underlying OS is fine with it.

0
0
Thumb Up

Pi–oneers

My first Pi arrived at the weekend, so I'm looking forward to joining this happy band of tinkerers —just as soon as I think of a suitably fun project to start on.

However:

"...The Raspberry Pi, an ARM-powered £20 computer..."

...I'm sure we'd all love to hear where you can p-p-p-ick up a Pi for twenty quid. It's currently £25,95 + £4,95 P&P [total: £30,87] from RS and £27,21 + £5,95 P&p [total £33,61] from Farnell.

0
0

Re: Pi–oneers

"I'm sure we'd all love to hear where you can p-p-p-ick up a Pi for twenty quid."

The Model A is $25 (compared to $35 for the B) plus local taxes... and ex VAT the new Model B is only £ 21.60 from RS and about a pound more from Farnell, so it's not that far out to be fair (but perhaps a teeny bit misleading).

0
0
Unhappy

Re: Pi–oneers

Ah, but therein lies the rub.

Unless you're a business, you have to stump up the VAT and aren't able to claim it back. And, given that the target market for the Pi is the amateur tinkerer not commercial enterprise, the VAT-inclusive price is the price most people will end up paying. Also, as far as I am aware, both RS Components and Farnell are mail order only retailers. Therefore the P&P costs are also unavoidable*. So, whilst in theory the Pi might cost just over £20, in practice most people will not be able to secure one for under £30.

[*P&P charges are a complete rip-off. Posted out in a jiffy bag, standard post. It must cost the suppliers under a quid to send them out, yet both charge around a fiver P&P]

0
0

Re: Pi–oneers

"Ah, but therein lies the rub.

Unless you're a business, you have to stump up the VAT and aren't able to claim it back"

Partly true - one of the bigger markets the Pi is aimed at is the educational one, much of which would be able to claim back the VAT (as I understand it anyway, but i'm not in that sector - section 33B of the VAT Act 1994 seems to have the legal basis for this, and there are other allowances).

"Also, as far as I am aware, both RS Components and Farnell are mail order only retailers."

RS, certainly, used to run a counter service but i've not used that for years...and it would mean them adding a 'Collect from trade counter' option for them on the website when checking out - looks like that's not the way they've got the ordering set up for the Pi however. Might be worth asking them.

"[*P&P charges are a complete rip-off. Posted out in a jiffy bag, standard post. It must cost the suppliers under a quid to send them out, yet both charge around a fiver P&P]"

Totally agree.

0
0
JB
Happy

Very interesting article, even if i struggled to understand most of it.

I love my Pi and have been enjoying learning new stuff like using ssh, and reacquainting myself with the command line and programming, but get very frustrated at my lack of ability in learning Python. I was a keen hobbyist programmer back in the 80s and 90s, using BASIC, Pascal and some C++, and looking back at some of the surviving scripts I'm amazed at some of the stuff I did. I'm finding that python tutorials are either "print "Hello World!" at the interpreter prompt", or a full-blown in-depth essay where it's assumed you know what stuff like libraries and classes are. I wish there was something for us ex-hobbyist programmers to get us up to date...or they put GOTO into Python! :)

Please keep the articles coming...immersion is one way to learn!

0
0
Silver badge

I found "Learning Python" an excellent primer. Python is probably closer to Pascal than Basic so forget GOTO just give your subroutines names and call them functions and you'll be away.

1
1
Bronze badge
Thumb Up

http://code.google.com/edu/languages/google-python-class/

This, with the accompanying videos was how I learnt Python, and now I use it every day for my job. OK so it doesn't give you everything you'll ever need to know, but it definitely goes a long way beyond "hello world!"

0
0
This topic is closed for new posts.