Arduino library to drive MCP4631 dual pot

For stand-alone microprocessors

Arduino library to drive MCP4631 dual pot

Postby Doug Coulter » Sun Dec 31, 2017 4:04 pm

I needed this myself, so I thought I'd share - this controls a microchip MCP4631 dual pot via I2C.
I didn't generalize this at all - the intrepid reader can add:
Something to do with TCON so you can disconnect pins (why?) and ignore I2C "general call", which might be handy.
Reading the pot wiper settings - I assume I can keep track of those in a variable, and so can you, but some anal types might want to be able to read the pot.

FWIW, the thing comes up enabled with both pots set at the middle. The other weird thing is they have 129 positions - 0 through (including!) 128. I handle bad values in the class, it's pretty easy, just be aware.
the which variable can be 0 or 1 (but I and it with 1 so...false or true).

The example is on the lame side in that it's just the start of an ESP8266 sketch I'm working on that has wifi, static IP, over-the-air-updates, my LANDNS junk, and it counts pot 0 from zero up repeatedly. The rest is on you.
This is so simple to use you might have trouble even finding the code...Just unzip the library in your arduino IDE library folder and you're good to go.
The only caveat I've found is that sometimes a brutal reset will cause the MCP chip to hang and hold I2C data low...till the next power cycle. In that case, your arduino may refuse to boot unless everything gets that power cycle.
To channel Steve in India "have you tried turning it off and back on again?". I'd fix it if I knew what caused it.
Enjoy!
CLab_MCP4631.zip
the goodies
(5.36 KiB) Downloaded 277 times

MCP4631DPOT10k.pdf
the part
(3.26 MiB) Downloaded 279 times
Posting as just me, not as the forum owner. Everything I say is "in my opinion" and YMMV -- which should go for everyone without saying.
User avatar
Doug Coulter
 
Posts: 3515
Joined: Wed Jul 14, 2010 7:05 pm
Location: Floyd county, VA, USA

Return to Embedded software

Who is online

Users browsing this forum: No registered users and 2 guests