Need help using the digital potentiometer MCP4018 5k

Hi everyone,

Thanks in advance, I'm having trouble with understanding how this tiny chip works. We have a RC transmitter (ct6b) and have removed one of the 5v pots from the device and want to replace it with a digital one (MCP4018 5k) to control the rx output.

The code i am using is:

// Example 20.1

int dt = 2000; // used for delay duration
byte rval = 0x00; // used for value sent to potentiometer
#include "Wire.h"
#define pot_address 0x2F // each I2C object has a unique bus address, the MCP4018 is 0x2F or 0101111 in binary

void setup()
{
  Wire.begin();
  Serial.begin(9600); 
}

void potLoop()
// sends values of 0x00 to 0x7F to pot in order to change the resistance
// equates to 0~127
{
  for (rval=0; rval<128; rval++)
  {
    Wire.beginTransmission(pot_address);
    Wire.write(rval); // 
    Wire.endTransmission();
    Serial.print(" sent - ");
    Serial.println(rval, HEX);
    delay(dt);
  }
}

void loop()
{
  potLoop();
}

I have wired it up and I left with two wires going spare, the Wiper and the A or INPUT. My question is am I heading in the right direction altogether and if so how would i wire it up.

Image of chip diagram/pinouts: http://i1.wp.com/tronixstuff.com/wp-content/uploads/2010/10/mcp4018sch1.jpg?resize=500%2C363
REF: Tutorial: Arduino and the I2C bus – Part One | tronixstuff.com

Many thanks!

Jamie.

Nevermind, the chip was placed the wrong way round. Works a treat though, we can control the rx output digitally now.

Cheers. ps dont use your eyes to judge pin 1 on a 2x2mm chip :slight_smile: