The simplest digital potentiometer AD5206 [code snippet]

When it comes to digital potentiometers there are a lot of options and some are very advanced, allowing to save position in potentiometer's EEPROM, read the current setting, increment 1 click at a time, lock the position, etc, etc. I tried a few and then stumbled upon AD5206. This is probably the simplest digital potentiometer you can find. It is a 6 channel, stripped down bare minimum version that only need 2 commands - number of the channel (0...5), value to set (0...255)!

Here is how simple it is to work with this potentiometer: Set all wipers midway:

	// setup
	pinMode(YOUR_SELECT_PIN, OUTPUT);
	pinMode(YOUR_CLOCK_PIN, OUTPUT);
	pinMode(YOUR_DATAOUT_PIN, OUTPUT);
	digitalWrite(YOUR_SELECT_PIN, HIGH);
	digitalWrite(YOUR_CLOCK_PIN, HIGH);
	digitalWrite(YOUR_DATAOUT_PIN, HIGH);


	// use
	for (int i = 0; i < 6; ++i)
	{
		digitalWrite(YOUR_SELECT_PIN, LOW);
		shiftOut(YOUR_DATAOUT_PIN, YOUR_CLOCK_PIN, MSBFIRST, i); // channel
		shiftOut(YOUR_DATAOUT_PIN, YOUR_CLOCK_PIN, MSBFIRST, 127); // half way
		digitalWrite(YOUR_SELECT_PIN, HIGH);
	}

That's all. You don't need to bother with SPI, though you can use the same pins. Can keep current value in a variable, it is not going to change unless you change it or power down. If all you want is to replace physical pot with digital with minimum effort, don't have to look any further.

1 Like

Nice, thanks.
This very useful. I found them for less than $2 on aliexpress.

Nice, though I don’t shop on Ali after the seller sent wrong goods and Ali decided that I should pay half, even though it was not what I paid for.

That's rough. Hope it wasn't too much of a loss.
I buy a lot from them, 20-30 orders per year. I've had a couple packages not show up and one wrong order but I've been fortune enough not to get burned like that. In my last order I got some loose CPLDs that I have yet to mount. Only $0.75 each.

It was not much, probably why they thought they could get away with, but they got under my skin, so I raised issue with PayPal. PayPal contacted Ali, and Ali said, ok send it back to us for full refund then. The postage was 3x the money they owed me, PayPal reimbursed me for the postage, and now Im waiting for the rest of my refund upon delivery. I’m glad this happened with the cheap item, and I was thinking of ordering oscilloscope from Ali, woohoo, dodged that bullet.

Another dispute that went bad at the same time, Yodel, UK delivery company, lost my parcel. Ali ruled it was my fault I did not pick it up, even though I showed the evidence where Yodel admitted losing it. So no more shopping on Ali for me.

Thanks. Very useful

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.