Here's the code to control an AD5254 digital potentiometer using an Arduino Duemilanove. We'll use this four channel digital potentiometer to make the Honda ECU see appropriate resistances for items like temperature sensors.
// I2C Digital Potentiometer
// by Jake Staub
// Controls one AD5254 256 position digital potentiometer via I2C/TWI
//
// Device address 01011(AD1)(AD0) from data sheet
// AD1 AD0 Device Addressed
// 0 0 U1
// 0 1 U2
// 1 0 U3
// 1 1 U4
// Potentiometer address from data sheet
// A4 A3 A2 A1 A0 RDAC
// 0 0 0 0 0 RDAC0
// 0 0 0 0 1 RDAC1
// 0 0 0 1 0 RDAC2
// 0 0 0 1 1 RDAC3
// Attach leads to W and B so resistance value counts up in increments.
// Created 27 February 2009
// Arduino analog input 4 - I2C SDA
// Arduino analog input 5 - I2C SCL
#include Wire.h Note: place carrots around Wire.h; for some reason this page editor won't allow me to save the proper line of code.
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte val = 0;
void loop()
{
Wire.beginTransmission(0x2c); // transmit to device U1 (0x2c or hex for 0101100)
// device address is specified in datasheet,
// up to three more devices could be used; U2, U3, U4 (addresses above)
Wire.send(0x00); // sends instruction byte to RDAC0 (0x00 or hex for 0000000)
Wire.send(val); // sends potentiometer value byte
Wire.endTransmission(); // stop transmitting
Wire.beginTransmission(0x2c);
Wire.send(0x01); // sends instruction byte to RDAC1 (0x01 or hex for 0000001)
Wire.send(val);
Wire.endTransmission();
Wire.beginTransmission(0x2c);
Wire.send(0x02); // sends instrcution byte to RDAC2 (0x02 or hex for 0000010)
Wire.send(val);
Wire.endTransmission();
Wire.beginTransmission(0x2c);
Wire.send(0x03); // sends instruction byte to RDAC3 (0x03 or hex for 0000011)
Wire.send(val);
Wire.endTransmission();
val++; // increment value
if(val == 255) // if reached 256th position (max)
{
val = 0; // start over from lowest value
}
delay(5000); // time delay to see resistance values change via multimeter
}






