tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 2:14 pm

Issue 46 Page 32 Internet Radio, schematic I believe should show MCP3008 pins VDD and V_REF connected together. Without this mod the output from CH0 does not vary. Also the maximum output appears to be around 0.48, so I have changed the test on line 16 of the program to >= 0.4, and on line 19 to <0.4.

Unfortunately the Radio OP does not start until the program is closed, does anyone have any idea why this is so?

I hope this is the correct place to ask a question on MagPi progect, or is there an alternative?

Tadder

User avatar
DougieLawson
Posts: 34561
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 2:55 pm

That schematic is completely wrong. Vdd isn't connected to 5V0 or 3V3 on the RPi, so that MCP3008 isn't powered up.

The breadboard diagram (page before) is correct as both Vdd and Vref are connected to 3V3 on the RPi.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 3:07 pm

Thanks for the response, I should have mentioned that I had noticed this omission and the MCP 3008 is in fact powered, with an output max of 0.48. I did however have to connect VREF to VDD to get any output.

I still can’t see why I get an audio output only after closing the program.

Tadder

User avatar
DougieLawson
Posts: 34561
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 3:23 pm

Try downloading the code from http://magpi.cc/1OG2Y9i
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

B.Goode
Posts: 6695
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 3:32 pm

This seems to largely duplicate a thread here: viewtopic.php?f=106&t=109621&p=992705&h ... ta#p992705

That seems to be the appropriate place for it.

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 5:08 pm

DougieLawson wrote:Try downloading the code from http://magpi.cc/1OG2Y9i
Thank you for your continuing help. I have downloaded as suggsted, but no change, no sound until I kill the program, at which point stream from selected channed is played.

Just a thought, I am running this on a PI 3, the original was on a PI 2, could there be a connection?

Tadder

User avatar
DougieLawson
Posts: 34561
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 5:30 pm

Nope. Those Magpi programs should run on any RPi with Raspbian Jessie & python3.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 7:30 pm

Thanks, actually after looking at the code maybe the logic is flawed?

The main program continually polls the value from the pot, but this means that every time the while True loop is entered the program carries out the "killall mplayer" process followed by "mplayer -playlist " + station + 2 " &" regardless of if any change has been detected in the pot.

So maybe the process can't begin to start until the program is killed ?

Tadder

User avatar
DougieLawson
Posts: 34561
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 7:46 pm

Urgh!

Code: Select all

from gpiozero import MCP3008
import time
import os

station_dial = MCP3008(0)

Magic = "http://tx.whatson.com/icecast.php?i=magic1054.mp3.m3u"
Radio1 = "http://www.listenlive.eu/bbcradio1.m3u"

def change_station(station):
    os.system("killall mplayer")
    os.system("mplayer -playlist " + station + " &")

station = "http://localhost" # dummy value 
while True:
    if station_dial.value >= 0.5 and station != Magic:
        station = Magic
        change_station(station)
    elif station_dial.value < 0.5 and station != Radio1:
        station = Radio1
        change_station(station)
    time.sleep(0.1)
My changes should fix it, if the station is already set we won't attempt to change it.

That code is untested because I don't have a MCP3008 and a pot handy.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Help Wanted Issue 46 Page 32 Internet Radio

Sat Jun 25, 2016 8:45 pm

Thanks a lot for your assistance, really appreciated.
Unfortunately I won't be able to try it out until Monday evening, but I will let you know how it goes.
Thanks again
Tadder

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Help Wanted Issue 46 Page 32 Internet Radio

Mon Jun 27, 2016 7:05 pm

Your code worked perfectly, thank you.

As a newcomer you tend to assume that anything technical printed in a glossy magazine will have been checked before publication and therefore if it doesn’t work it must be your own fault. If nothing else this experience teaches me to approach all articles with some healthy scepticism.

Thanks again

Tadder

User avatar
DougieLawson
Posts: 34561
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Help Wanted Issue 46 Page 32 Internet Radio

Mon Jun 27, 2016 7:21 pm

When I used to help sub-editing the MagPi magazine (that ended in Feb 2015 with the re-launch) we did go through every article and test the code. There were a few articles where the code got completely re-written by the sub-editors because it either didn't work or was just plain ugly (cut'n'paste code) or wouldn't fit the space allocated for the article.

That piece seems to have gone missing.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

robthez
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 72
Joined: Thu Oct 11, 2012 10:50 am
Location: Bournemouth

Re: Help Wanted Issue 46 Page 32 Internet Radio

Wed Jun 29, 2016 3:22 pm

Ah thanks for catching that, looks like the schematic got changed a bit right at the end of making the feature and we didn't notice it. Code is completely my fault. I've updated the GitHub and we'll be starting an errata section in issue 48

Return to “The MagPi”