Problems with digi poti AD5263 over I2C, pls help

Hey!

i ran into problems with the AD5263 digital potentiometer and hope to get some help here. I use the AD5263 connected to an Arduino Uno R3 to control an ion gun by remote through python. So i want the control 3 of the 4 RDAC channels to control the settings on the ion gun. My Problem is that i can only speak to 2 of 3 used channels.

A short explanation to the code: my python programm sends messages like 'Aon', 'Aoff', 'A210', 'A0', 'E255', 'Eon', 'Eoff', 'M120', 'Moff' and so on, to switch my Magnetron, Extractor or Anode on and it can send a number between 0 and 255 to set the RDACs wiper position.

My Problem here is that i can't talk to the Magnetron part. I tried a loooot of possible adress or bit sequences but it does all nothing. The rest of the code works fine. What adress do i need in the line:

Wire.write(0x10);                                                         // 16?? 8?? 3 ??

to talk to RDAC3? It drives me mad. A big thank you to everyone who contributes to my solution!!! Any additional tips to my code are also welcome. This is my most serious Arduino project so far :smiley:

#include <Wire.h>

int statusPinMagnetron = 2;
int statusPinExtractor = 4;
int statusPinAnode = 7;
int resistorvalue = 0;


void setup() {

  Serial.begin(115200);
  Wire.begin();                                           // join i2c bus (for digi poti)
  pinMode(statusPinMagnetron, OUTPUT);                  //declare pins as output
  pinMode(statusPinExtractor, OUTPUT);
  pinMode(statusPinAnode, OUTPUT);
  digitalWrite(statusPinMagnetron, HIGH);                     //initial condition to switch the devices off
  digitalWrite(statusPinExtractor, HIGH);                         //initial condition to switch the devices off
  digitalWrite(statusPinAnode, HIGH);                     //initial condition to switch the devices off

}

void loop() {

  if (Serial.available() > 0) {

    Serial.println("serial received");                             //bugtracker

    String datastring = Serial.readString();
    char valuechars[3];                                       //tranformation neccessary for differ string and resi value
    valuechars[0] = datastring[1];
    valuechars[1] = datastring[2];
    valuechars[2] = datastring[3];
    String valuestring = valuechars;
    int intconverteddatastring  = valuestring.toInt();



    if (datastring[1] != 'o') {                               //set resistorvalue if a number and no onoff state was recieved

      resistorvalue = intconverteddatastring;

    }

    else if (datastring[1] == 'o') {
      resistorvalue = 0;

    }

    if (datastring[0] == "M"[0]) {                          //commands for changing the magnetron settings

      if ((datastring[1] + datastring[2]) == ("on"[0] + "on"[1])) {      //switching magnetron on
        digitalWrite(statusPinMagnetron, LOW);
        Serial.println("Extractor on");
      }

      else if ((datastring[1] + datastring[2] + datastring[3]) == ("off"[0] + "off"[1] + "off"[2])) {          //switching magnetron off
        digitalWrite(statusPinMagnetron, HIGH);
        Serial.println("Extractor off");
      }

      else if (datastring[1] != 'o') {     // set resistor values

        Wire.beginTransmission(0x2c); // transmit to device                   
        Wire.write(0x10);                                                         // 16?? 8?? 3 ??
        Wire.write(resistorvalue);             // sends potentiometer value byte
        Wire.endTransmission();     // stop transmitting

      }
    }
    else if (datastring[0] == "E"[0]) {                          //commands for changing the Extractor settings

      if ((datastring[1] + datastring[2]) == ("on"[0] + "on"[1])) {      //switching Extractor on
         digitalWrite(statusPinExtractor, LOW);
         Serial.println("Extractor off");
      }

      else if ((datastring[1] + datastring[2] + datastring[3]) == ("off"[0] + "off"[1] + "off"[2])) {          //switching Extractor off

        digitalWrite(statusPinExtractor, HIGH);
        Serial.println("Extractor off");
      }

      else if (datastring[1] != 'o') {

        Wire.beginTransmission(0x2c); // transmit to device                   
        Wire.write(0);                                                         // 0
        Wire.write(resistorvalue);             // sends potentiometer value byte
        Wire.endTransmission();     // stop transmitting

      }


    }

    else if (datastring[0] == "A"[0]) {                          //commands for changing the Anode settings

      if ((datastring[1] + datastring[2]) == ("on"[0] + "on"[1])) {      //switching Anode on
        digitalWrite(statusPinAnode, LOW);
        Serial.println("Anode on");                                                                                               //bugtracker


      }

      else if ((datastring[1] + datastring[2] + datastring[3]) == ("off"[0] + "off"[1] + "off"[2])) {          //switching Anode off

        digitalWrite(statusPinAnode, HIGH);
        Serial.println("Anode off");                                                                                               //bugtracker
      }

      else if (datastring[0] != 'o') {            // set resistor values

        Wire.beginTransmission(0x2c); // transmit to device                   
        Wire.write(32);                                                         // 
        Wire.write(resistorvalue);             // sends potentiometer value byte
        Wire.endTransmission();     // stop transmitting

      }


    }
  }
}

What adress do i need in the line:

That depends on how you wired your chip. As you forgot to post the wiring diagram I can only tell you that the number is in the range 0x2C - 0x2F. If you provide more information (as the sticky post at the top of the forum should have told you) we might help more.

This is quite a strange syntax:

if (datastring[0] == "M"[0]) {

Using

if (datastring[0] == 'M') {

would have been much clearer.

This

if ((datastring[1] + datastring[2]) == ("on"[0] + "on"[1])) {

is definitely not doing what you expect it to do.

In any case: get rid of the String class, it wastes a lot of memory and Arduinos have very little of it. Learn to use the C string comparison functions as p.e. strncmp(), although your simple parser could be done by byte comparisons without problems.

Hi again, thanks for answering. Sry for not including the circuit from the start. I added it now, as you can see. Unfortunately the adresses between 0x2C - 0x2F don't work. Maybe the IC is faulty?

if (datastring[0] == "M"[0]) {

Yea, i thought that this is not a very elegant solution. I thought that i had to compare a char to a char and that

if (datastring[0] == 'M') {

wouldn't work because here i compare a char to a string (i think) and i had problems with that in the past.

This code part

if ((datastring[1] + datastring[2]) == ("on"[0] + "on"[1])) {

works so far, as it does what is in the brackets after the if statemant. But you are right that the handling with the string class in the arduino is stupid from my side. We built it up like this, because we needed something workin pretty quick. I will mntry to rewrite the arduino code, and the python side accordingly to communicate over byte class instead of string class.

Allright, i found the error. Our electronics guy fucked up and did pretty bad soldering at some pins. For everyone interested, the code works so far and the correct adresses for the first 3 RDAC channels are:

Wire.write(0)   //channel 1

Wire.write(32)   //channel 2

Wire.write(64)   //channel 3

The fourth one can be found out if one looks at the bit composition of the instruction byte in the data sheet. The instruction byte is effectively the byte that is send to choose the internal channel.

I can only tell you that the number is in the range 0x2C - 0x2F.

is unfortunately wrong

Can be closed. Thx