{"id":13802007,"url":"https://github.com/alankrantas/micropython-TEA5767","last_synced_at":"2025-05-13T12:32:10.045Z","repository":{"id":113012376,"uuid":"206531451","full_name":"alankrantas/micropython-TEA5767","owner":"alankrantas","description":"MicroPython driver for TEA5767 FM radio module on ESP8266/ESP32/Pico","archived":false,"fork":false,"pushed_at":"2024-02-03T16:05:04.000Z","size":61,"stargazers_count":46,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-22T19:57:33.652Z","etag":null,"topics":["esp32","esp8266","fm","micropython","micropython-esp32","micropython-esp8266","pico","python","radio","tea5767"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alankrantas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-05T09:57:56.000Z","updated_at":"2025-03-17T22:46:00.000Z","dependencies_parsed_at":"2024-11-14T12:49:46.301Z","dependency_job_id":"273951df-f120-4a85-a7ec-db4509815ae1","html_url":"https://github.com/alankrantas/micropython-TEA5767","commit_stats":{"total_commits":44,"total_committers":2,"mean_commits":22.0,"dds":0.06818181818181823,"last_synced_commit":"e16e5e5aa6226ab1d6c82ef2f233ce753a23bd9c"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fmicropython-TEA5767","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fmicropython-TEA5767/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fmicropython-TEA5767/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fmicropython-TEA5767/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alankrantas","download_url":"https://codeload.github.com/alankrantas/micropython-TEA5767/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253942525,"owners_count":21988072,"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","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":["esp32","esp8266","fm","micropython","micropython-esp32","micropython-esp8266","pico","python","radio","tea5767"],"created_at":"2024-08-04T00:01:32.964Z","updated_at":"2025-05-13T12:32:09.773Z","avatar_url":"https://github.com/alankrantas.png","language":"Python","funding_links":[],"categories":["Libraries"],"sub_categories":["Communications"],"readme":"# MicroPython Driver for TEA5767 FM Radio Module\n\n![41015747](https://user-images.githubusercontent.com/44191076/64875299-62e6e300-d67f-11e9-92d2-b0bdd43494aa.jpg)\n\n[TEA5767](https://www.sparkfun.com/datasheets/Wireless/General/TEA5767.pdf) is a cheap but functional FM radio module, which allow you to build DIY FM radios. It comes with an antenna via a 3.5mm jack but have no internal volume control. \n\nThis driver has been tested on ESP8266, ESP32 and RPi Pico running MicroPython v1.16. The **CircuitPython** version can be found [here](https://github.com/alankrantas/circuitpython-TEA5767).\n\n## Wiring\n\n| Pin | Connect to |\n| --- | --- |\n| +5V | 3.3V or 5V |\n| SDA | SDA |\n| SLC | SCL |\n| GND | GND |\n\nBoth 3.3V and 5V power works; 5V may results better sound quality.\n\n## Import and Initialize\n\nUpload ```TEA5767.py``` to your board. You can use [Thonny](https://randomnerdtutorials.com/getting-started-thonny-micropython-python-ide-esp32-esp8266/) to do so.\n\nTo import and initialize the driver:\n\n```python\nfrom machine import Pin, SoftI2C\nfrom TEA5767 import Radio\n\ni2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=400000)\nradio = Radio(i2c)  # initialize and set to the lowest frequency\nradio = Radio(i2c, freq=106.7)  # initialize and set to a specific frequency\n\nprint('Frequency: FM {}\\nReady: {}\\nStereo: {}\\nADC level: {}'.format(\n        radio.frequency, radio.is_ready,  radio.is_stereo, radio.signal_adc_level\n        ))\n```\n\nYou can also use ```I2C``` module on pins that supported hardware I2C bus (ESP8266s dno't have them):\n\n```python\nfrom machine import Pin, I2C\nfrom TEA5767 import Radio\n\n# Hardware I2C bus 0 on ESP32\ni2c = I2C(0, scl=Pin(18), sda=Pin(19), freq=400000)\nradio = Radio(i2c)\n```\n\n## Parameters\n\nThe radio can be initialized with the following parameters:\n\n```python\nradio = Radio(i2c, addr=0x60, freq=106.7, band=\"US\", stereo=True,\n                      soft_mute=True, noise_cancel=True, high_cut=True)\n```\n\n| Parameter | description |\n| --- | --- |\n| ```i2c``` | ```machine.I2C``` or ```machine.SoftI2C``` object |\n| ```addr``` | I2C address (default ```0x60```) |\n| ```freq``` | FM frequency (default = lowest freq by the ```band``` setting) |\n| ```band``` | band limits; ```\"US\"``` (default) = US/Europe band (87.5-108 MHz); ```\"JP\"``` = Japan band (76-91 MHz) |\n| ```stereo``` | stereo mode (default ```True``` = use stereo audio if possible; ```False``` = forced mono) |\n| ```soft_mute``` | soft mute mode (noise control, default ```True```) |\n| ```noise_cancel``` | stereo noise cancelling (default ```True```) |\n| ```high_cut``` | high cut control (noise control, default ```True```) |\n\n## Set Frequency\n\nSet the radio to a specific frequency:\n\n```python\nradio.set_frequency(106.7)  # set to FM 106.7\n```\n\n## Change Frequency\n\n```python\nradio.change_freqency(0.1)  # increase 0.1 MHz\nradio.change_freqency(-0.1)  # decrease 0.1 MHz\n```\n\nThese methods also will change the direction of search mode (see below).\n\n## Mute/standby Mode\n\n```python\nradio.mute(True)\nradio.standby(True)\n```\n\n```radio.mute()``` is simply turning off the sound output. If you want to save power, use ```radio.standby()``` instead.\n\nThe TEA5767 also allows you to turn off right and/or left speaker, but I decided not to implement these functions.\n\n## Search Mode\n\n```python\nradio.search(True)  # turn on search mode\nradio.search(False)  # turn off search mode\nradio.search(not radio.search_mode)  # toogle search mode\nradio.search(True, dir=1, adc=7)  # turn on search mode and set search parameters\n```\n\n* ```dir``` = search direction; ```1``` = search station by increasing frequency (default), ```0``` = decreasing.\n* ```adc``` = desired signal ADC resolution (sound quality). Available values are ```0```, ```5```, ```7``` (default) or ```10```. The radio would try to find a station which ADC level satisfied this setting.\n\nWhen the search mode is enabled, the radio would attempt to find a station with strong signal **whenever you set a new frequency or change it**.\n\nThe radio may need a bit of time to tune on a stable signal, so it would be recommended to run ```radio.read()``` and keep updating your external display with ```radio.frequency``` on loop.\n\n## Read Status From the Radio\n\nSome variables will be updated after calling ```radio.read()```:\n\n```python\nradio.read()\nfrequency = radio.frequency\nsearch_mode = radio.search_mode\nis_ready = radio.is_ready\nis_stereo = radio.is_stereo\nsignal_adc_level = radio.signal_adc_level\n```\n\n* ```radio.frequency```: current frequency, float number (may be changed in search mode)\n* ```radio.search_mode```: search mode status (True/False)\n* ```radio.is_ready```: station is ready (signal is strong enough)? (True/False)\n* ```radio.is_stereo```: stereo mode status? (True/False)\n* ```radio.signal_adc_level```: station ADC resolution? (0, 5, 7 or 10)\n\nYou may need to call it a few times with some time delay when the search mode is enabled (the radio frequency would jump around a bit).\n\n## Manually Update the Radio\n\n```python\nradio.update()\n```\n\nThis method will be automatically called by many other methods of the radio. If you wish to change some parameters, you can manually call ```radio.update()``` to update radio status:\n\n```python\nradio.stereo_mode = True\nradio.stereo_noise_cancelling_mode = True\nradio.high_cut_mode = True\nradio.update()\n```\n\nBy default ```radio.update()``` will wait 1 ms at the end and then call ```radio.read()``` for the I2C bus have maximum delay of 400 us.\n\n## A Simplified MicroPython Version Without Using This Driver\n\nIf you just want to set the frequency of TEA5767, you can use code as short as below (simply paste it into your script):\n\n```python\nfrom machine import Pin, SoftI2C\n\ni2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=400000)\n\ndef radio_frequency(freq):\n    freqB = 4 * (freq * 1000000 + 225000) / 32768\n    i2c.writeto(0x60, bytearray([int(freqB) \u003e\u003e 8, int(freqB) \u0026 0XFF, 0X90, 0X1E, 0X00]))\n    \nradio_frequency(106.7)\n```\n\nThis code does not read anything back and don't enable the search mode, but will turn on stereo mode, soft mute, stereo noise cancelling and high cut.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Fmicropython-TEA5767","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falankrantas%2Fmicropython-TEA5767","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Fmicropython-TEA5767/lists"}