Advertisement
BaSs_HaXoR

Pirate Radio RaspberryPi Rogue Station Fz BROADCASTER

Nov 24th, 2018
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.61 KB | None | 0 0
  1. #####################################################################
  2. ## Raspberry Pi - PIRATE RADIO STATION BROADCASTING #
  3. ## https://makezine.com/projects/raspberry-pirate-radio/ #
  4. ## https://www.youtube.com/watch?v=CBb8BN0dqoQ #
  5. #####################################################################
  6. This simple hack turns your Raspberry Pi into a powerful FM transmitter! It has enough range to cover your home, DIY drive-in movie, silent disco, a high school ball game, or even a bike parade (depending on the stragglers).
  7.  
  8. PiFM software not only boldly enhances the capability of your Pi, but does so with nothing more than a single length of wire. This hack starts with the absolute minimum you need to run a Raspberry Pi — an SD card, a power source, and the board itself — and adds one piece of wire. It’s the coolest Pi device we’ve ever seen with so few materials.
  9.  
  10. PiFM was originally created by Oliver Mattos and Oskar Weigl, and revised by Ryan Grassel. We’d like to thank the whole PiFM community for inspiration. MAKE’s contribution to the project, the PirateRadio.py script, now enables playback without using the command line, and handles all the most common music file formats automatically. It was written by MAKE Labs engineering intern Wynter Woods. You can find the source code here.
  11.  
  12. ###############################################################################################################################################################################################################
  13. Technically, all you need for an antenna is a piece of wire. For an optimal antenna, you could attach a 75cm wire to pin 4, with a 75cm power cable pointed in the other direction. (That would effectively make a half-wave dipole antenna at 100MHz, near the middle of the FM band.) We just used 40cm of 12 AWG solid wire, since things started tipping over when the wire got longer.
  14.  
  15. Cut and strip a female jumper wire. Solder it to one end of your antenna, and insulate with heat-shrink tubing.
  16. Dab hot glue around the joint for support, and stick it on pin 4 of the GPIO pins of your Raspberry Pi. The glue makes the antenna more rigid so it stands up better.
  17. NOTE: If you have the Raspberry Pi Starter Kit and you're in a hurry, you can just use a male jumper wire plugged into the Cobbler breakout board! (Both are included in the kit.) It will work, but the range will be roughly half of what you'd get with 40cm of 12 AWG solid copper.
  18.  
  19. NOTE: The Raspberry Pi’s broadcast frequency can range between 1Mhz and 250Mhz, which may interfere with government bands. We advise that you limit your transmissions to the standard FM band of 87.5MHz–107.9MHz (see Step 3) and always choose a frequency that’s not already in use, to avoid interference with licensed broadcasters.
  20. ###############################################################################################################################################################################################################
  21. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  22. ################################### www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter ###################################
  23. ################################### https://github.com/Make-Magazine/PirateRadio ###################################
  24. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  25. ###############################################################################################################################################################################################################
  26. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  27. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  28. Steps to play sound:
  29. (Created by Oliver Mattos and Oskar Weigl. Code is GPL)
  30. sudo python
  31. >>> import PiFm
  32. >>> PiFm.play_sound("sound.wav")
  33.  
  34. Now connect a 70cm (optimally, ~20cm will do) or so plain wire to GPIO 4 (which is pin 7 on header P1) to act as an antenna, and tune an FM radio to 103.3Mhz.
  35. http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29
  36.  
  37. Download the module here: http://omattos.com/pifm.tar.gz
  38. (this contains both source and a ready to go binary. Just run the above code in the same folder. The antenna is optional, but range is reduced from ~100 meters to ~10cm without the antenna. The sound file must be 16 bit mono wav format. )
  39. New! Now with stereo
  40.  
  41. sudo ./pifm left_right.wav 103.3 22050 stereo
  42. # Example command lines
  43.  
  44. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  45. # play an MP3
  46. ffmpeg -i input.mp3 -f s16le -ar 22.05k -ac 1 - | sudo ./pifm -
  47.  
  48. # Broadcast from a usb microphone (see arecord manual page for config)
  49. arecord -d0 -c2 -f S16_LE -r 22050 -twav -D copy | sudo ./pifm -
  50.  
  51. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  52. How to change the broadcast frequency
  53.  
  54. Run the ./pifm binary with no command line arguments to find usage.
  55.  
  56. The second command line argument is the frequency to transmit on, as a number in Mhz. Eg. This will transmit on 100.0
  57.  
  58. sudo ./pifm sound.wav 100.0
  59.  
  60. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  61. It will work from about 1Mhz up to 250Mhz, although the useful FM band is 88 Mhz to 108 Mhz in most countries.
  62.  
  63. Most radio receivers want a signal to be an odd multiple of 0.1 MHz to work properly.
  64. The details of how it works
  65.  
  66. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  67. ttp://blog.codeclub.org.uk/blog/brief/
  68. Below is some code that was hacked together over a few hours at the Code Club pihack. It uses the hardware on the raspberry pi that is actually meant to generate spread-spectrum clock signals on the GPIO pins to output FM Radio energy. This means that all you need to do to turn the Raspberry-Pi into a (ridiculously powerful) FM Transmitter is to plug in a wire as the antenna (as little as 20cm will do) into GPIO pin 4 and run the code posted below. It transmits on 100.0 MHz.
  69.  
  70. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  71. started to break up after we went through several conference rooms with heavy walls, at least 50m away, and crouched behind a heavy metal cabinet. The sound quality is ok, but not amazing, as it currently plays some clicks when the CPU gets switched away to do anything else than play the music. The plan was to make a kernel mode driver that would be able to use the DMA controller to offload the CPU and play smooth music without loading the CPU, but we ran out of time. Now Done and working, DMA from userspace is awesome and awful at the same time!
  72.  
  73. If you're v. smart, you might be able to get stereo going! Done!
  74. Accessing Hardware
  75.  
  76.  
  77. ###################################-----------------------------------------------------------------------------------------------------------------------------------------###################################
  78. The python library calls a C program (provided both precompiled and in source form). The C program maps the Peripheral Bus (0x20000000) in physical memory into virtual address space using /dev/mem and mmap. To do this it needs root access, hence the sudo. Next it sets the clock generator module to enabled and sets it to output on GPIO4 (no other accessible pins can be used). It also sets the frequency to 100.0Mhz (provided from PLLD@500Mhz, divided by 5), which provides a carrier. At this point, radios will stop making a "fuzz" noise, and become silent.
  79.  
  80. Modulation is done by adjusting the frequency using the fractional divider between 100.025Mhz and 99.975Mhz, which makes the audio signal. The fractional divider doesn't have enough resolution to produce more than ~6 bit audio, but since the PI is very fast, we can do oversampling to provide about 9.5 bit audio by using 128 subsamples per real audio sample. We were being naieve with our subsampling algorithm - you can now get full 16 bit quality sound, and it even does FM pre-emphasis so that the result doesn't sound bass-heavy.
  81.  
  82. https://www.wired.com/2015/11/create-your-own-pirate-radio/
  83. ###############################################################################################################################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement