{"id":17227175,"url":"https://github.com/tomcombriat/dac_mcp49xx","last_synced_at":"2026-05-10T16:04:49.852Z","repository":{"id":104970380,"uuid":"266161493","full_name":"tomcombriat/DAC_MCP49XX","owner":"tomcombriat","description":"Forked version from exscape in order to make it compile for non-AVR platforms:","archived":false,"fork":false,"pushed_at":"2020-09-23T16:19:04.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T15:44:46.755Z","etag":null,"topics":["arduino","arduino-ide","dac","electronics","mcp4812","mcp4822","mcp4921","mcp4922","stm32"],"latest_commit_sha":null,"homepage":"https://github.com/exscape/electronics/tree/master/Arduino/Libraries/DAC_MCP49xx","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomcombriat.png","metadata":{"files":{"readme":"README.txt","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-05-22T16:48:17.000Z","updated_at":"2021-10-10T15:51:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c7a94bb-4cf2-4d8d-83a3-5ce8c463d8e3","html_url":"https://github.com/tomcombriat/DAC_MCP49XX","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomcombriat%2FDAC_MCP49XX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomcombriat%2FDAC_MCP49XX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomcombriat%2FDAC_MCP49XX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomcombriat%2FDAC_MCP49XX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomcombriat","download_url":"https://codeload.github.com/tomcombriat/DAC_MCP49XX/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245515604,"owners_count":20628196,"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":["arduino","arduino-ide","dac","electronics","mcp4812","mcp4822","mcp4921","mcp4922","stm32"],"created_at":"2024-10-15T04:18:25.923Z","updated_at":"2026-05-10T16:04:49.760Z","avatar_url":"https://github.com/tomcombriat.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Tweak of the following library for use with STM32 and other non_AVR platforms.\nT. Combriat\n\n\n\nArduino library for the Microchip MCP49x1/MCP49x2 series DACs\nThomas Backman \u003cserenity@exscape.org\u003e, 2012\n\nVersion 1.1 (October 2, 2012)\nChanges from v1.0:\n* Support for MCP49x2 series DACs added; thanks to Jonas Gruska for idea/code/testing\n* Library renamed from DAC_MCP49x1 to DAC_MCP49xx\n\nSupported models:\n* MCP4901 (8-bit, single)\n* MCP4911 (10-bit, single)\n* MCP4921 (12-bit, single)\n* MCP4902 (8-bit, dual)\n* MCP4912 (10-bit, dual)\n* MCP4922 (12-bit, dual)\n\nExample usage:\n\n/////////////////////////////////\n\n#include \u003cSPI.h\u003e         // Remember this line!\n#include \u003cDAC_MCP49xx.h\u003e\n\nDAC_MCP49xx dac(DAC_MCP49xx::MCP4901, 10); // DAC model, SS pin\n\nvoid setup() {\ndac.init();\n } \n\nvoid loop() {\n  dac.output(255);\n  delay(2500);\n  dac.output(0);\n  delay(2500);\n}\n\n/////////////////////////////////\n\nSee the example sketches for slightly more detailed examples.\n\n** LATCH has been removed for compatibility: just tie LDAC to GND **\n\nA note on latching/LDAC:\n\tThe way these DACs work is as follows: when a value is sent to them via\n\tthe output*() methods, the output does not instantly change.\n\tInstead, the DAC waits until the LDAC pin has been pulled low. Therefore,\n\tif that pin is tied to ground, the output *will* instantly change.\n\tHowever, if that pin is connected to the Arduino, you will need to latch\n\tthe output in order for a change to happen. There are two ways to do this:\n\t1) Call latch(), which creates a low pulse\n\t2) MCP49x2 only: call output2(), with the automaticallyLatchDual option set\n\t   (true by default), which will then call latch() for you\n\n\tThe main usage of this functionality is to synchronize multiple DACs (2 or more),\n\tto make their outputs change at the same moment, despite having the data sent\n\tto them one at a time.\n\nSimple function overview:\n\nConstructor (DAC_MCP49xx, int SS_pin)\n\tTakes three arguments: the DAC model (MCP4901, MCP4911, MCP4921,\n\tMCP4902, MCP4912 or MCP4922), the chip select pin, and the LDAC pin.\n\tIf the LDAC functionality isn't wanted (if you don't know, you likely don't\n\twant it), make sure the LDAC pin is tied to ground, and simply ignore that\n\targument (or pass -1).\n\nsetBuffer(bool)\n\tShould the DAC buffer the reference voltage?\n\tNote: if \"true\", VREF cannot be VDD (e.g. +5 V). Defaults to false.\n\nsetGain(int)\n\tSets the gain. The output voltage is x/2^n * VREF * gain, where x = the value\n\tpassed to out and n = the number of bits\n\tFor example, for a 8-bit DAC with gain 2x and VREF = 5 V where out(100) is\n\tcalled, vout = 100/256 * 5 * 2 = 3.90625 V.\n\tOnly 1 and 2 are valid values!\n\tDefaults to 1x.\n\nsetSPIDivider(int)  ** REMOVED\n\tSets the SPI clock frequency. See the Arduino docs: http://arduino.cc/en/Reference/SPISetClockDivider\n\tUses the same constants (SPI_CLOCK_DIV2 etc.) as in the Arduino docs.\n\nsetAutomaticallyLatchDual(bool)    ** REMOVED\n\tIf true: will automatically pull the LDAC pin low after output2() is called.\n\tIf false: won't do the above.\n\tOnly relevant for the MCP49x2 dual DACs.\n\tDefaults to true.\n\nshutdown(void)\n\tShuts the DAC down to save power. (~3.5 µA in standby, ~150 µA powered up.)\n\tSettling time after calling set() increases from ~5 to ~10 µs when in standby.\n\noutput(unsigned short)\n\tMCP49x1 (single DAC) only.\n\tSends the value to the DAC. If the LDAC pin is tied to ground, Vout will change \"instantly\".\n\tIf the LDAC pin is connected to the Arduino, nothing will change until latch() is called.\n\noutputA(unsigned short)\n\tMCP49x2 (dual DAC) only.\n\tSends the value to DAC A. Same as output().\n\noutputB(unsigned short)\n\tMCP49x2 (dual DAC) only.\n\tSends the value to DAC B. Otherwise same as output().\n\noutput2(unsigned short, unsigned short)\n\tMCP49x2 (dual DAC) only.\n\tSends the two output values to the two outputs of the dual DACs.\n\tLatches the output automatically unless setAutomaticallyLatchDual() has been\n\tcalled with 'false' as the argument.\n\nlatch(void)  ** REMOVED\n\tChanges the output voltage based on the last value(s) sent using the output*() methods.\n\tCreates a low pulse on the DAC's LDAC pin (pin 5 on the DAC chip).\n\tThe LDAC pin can be tied to ground instead, to update automatically ASAP, in\n\twhich case this method does nothing.\n\ninit()\n        Need to be called in setup(), for good SPI compatibility.\n\ninit(\u0026 SPIClass)\n        If you want to use another SPI port.\n\nsetPortWrite(bool)\n\tNote: PortWrite is not supported on the Arduino Leonardo, but should work on\n\tthe Uno and Mega. (One could change this by changing the ports used in the code.)\n\t*** The CS and LDAC pins set in the constructor are IGNORED when this is set to true!!! ***\n\n\tPortWrite is a method that speeds up the code significantly, but only works on fixed pins (see below).\n\tIt's roughly 30 times faster than digitalWrite in my measurements for this code.\n\t(That doesn't mean that the entire code is 30 times faster, but changing a pin value is.)\n\n\tIn order to use the faster method e.g. on the Arduino Uno, you must use pin 7 on the Uno for the LDAC pin, \n\tand pin 10 for the CS pin. Anything else won't work. If these pins are busy doing something else, you can't use this speed-up\n\twithout modifying the code.\n\n\tUse these pins:\n\n\tFor the CS pin: PD7 (Uno: digital pin 7, Mega: digital pin 38)\n\n\tAlso note that since these are fixed, and CS cannot be shared between devices, *you can't use multiple DACs with PortWrite enabled*!\n\n\tSo, in short...\n\tPro: much faster (only matters for relatively high-frequency stuff;\n\tthe difference is on the order of a few microseconds)\n\tCons: only works on fixed pins, only works with 1 DAC, doesn't work on all Arduinos\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomcombriat%2Fdac_mcp49xx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomcombriat%2Fdac_mcp49xx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomcombriat%2Fdac_mcp49xx/lists"}