{"id":14383843,"url":"https://github.com/rm-hull/pifm","last_synced_at":"2025-08-23T16:31:53.802Z","repository":{"id":6218112,"uuid":"7449415","full_name":"rm-hull/pifm","owner":"rm-hull","description":"Copy of http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter","archived":true,"fork":false,"pushed_at":"2017-10-15T09:55:08.000Z","size":16763,"stargazers_count":527,"open_issues_count":7,"forks_count":130,"subscribers_count":42,"default_branch":"master","last_synced_at":"2024-12-21T12:33:22.081Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rm-hull.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-05T00:13:04.000Z","updated_at":"2024-11-11T17:12:40.000Z","dependencies_parsed_at":"2022-08-31T04:30:58.967Z","dependency_job_id":null,"html_url":"https://github.com/rm-hull/pifm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rm-hull/pifm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fpifm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fpifm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fpifm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fpifm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rm-hull","download_url":"https://codeload.github.com/rm-hull/pifm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-hull%2Fpifm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271755685,"owners_count":24815459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-28T18:01:01.459Z","updated_at":"2025-08-23T16:31:52.994Z","avatar_url":"https://github.com/rm-hull.png","language":"C++","funding_links":[],"categories":["C++","electronic"],"sub_categories":["USB GADGET"],"readme":"```diff\n- Note: this project is no longer maintained\n```\n\n## UPDATE\n\n~~### https://github.com/richardghirst/PiBits/blob/master/PiFmDma/PiFmDma.c presents a rewrite using DMA, which uses much less CPU than this version. Please use that version in preference.~~\n\nThis has been updated by the original authors to use DMA, as well as allow tuning and stereo.  Richard Hirst is no longer maintaining PiBits, and refers users to this solution.\n\n## Turning the Raspberry Pi Into an FM Transmitter\n\n### Steps to play sound:\n\n*(Created by Oliver Mattos and Oskar Weigl. Code is GPL)*\n\n```\nsudo python\n\u003e\u003e\u003e import PiFm\n\u003e\u003e\u003e PiFm.play_sound(\"sound.wav\")\n```\n\nNow connect a 20cm or so plain wire to GPIO 4 (which is pin 7 on [header P1](http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29)) to act as an antenna, and tune an FM radio to 103.3Mhz\n\nfrom a [post on MAKE](http://blog.makezine.com/2012/12/10/raspberry-pi-as-an-fm-transmitter/?parent=Electronics) by Matt Richardson\n\nThe 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.\n\n### New! Now with stereo\n\n```\nsudo ./pifm left_right.wav 103.3 22050 stereo\n\n# Example command lines\n# play an MP3\nffmpeg -i input.mp3 -f s16le -ar 22.05k -ac 1 - | sudo ./pifm -\n\n# Broadcast from a usb microphone (see arecord manual page for config)\narecord -d0 -c2 -f S16_LE -r 22050 -twav -D copy | sudo ./pifm -\n```\n\n### How to change the broadcast frequency\n\nRun the ./pifm binary with no command line arguments to find usage.\n\nThe second command line argument is the frequency to transmit on, as a number in Mhz. Eg. This will transmit on 100.0\n\n\u003e sudo ./pifm sound.wav 100.0\n\nIt will work from about 1Mhz up to 250Mhz, although the useful FM band is 88 Mhz to 108 Mhz in most countries.\n\nMost radio receivers want a signal to be an odd multiple of 0.1 MHz to work properly.\n\n### The details of how it works\n\nBelow is some code that was hacked together over a few hours at the [Code Club pihack](http://blog.codeclub.org.uk/blog/brief/). 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.\n\nWhen testing, the signal only 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!\n\n~~If you're v. smart, you might be able to get stereo going!~~ Done!\n\n### Accessing Hardware\n\nThe python library calls a C program. 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)~~ 103.3, which provides a carrier. At this point, radios will stop making a \"fuzz\" noise, and become silent.\n\nModulation is done by adjusting the frequency using the fractional divider between 103.325Mhz and 103.275Mhz, 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 naive 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. \n\n### Notes\n\nThis is a copy of the updated documentation and code from \nhttp://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter, \n\nThe only changes are removal of the download link (since the source can be downloaded here), and formatting in Github Markdown.\n\nAll rights of the original authors reserved.\n\n### References\n\n* http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter\n\n* http://blog.makezine.com/2012/12/10/raspberry-pi-as-an-fm-transmitter/?parent=Electronics\n\n* http://www.youtube.com/v/ekcdAX53-S8#! \n\n* https://github.com/richardghirst/PiBits/pull/18\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frm-hull%2Fpifm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frm-hull%2Fpifm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frm-hull%2Fpifm/lists"}