{"id":13802312,"url":"https://github.com/scruss/mcp4131","last_synced_at":"2025-10-06T23:20:40.110Z","repository":{"id":149744550,"uuid":"414046937","full_name":"scruss/mcp4131","owner":"scruss","description":"MicroPython module to control MicroChip's MC4131 SPI digital potentiometer","archived":false,"fork":false,"pushed_at":"2021-10-06T03:11:17.000Z","size":4,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-26T17:48:55.321Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scruss.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}},"created_at":"2021-10-06T02:44:12.000Z","updated_at":"2023-06-22T15:10:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"fa69a98c-ef6d-41a9-832f-dd410023f2cd","html_url":"https://github.com/scruss/mcp4131","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/scruss/mcp4131","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scruss%2Fmcp4131","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scruss%2Fmcp4131/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scruss%2Fmcp4131/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scruss%2Fmcp4131/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scruss","download_url":"https://codeload.github.com/scruss/mcp4131/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scruss%2Fmcp4131/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267463949,"owners_count":24091491,"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-07-28T02:00:09.689Z","response_time":68,"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-04T00:01:41.838Z","updated_at":"2025-10-06T23:20:35.057Z","avatar_url":"https://github.com/scruss.png","language":"Python","funding_links":[],"categories":["Libraries"],"sub_categories":["IO"],"readme":"# mcp4131\nMicroPython module to control MicroChip's MC4131 SPI digital potentiometer\n\n    from machine import Pin, ADC, SPI\n    import mcp4131\n    import time\n    a = ADC(0)\n    cs = Pin(17, Pin.OUT)\n    s = SPI(0, sck=Pin(18), mosi=Pin(19), miso=Pin(16))\n    m = mcp4131.MCP4131(s, cs)\n    \n    potval = m.set(0)\n    direction = 1\n    while True:\n        time.sleep(.1)\n        v = a.read_u16()\n        print(\"[ %5.3f %5.3f %5.3f ]\" % (0.0, 3.3*v/65536, 3.3))\n        if direction == 1:\n            potval = m.inc()\n        else:\n            potval = m.dec()\n        if potval == 128:\n            direction = -1\n        if potval == 0:\n            direction = 1\n\n## Hardware overview\n\nThe MCP4131 is a simple single-wiper 7-bit digital potentiometer controlled by an SPI interface. It has no memory settings, so will forget its current setting when it loses power.\n\nSpec/Datasheet: [mcp4131 | Microchip Technology](https://www.microchip.com/en-us/product/MCP4131)\n\n## Methods\n\n### Creation\n\n    m = mcp4131.MCP4131(s, cs)\n\nTakes two arguments:\n\n* *s*, an SPI object\n* *cs*, a Pin object for the SPI Chip Select line.\n\nNote that on initialization, the potentiometer is set mid-way (64).\n\n### set\n\nSet the potentiometer to a value between 0 .. 128, inclusive. Returns the value of the potentiometer:\n\n    potval = m.set(0)\n    \n### get\n\nGets the potentiometer value, a number between 0 .. 128 inclusive.\n\n    potval = m.get()\n\n### inc\n\nIncrements the value of the wiper. Will not go past 128. Returns a value between 0 .. 128, inclusive. \n\n    potval = m.inc()\n\n### dec\n\nDecrements the value of the wiper. Will not go past 0. Returns a value between 0 .. 128, inclusive. \n\n    potval = m.dec()\n\n### value\n\nSynonym for **get()**.\n\n    potval = m.value()\n    \n### ratio\n\nSimlar to  **get()**, but returns a floating point value from 0.0 .. 1.0.\n\n    potratio = m.ratio()\n\n## Note / Caveat\n\nThe MCP4131 uses a multiplexed data in/data out pin. Reading the wiper value is quite cumbersone, so I maintain the current potentiometer wiper value in a parallel variable. **get()** and others merely return the value of this variable. \n\n## Author\n© 2021, Stewart Russell, scruss.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscruss%2Fmcp4131","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscruss%2Fmcp4131","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscruss%2Fmcp4131/lists"}