Digital Potentiometer Help

I am trying to program this digital potentiometer and am beyond stuck. Here is the data sheet

http://www.analog.com/en/digital-to-analog-converters/digital-potentiometers/ad5272/products/product.html

this is the code I have so far.

#include <Wire.h>

void setup()
{
Wire.beginOnPins(5,6);
Wire.begin(); // join i2c bus (address optional for master)
int reset_command = 4096;
Wire.write(reset_command);
int enable = 7168;
Wire.write(enable);

}

byte val = 0;

void loop()
{
Wire.beginTransmission(46);
//int output = val+1024;
Wire.write(byte(0x01)); // sends instruction byte
Wire.write(val);
//Wire.write(output);
Wire.endTransmission(); // stop transmitting

val++; // increment value
if(val == 1023)
{
val = 0; // start over from lowest value
}
delay(2000);
}

At this point all I want it to do is vary the resistance for me. I am measuring the resistance between pins A and W. The SDA and SCL pins are in 5 and 6. I am also using an RFduino. PLEASE HELP!

The resistance reads zero with this code. I cant get it to do anything else.

Are you getting any error messages when you try and compile the code? If so what are they? How have you wired the SDA / SCL lines?

When I try and compile your sketch I get

sketch_jun24a.ino: In function 'void setup()':
sketch_jun24a:5: error: 'class TwoWire' has no member named 'beginOnPins'

So what is the wire library you are using?

I am also using an RFduino.

WTF is on of those?

The SDA and SCL pins are in 5 and 6.

Have you got pull up resistors?

Please read the how to use the forum sticky and modify that first post to include the proper code tags.

A quick look at the data sheet for that chip should give you some answers. For example you are writing to address 44, is that correct for your device as it can be set differently depending on which pins you set high and low. Have you tied the reset pin high? Have you decoupled the GND pin as it suggests to do, etc ...

thermalhound:
A quick look at the data sheet for that chip should give you some answers. For example you are writing to address 44, is that correct for your device as it can be set differently depending on which pins you set high and low. Have you tied the reset pin high? Have you decoupled the GND pin as it suggests to do, etc ...

I have tied the reset pin to high. All other pins are decoupled as it suggests. ADDR has no connection and according to the data sheet if ADDR isn't connected then the address is 46.

Grumpy_Mike:
When I try and compile your sketch I get

sketch_jun24a.ino: In function 'void setup()':
sketch_jun24a:5: error: 'class TwoWire' has no member named 'beginOnPins'

So what is the wire library you are using?

I am also using an RFduino.

WTF is on of those?

The SDA and SCL pins are in 5 and 6.

Have you got pull up resistors?

Please read the how to use the forum sticky and modify that first post to include the proper code tags.

#include <Wire.h>

void setup()
{
  Wire.beginOnPins(5,6);
  Wire.begin(); // join i2c bus (address optional for master)
  int reset_command = 4096;
  Wire.write(reset_command);
  int enable = 7168;
  Wire.write(enable);
  
}

byte val = 0;

void loop()
{
  Wire.beginTransmission(46); // transmit to device #44 (0x2c)
                                // device address is specified in datasheet
  int output = val+1024;  
  //Wire.write(byte(0x01));            // sends instruction byte  
  //Wire.write(val);                 // sends instruction byte  
  Wire.write(output);             // sends potentiometer value byte  
  Wire.endTransmission();     // stop transmitting

  val++;        // increment value
  if(val == 1023) // if reached 64th position (max)
  {
    val = 0;    // start over from lowest value
  }
  delay(1000);
}

I am not receiving an errors when uploading this code. Here is a link to RFduino which is the board I am using.

http://www.rfduino.com/

The SCL and SDA pins are going straight to the board. Not sure what you mean by pull up resistors.

The address also depends on the state of pins A0 and A1 which will also need to be tied either high or low depending on what you want the address to be.

Also did your code compile or did you get error messages? I, like Grumpy_Mike, got a compiler error when I tied. I did get it to compile however just by commenting out the Wire.beginOnPins line (as this isn't a valid instruction) so that it now reads ..

//Wire.beginOnPins(5,6);

The other glaring issue is that on an Arduino Uno (I am assuming this is what an RFduino is based on) SDA is on pin A4 and SCL is on pin A5 and not on digital pins 5 & 6

I2C lines (SDA and SCL) need to have a resistor (nominally 10K) placed between it and 5v (i.e. it is pulled up to 5v). Connecting the pins directly to the board without these resistors in place won't work.

The same is true for the reset line that I mentioned earlier, and the AO and A1 pins (although you can also pull them down to GND should you wish, but you do need to do one or the other which will set the address).

If you could upload a circuit diagram or even a clear photo of your circuit it would make it much easier to help you

OK so I have checked out the RFDuino and it definitely isn't based on the pin outs of the Uno so ignore what I said about pins A4 and A5.

That being said I couldn't find anything in the documentation indicating which of the pins on the device are the SDA and SCL line, in fact I couldn't see anything that said it was even compatible with the I2C protocol.

If RFDuino have supplied you with a version of the Wire.h library that they have re-written to change the pin mapping then this should be fairly simple to get working (and by adding the pull-ups etc already discussed you should get a good idea). If they haven't re-written the wire library then you will have to and that is a much larger can of worms and something you would be best consulting with the people over at RFDuino about

Hi bazinjohn

In setup(), you have ...

  int reset_command = 4096;
  Wire.write(reset_command);
  int enable = 7168;
  Wire.write(enable);

You need to surround these with Wire.beginTransmission( <device address> ) and Wire.endTransmission() as you have in loop().

Also, you are writing integer values in these two write() statements. I think you need to send each as two bytes. For example:

Wire.write(reset_command / 256); // Assumes MSB needs to be sent first
Wire.write(reset_command % 256);

Same comment applies to your code in loop() where you write the integer variable output.

I don't know if the actual values are correct - I guess you have worked them out from the data sheet.

Regards

Ray

thermalhound:
OK so I have checked out the RFDuino and it definitely isn’t based on the pin outs of the Uno so ignore what I said about pins A4 and A5.

That being said I couldn’t find anything in the documentation indicating which of the pins on the device are the SDA and SCL line, in fact I couldn’t see anything that said it was even compatible with the I2C protocol.

If RFDuino have supplied you with a version of the Wire.h library that they have re-written to change the pin mapping then this should be fairly simple to get working (and by adding the pull-ups etc already discussed you should get a good idea). If they haven’t re-written the wire library then you will have to and that is a much larger can of worms and something you would be best consulting with the people over at RFDuino about

I had to add the RFduino board and library in order to get “Wire.beginOnPin(clock pin, data pin)” to work. This command sets the SDA and SCL pins to 5 and 6 and is specific to RFduino. The circuit is an amplification board for a load cell. I’ll attach the expressPCB file and a picture of the circuit. I’m still a little confused on the addressing. Is it not 46?

sending.pcb (14.2 KB)

ADDR has no connection and according to the data sheet if ADDR isn't connected then the address is 46.

Table 11 in the datasheet you linked to says that the 7-bit address for ADDR not connected is 0b0101110. Which is indeed 46 decimal.

I had to add the RFduino board and library in order to get "Wire.beginOnPin(clock pin, data pin)" to work.

How do you mean add. There is nothing in the code you posted showing this.
Did this replace the wire library.

This is an Arduino forum not a "look alike so called compatible rip off" forum.
I suggest you try and get support from the people who made that machine.