{"id":890,"date":"2014-10-31T14:08:14","date_gmt":"2014-10-31T14:08:14","guid":{"rendered":"http:\/\/naich.net\/wordpress\/?p=890"},"modified":"2015-03-06T10:48:42","modified_gmt":"2015-03-06T10:48:42","slug":"pi-rate-radio-jukebox","status":"publish","type":"post","link":"https:\/\/naich.net\/wordpress\/index.php\/pi-rate-radio-jukebox\/","title":{"rendered":"Pi-rate Radio Jukebox"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-891\" src=\"http:\/\/naich.net\/wordpress\/wp-content\/uploads\/2014\/10\/p1070168.jpg\" alt=\"p1070168\" width=\"290\" height=\"217\" srcset=\"https:\/\/naich.net\/wordpress\/wp-content\/uploads\/2014\/10\/p1070168.jpg 800w, https:\/\/naich.net\/wordpress\/wp-content\/uploads\/2014\/10\/p1070168-300x225.jpg 300w\" sizes=\"auto, (max-width: 290px) 100vw, 290px\" \/>Note: <a title=\"Pirpl \u00e2\u20ac\u201c it\u00e2\u20ac\u2122s another Pirate Radio PLaylist thing!\" href=\"http:\/\/naich.net\/wordpress\/?p=927\">there is an update to this post<\/a>.<\/p>\n<p>There is a nice hack for a Raspberry Pi where you can turn it into an <a href=\"http:\/\/www.icrobotics.co.uk\/wiki\/index.php\/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter\">FM transmitter<\/a>. \u00c2\u00a0While this is\u00c2\u00a0illegal in most countries, the range is quite limited so it&#8217;s fairly\u00c2\u00a0unlikely you&#8217;ll go to prison. The only hardware needed is your Raspberry Pi and a piece of wire attached to pin 7 (GPIO 4) of the <a href=\"http:\/\/elinux.org\/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29\">GPIO connector<\/a>. \u00c2\u00a0The length of the wire depends on the frequency you are transmitting on &#8211; roughly speaking, it should be 299\/(frequency x 4) metres long. \u00c2\u00a0So 103 MHz is 725 mm. \u00c2\u00a0Or if you are using inches, 299\/(frequency x 0.1016) inches.<\/p>\n<p>It&#8217;s very easy\u00c2\u00a0to <a href=\"http:\/\/www.maketecheasier.com\/run-radio-station-with-raspberry-pi\/\">transmit\u00c2\u00a0internet radio<\/a>\u00c2\u00a0using just one line of Bash but if, like me, you have a few thousand MP3s , there&#8217;s no quick and dirty way to pump them out to the transmitter.<\/p>\n<p>Until now. \u00c2\u00a0Behold the <a title=\"Download link\" href=\"http:\/\/naich.net\/pirjb.tgz\">PIrate Radio Juke Box (pirjb)<\/a>.\u00c2\u00a0If you can think of a better name for it, please leave a comment. \u00c2\u00a0A couple of Bash scripts, a minor alteration to the pifm code and a reckless disregard for radio licensing regulations is all that is needed to listen to your collection on any FM radio. \u00c2\u00a0 You can repeat and shuffle with either a playlist of MP3s in a file or point it to the directory the MP3s live in and it&#8217;ll scan them and make its own playlist.<\/p>\n<p>Also included is a web server to show you the currently playing track. \u00c2\u00a0Using your browser, you can skip to the next track or shut everything down and turn the transmitter off. \u00c2\u00a0Note that you can&#8217;t turn it back on with the web interface yet. \u00c2\u00a0That&#8217;s the next thing on the to do list. \u00c2\u00a0You can get to the page by going to http:\/\/your_pi_address:8080\/ \u00c2\u00a0The &#8220;8080&#8221; is set in the pirjb.sh file, at the top.<\/p>\n<p><em>Note that I do\u00c2\u00a0not condone\u00c2\u00a0or encourage the use of transmitting equipment without the proper license. \u00c2\u00a0This article is presented purely as an exercise in theoretical programming. \u00c2\u00a0Your statutory rights are not affected. \u00c2\u00a0Your home may be at risk if you set fire to the curtains.<\/em><\/p>\n<h4>Setting up<\/h4>\n<p>You need to have the following packages installed: sox, netcat, mp3info. \u00c2\u00a0Use<\/p>\n<pre>sudo apt-get install sox netcat mp3info<\/pre>\n<p>to install them.<\/p>\n<p>Copy <a title=\"Another link to the files in case you missed the first one\" href=\"http:\/\/naich.net\/pirjb.tgz\">the pirjb archive<\/a>\u00c2\u00a0to an empty directory on your Pi and extract the files with<\/p>\n<pre>tar zxf pirjb.tgz<\/pre>\n<p>You need to edit <strong>pirjb.sh<\/strong>. \u00c2\u00a0The top few lines are where things like the transmission frequency, path to the scripts\u00c2\u00a0and the port for the web server are defined. \u00c2\u00a0There is also a line for the compander settings for sox in order to have an AGC. \u00c2\u00a0If you didn&#8217;t understand that last sentence, don&#8217;t change that line. \u00c2\u00a0I&#8217;ve also included the source for the pifm binary included in the archive. \u00c2\u00a0There is a very minor change to it from <a href=\"http:\/\/www.icrobotics.co.uk\/wiki\/index.php\/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter\">this one<\/a> &#8211; calling it with no parameters turns off the transmitter. \u00c2\u00a0Please do compile it and use it instead of the binary I&#8217;ve put in the archive. \u00c2\u00a0You shouldn&#8217;t really be running binaries from random geezers on the interwebs anyway. \u00c2\u00a0And I am sometimes quite random.<\/p>\n<p>You need to make pifm run as root using setuid in order for the transmitter to work. \u00c2\u00a0Do this with:<\/p>\n<pre>sudo chown root:root pifm\r\nsudo chmod 4755 pifm<\/pre>\n<p>To run it use:<\/p>\n<p>pirjb.sh -d &lt;directory name&gt; \u00c2\u00a0or<br \/>\npirjb.sh -p &lt;playlist&gt;<\/p>\n<p>Switches are -s to shuffle the track order, -r to repeat the playlist indefinitely. \u00c2\u00a0The playlist file should have the full path of each\u00c2\u00a0mp3 you want to play\u00c2\u00a0per\u00c2\u00a0line, i.e.<\/p>\n<p>\/home\/naich\/music\/Wombles Christmas Special\/01 Wombling Christmas.mp3<br \/>\n\/home\/naich\/music\/Napalm Death\/Scum\/Human Garbage.mp3<br \/>\n&#8230; and so on.<\/p>\n<p>Have fun playing with it and do not use it because\u00c2\u00a0it is illegal to do so.<\/p>\n<h4>Files included in the archive:<\/h4>\n<ul>\n<li>pifm : The transmitter binary<\/li>\n<li><a title=\"The main script\" href=\"http:\/\/naich.net\/pirjb.sh\" target=\"_blank\">pirjb.sh<\/a> : The jukebox script. \u00c2\u00a0Edit the first few lines for your system.<\/li>\n<li><a title=\"Cheap and nasty web server script\" href=\"http:\/\/naich.net\/pirjb_webserver.sh\" target=\"_blank\">pirjb_webserver.sh<\/a> : The webserver script. \u00c2\u00a0No need to edit it.<\/li>\n<li><a href=\"http:\/\/naich.net\/pirjb_template.html\" target=\"_blank\">pirjb_template.html<\/a> : The template for the web server page. \u00c2\u00a0See\u00c2\u00a0pirjb_webserver.sh for information about using it. \u00c2\u00a0Or just look at the file itself and have a guess. \u00c2\u00a0It&#8217;s not hard to see what&#8217;s going on.<\/li>\n<li><a href=\"http:\/\/naich.net\/source\/pifm.c\" target=\"_blank\">source\/pifm.c<\/a> : The source for pifm. \u00c2\u00a0Compile with\u00c2\u00a0g++ -O3 -o pifm pifm.c then copy over the top of pifm. \u00c2\u00a0Don&#8217;t forget to chown and chmod the compiled program.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Note: there is an update to this post. There is a nice hack for a Raspberry Pi where you can turn it into an FM transmitter. \u00c2\u00a0While this is\u00c2\u00a0illegal in most countries, the range is quite limited so it&#8217;s fairly\u00c2\u00a0unlikely you&#8217;ll go to prison. The only hardware needed is your Raspberry Pi and a piece [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74,102],"tags":[107,106,105,110],"class_list":["post-890","post","type-post","status-publish","format-standard","hentry","category-geek","category-raspberry-pi","tag-jukebox","tag-music","tag-radio","tag-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=890"}],"version-history":[{"count":20,"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/890\/revisions"}],"predecessor-version":[{"id":948,"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/890\/revisions\/948"}],"wp:attachment":[{"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/naich.net\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}