library for AD5242 and AD5241 digital potentiometer

I needed to work with a digital potentiometer and I choose the AD5242 (I2C). The reasons are simple: One AD5242 has two potmeters (10K in 256 steps) on board and because the AD has two free address lines, I can have 8 digital pot meters over I2C . Valid addresses are 0x2C..0x2F.

datasheet: - http://www.analog.com/static/imported-files/data_sheets/AD5241_5242.pdf -

On the internet there were samples how to control the AD5241 (single pot) but I found no code for the AD5242 and no support for the additional output lines. So I made a library that allows one to set the value of the two potmeters, read them back AND to control the 2 output lines.

The first version of the lib can be found here - https://github.com/RobTillaart/Arduino/tree/master/libraries/AD524X - and it includes a number of example sketches. The lib seems to work well and I tested the devices both at 100KHz and 400KHz without problems.

TODO:

  • read about the meaning of the shutdown bit
  • implement a read function for the 2 output lines (prio; completeness)
  • optimize if possible.
  • refactor the code

The lib can also be used for the AD5241 but of course only rdac 0 can be addressed meaningful.

Comments, remarks etc are as always welcome.

1 Like

updated to version 0.1.01
main points:

  • added getO1() , getO2() => also in test sketch
  • added zeroAll() - no test sketch yet

Hi Rob,
I just tried using your code with AD5242 and Arduino Nano and I can not get it to work.
Unfortunately there is not much description in your examples so I do not know what the functions do.
Would you be so kind to explain me shortly how does AD524X_write example works?
Best regards
Emir

Sorry for the late reaction but I never tried that (in fact any) lib on a Nano as I have none.

Is the Nano a 3.3V device?