This example shows how to control a Analog Devices AD5171 Digital Potentiometer which communicates via the I2C
synchronous serial protocol. Using Arduino's I2C Wire
Library, the digital pot will step through 64 levels of
resistance, fading an LED.
Because the 12C protocol allows for each
enabled device to have it's own unique address, and as both master and slave
devices to take turns communicating over a single line, it is possible for your
Arduino to communicate with many different devices (in turn) while using just
two pins of your microcontroller.
Hardware Required
·
Arduino Board
·
AD5171 Digital Pot
·
LED
·
(1) 220 ohm resistor
·
(2) 4.7K ohm resistors
·
breadboard
·
hook-up wire
Circuit
Connect
pins 3, 6, and 7 of the AD5171 to
GND, and pins 2 and 8 to +5V.
Connect pin 4, the digital pot's clock pin (SCL), to analog pin 5 on the
Arduino, and pin 5, the data line (SDA), to analog pin 4. On both the SCL and
SDA lines, add 4.7K ohm pull up resistors, connecting both lines to +5 V.
Finally, wire an LED to pin 1, the AD5171's "wiper", with a 220 ohm LED in series.
When the AD5171's
pin 6, ADO, is connected to ground, it's address is is 44. To add another
digital pot to the same SDA bus, connect the second pot's ADO pin to +5V,
changing it's address to 45.
You can only use two of these digital
potentiometers simultaneously.
Schematic
Code
// I2C Digital Potentiometer
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte val = 0;
void loop()
{
Wire.beginTransmission(44); // transmit to device #44 (0x2c)
// device address is specified in datasheet
Wire.send(0x00); // sends instruction byte
Wire.send(val); // sends potentiometer value byte
Wire.endTransmission(); // stop transmitting
val++; // increment value
if(val == 64) // if reached 64th position (max)
{
val = 0; // start over from lowest value
}
delay(500);
}
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte val = 0;
void loop()
{
Wire.beginTransmission(44); // transmit to device #44 (0x2c)
// device address is specified in datasheet
Wire.send(0x00); // sends instruction byte
Wire.send(val); // sends potentiometer value byte
Wire.endTransmission(); // stop transmitting
val++; // increment value
if(val == 64) // if reached 64th position (max)
{
val = 0; // start over from lowest value
}
delay(500);
}
No comments:
Post a Comment