{"id":13613454,"url":"https://github.com/wayoda/micropython-mcp4725","last_synced_at":"2026-01-29T01:47:44.833Z","repository":{"id":53342689,"uuid":"67341770","full_name":"wayoda/micropython-mcp4725","owner":"wayoda","description":"A micropython driver for the mcp4725 I²C DAC","archived":false,"fork":false,"pushed_at":"2016-09-06T09:06:12.000Z","size":9,"stargazers_count":12,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T15:42:09.246Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wayoda.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}},"created_at":"2016-09-04T11:46:50.000Z","updated_at":"2024-10-18T02:25:18.000Z","dependencies_parsed_at":"2022-09-03T04:22:04.514Z","dependency_job_id":null,"html_url":"https://github.com/wayoda/micropython-mcp4725","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wayoda/micropython-mcp4725","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wayoda%2Fmicropython-mcp4725","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wayoda%2Fmicropython-mcp4725/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wayoda%2Fmicropython-mcp4725/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wayoda%2Fmicropython-mcp4725/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wayoda","download_url":"https://codeload.github.com/wayoda/micropython-mcp4725/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wayoda%2Fmicropython-mcp4725/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28859843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T22:56:21.783Z","status":"ssl_error","status_checked_at":"2026-01-28T22:56:00.861Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-01T20:00:47.490Z","updated_at":"2026-01-29T01:47:44.808Z","avatar_url":"https://github.com/wayoda.png","language":"Python","funding_links":[],"categories":["精选驱动库","Libraries"],"sub_categories":["功能类","IO"],"readme":"# micropython-mcp4725\nA [micropython](http://micropython.org) driver for the MCP4725 I²C DAC.\n\nThe MCP4725 is a digital to analog converter chip with a 12-Bit resolution on\nthe output. The MCP4725 works with a supply voltage from 3.3V to 5V. The output range runs from 0V up to the supply voltage. \n\nThe MCP4725 can be configured to use one of two different addresses (0x62,0x63) on the I²C bus.\nThat way it is possible to use 2 MCP4725 on any I²C bus. The device supports\nstandard (100kbps) and fast (400kbps) and hi-speed (3.4Mbps) bus speeds. But\nhi-speed seems not to be supported by any of the micropython hardware boards.\nThe fast baudrate of 400kbps works fine with the \n[WiPy](https://www.pycom.io/solutions/py-boards/wipy/) but compared with DACs\nthat are connected to a SPI-bus updates to the output voltage on a MCP4725 are still pretty slow.\n\nThe MCP4725 supports 3 different power-down modes where the output voltage\ndriver shuts down and the device goes to sleep to save energy. The cips wakes up\nfrom power-down mode whenever a output voltage update is send to the device.\n\nThe MCP4725 also has a small eeprom where the power-down mode and the initial\noutput voltage can be configured that are to be used when the MCP4725 is powered\nup.\n\n##Using the MCP4725 in your micropython project\nYou need only a few lines of code to add a MCP4725 to your project. (see [Issue 1](https://github.com/wayoda/micropython-mcp4725/issues/1) if you don't like\nlibraries)\n\n###Create and initialze the device on the I²C bus of your micropython board\nA micropython driver for an I²C device expects you to create and initialze a\n``machine.I2C`` instance and pass that to the constructor of the driver code.\n\nThe arguments used in the code example below work for a [WiPy](https://www.pycom.io/solutions/py-boards/wipy/) board. If you try this with a\ndifferent board please check the pins to use for the I²C bus. \n\n```python\n\nfrom machine import I2C\nimport mcp4725\n\n#create a I2C bus\ni2c=I2C(0,I2C.MASTER,baudrate=400000,pins=('GP15','GP14')) \n\n#create the MCP4725 driver\ndac=mcp4725.MCP4725(i2c,mcp4725.BUS_ADDRESS[0])\n```\n\n###Update the output on the MCP4725\nThe simple way to update the output on the DAC is to write a new value to the\ndevice\n```python\ndac.write(1200)\n```\nThe actual voltage on the output depends on the supply voltage the powers the\nMCP4725. If it runs on 3.3V the above command would drive the output to\n``(3300/4096)*1200 = 996mV`` if the DAC is powered with 5V the output will be\n``1464mV``. If the argument to the ``write(value)`` is negative the output will\nbe set to ``0V``. If the value argument is bigger than 4095 the output \nwill be set to the maximum output voltage of the DAC. \n\nOn power-up the MCP4725 will be initialized with the value read from the\ninternal eeprom of the device.\n\n###Configure the MCP4725\nThe power-down mode (see\n[Datasheet](http://www.microchip.com/wwwproducts/en/en532229)) and the output\nvalue of the DAC can be configured for the active session and for future\nsessions by saving the settings in an internal eeprom of the DAC.\n\nPower-down modes are selected by the keys in the POWER_DOWN_MODE dict.\n```python\nPOWER_DOWN_MODE = {'Off':0, '1k':1, '100k':2, '500k':3}\n```\n\n```python\n#configure the DAC to go into power-down mode and set the output value to maximum output.\ndac.config('100k',4096)\n```\nAfter running the command the output value will is set to its maximum, but since the\nDAC is in power-down mode this will not be measurable on the output pin.\n\n```python\n#configure the DAC to output ``Vdd/2`` on power-up or after a reset\ndac.config('Off',2048, eeprom=True)\n```\nThis configuration will be saved in the eeprom of the DAC and will be used\neverytime the DAC is powered up or reset.\n\n###Read settings and output voltage of the MCP4725\nThe MCP4725 support a single read command that returns the current configuration as well as the configuration stored in the eeprom of the device. \n```python\n\u003e\u003e\u003eresult=dac.read()\n\u003e\u003e\u003eprint(result)\n\u003e\u003e\u003e(False,'Off',300,'1k',200)\n```\nThe method returns a tuple with 5 items. \n\n1. The busy-flag of the eeprom on the dac. If ``True`` the DAC is busy writing\n   the values for power-down mode and the startup output value to its internal\neeprom. If ``False`` the DAC is ready for a new config setting.\n2. The current power-down configuration of the DAC. Returns a string with the\n   active setting. (see\n[Datasheet](http://www.microchip.com/wwwproducts/en/en532229))\n3. The current outout value\n4. The power-down configuration stored in the eeprom. This setting takes effect\n   when the DAC is reset or powered up.\n5. The output value  configuration stored in the eeprom. This setting takes effect\n   when the DAC is reset or powered up.\n\nThe result shown in the code example will read as\n\n* Write to eeprom of the chip has finshed\n* The power-down mode is ``'Off'``, the DACs output on.\n* The output is set to ``300/4096`` of the supply voltage of the DAC.\n* On powerup or after a reset the DAC will go into power-down mode ``'1k'`` (see\n[Datasheet](http://www.microchip.com/wwwproducts/en/en532229)).\n* The output voltage on startup or after a reset will be ``200/4096`` of the supply\n  voltage.\n\n##Example session on the REPL\n```python\nMicroPython v1.8.3-80-g1f61fe0 on 2016-08-31; WiPy with CC3200 \nType \"help()\" for more information.\n\u003e\u003e\u003e from machine import I2C                                                                                                                                     \n\u003e\u003e\u003e i2c=I2C(0,I2C.MASTER,baudrate=400000,pins=('GP15','GP14'))\n\u003e\u003e\u003e from mcp4725 import MCP4725, BUS_ADDRESS\n\u003e\u003e\u003e dac=MCP4725(i2c,BUS_ADDRESS[0])\n\u003e\u003e\u003e dac.read()\n(False, 'Off', 2048, 'Off',100)\n\u003e\u003e\u003e dac.write(3000)\nTrue\n\u003e\u003e\u003e dac.config(power_down='Off',value=0,eeprom=True)\nTrue                                                                                                                                                           \n\u003e\u003e\u003e dac.read()\n(False, 'Off', 0, 'Off', 0)\n\u003e\u003e\u003e dac.write(2000)\nTrue                                                                                                                                                           \n\u003e\u003e\u003e dac.read()\n(False, 'Off', 2000, 'Off', 0)\n\u003e\u003e\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwayoda%2Fmicropython-mcp4725","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwayoda%2Fmicropython-mcp4725","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwayoda%2Fmicropython-mcp4725/lists"}