Introduction: Digital Potentiometers Arduino Shield
The Digital Potentiometers Arduino Shield has been tested for compatibility with Arduino Duemilanove, Diecimila, and Arduino UNO R1/R2
This shield is based on the device AD5206 from Analog Devices.
On the Internet we can find some very basic applications of the component, reviewed in many blogs and sites, including the arduino.cc website “Controlling a digital potentiometer using SPI“. Unfortunately these tutorials focus on the way you can control this chip: the SPI (= Serial Peripheral Interface) protocol. Also the sample Sketches we find – limited to very few lines of code – are very simple but also almost useless.
Also the usage suggestions are very poor: how to control digitally the audio levels of some devices. But then? It’s up to you. Nothing else.
So the reason I have decided to create this shield project is to have a full working digital potentiometer lab reliable and ready for real-world applications. Also the sketches are a bit more complex but includes, hopefully, useful features explained.
An application example of the shield with a second Arduino board controlling a servo has been published on an article on Electro Schematics and is described in the last part of this instruc
Step 1: The Circuit
As you can see in the circuit schematics, it is divided in three parts:
1. Test LEDs and Digital Potentiometers external connector
Every digital potentiometer output is accessible on a pin of the JP1 connector (named DigiPot Ext Connections) the same output signals are connected to six test LEDs for testing and development purpose. To avoid interferences, the jumper JP2 (named Test Led Jumper) should be disconnected to exclude the LEDs from the circuit while working together with a controlled circuit.
The AD5206 is powered by the Arduino 5VCC but accept as potentiometers reference a variable voltage between about 1,5 and 5 V. To use a different voltage than Arduino VCC the first two pins of the JP1 connector should be used to power the AD5206 potentiometers and the jumper JP3 (named Internal Power Jumper) should be disconnected, to exclude the Arduino internal voltage reference.
2. The AD5206 circuitry
The central part of the schematics includes the connections to the Arduino board of the AD5206. I have added the LED7 to monitor the SPI clock signal when the micro controller sends data to the device.
Note: the digital potentiometers of the AD5206 are internally latched: this means that when the circuit is powered, the device retains the last setting sent.
3. Test and setting trimmers
To be used for testing purposes or to preset independent values on every digital potentiometers, I have added 6 trimmers connected to the six analog input of the Arduino. In the case you need one or more analog ports free for your projects the trimmers can be disabled with the DIP Switch S2.
When connecting the Arduino shield to an external circuit board through the signals on the connector JP1, you must put the GND signal (JP1-pin1) in common with the other circuit.
Step 2: The Software
First of all take in account that to simplify the serial printing features of the sketch (used for debugging and monitoring) I have used the Streaming library. The most updated version (V.5) can be downloaded as well as the sketch from this page.
How the sketch works
Explained in few words, the shield sketch replicates the input trigger values generating a proportional value to the corresponding digital output.
The program is well documented so it is not difficult to understand how every part works. I will spend some words only on the software header where the global parameters are defined.
#define MAXPOT 6 // Max number of potentiometers #define SERIALMON // Undef SERIALMON to avoid serial output. For testing purposes only // Units to show the potentiometer resistance value. #define KOHM 0 // Set to 0 if the resistance should be in Ohm instead of K // Units to show the digital potentiometer resisance value. #define DKOHM 1 // Set to 0 if the resistance should be in Ohm instead of K // Test analog potentiometers values in Ohm #define ANALOGPOT 1000.00 // Digital potentiometer value in Ohm #define DIGITALPOT 100000.00 // Steps divider from analog converter #define ANALOGDIVIDER 1024.00 // Steps divider of the digital potentiometer #define DIGITALDIVIDER 256 // SPI Clock frequency. //Higher is the clock frequency, higher is the digital potentiometer // response. Value is expressed in reading-per-second // The frequency calculation is an integer rounded. #define DIGIPOT_FREQ 8
To debug the program seeing what's happen while interacting with the analog triggers the line of code
enables the serial monitor to continuously dump the state of the potentiometers (analog and digital)
Replace this line of code with
to disable this feature. Depending on the speed you set the serial communication between Arduino and the computer, the continuous output may limit the working speed of the program.
With the serial monitor enabled (I have tested the program with a working speed of 9600 but it works better at higher speeds), the screenshot image shows an example of what you see.
- At a reasonable serial speed the frequency the monitor is updated depends on the constant DIGIPOT_FREQ. Changing the SPI clock frequency also the clock LED on the circuit changes its blinking speed.
- The approximate resistance calculation, based on the analog detected value and the output calculated setting for every potentiometer pair (analog vs digital) is only for testing and demonstration purposes. You can remove this calculation part because these values has no influence on the behaviour of the program.
Step 3: The Shield in Action
To test a filtered analog signal using a stable acceleration and deceleration curve, I have used a second Arduino (Duemilanove version) with a simple sketch moving a micro servo following the variation of an analog input PIN. The sketch DigiPot_ServoTest can be downloaded from this page.
As shown in the video, initially the Arduino Duemilanove can control the micro servo movement with a analog potentiometer connected to the analog PIN but it is not so precise and almost difficult to manage.
In the second part of the video, without changing the program in any part, the analog potentiometer is replaced on the same analog PIN by one of the digital outputs of the shield. The progran on the shield emulates the same behaviour of the analog potentiometer but in a more precise and regular way.
The shield sketch DigiPot_Filtered running in the video can be downloaded from this page. Due the very low current needed by the analog PIN of the controlled Arduino, for testing purposes also the test LEDs of the shield are left connected.
In this sample application I have used the first four analog trimmer of the shield to set four control parameters influencing the behaviour of the digital potentiometer response, connected to the analog PIN of the second Arduino:
- Minimum value or the servo in DEG
- Max value of the servo in DEG
- Curve smoothing: how much the movement is slow and smooth
- Motor pause: the delay between two cycles.
We have a be nice policy.
Please be positive and constructive.