Writing to ADG2188 Switch Array via I2c

Hi

I am trying to get my head around controlling a Analogue Devices ADG2188 Crosspoint router with a Arduino Mega using I2C. I am using the evaluation board from AD (Eval board link)
If I run various I2C scanner sketches it show the board appearing at 0x70 so I have been using it as the address but my code won’t change the crosspoints

Any tip would be appreciated, for the moment I just want to prove I can change the stat of the switches

Thanks

Simon

// Arduino Sketch to read / Write to a Analogue Devices  
// ADG 2188 CrossPoint Switch
// It uses the I2C in the Wire Library
// Written by Simon Hill simon(-dot-)hill(-at-)swhill(-dot-)co(-dot-)uk
// 28 November 2014 

int ADG2188_Address = 0x70;  // Addres of ADG2188 Eval board

// Cross point mapping
int X2_To_Y2_On = 0x92;
int X3_To_Y3_On = 0x9B;
int X2_To_Y2_Off = 0x12;
int X3_To_Y3_Off = 0x1B;
int X2_To_Y3_On = 0x93;
int X3_To_Y2_On = 0x9A;
int X2_To_Y3_Off = 0x13;
int X3_To_Y2_Off = 0x1A;

// Cross Point Write Method
int change_now = 0x01;
int Just_load_in = 0x00;

#include <Wire.h>

void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  TWBR = 12;
  
}

void loop() {
  // put your main code here, to run repeatedly:
  Wire.beginTransmission (ADG2188_Address);
  Wire.write (X2_To_Y2_On);
  Wire.write (change_now);
  Wire.write (0);
  Wire.beginTransmission (ADG2188_Address);
  Wire.write (X3_To_Y3_On);
  Wire.write (change_now);
  Wire.write (0);
  delay (1000);
  Wire.beginTransmission (ADG2188_Address);
  Wire.write (X2_To_Y2_Off);
  Wire.write (change_now);
  Wire.write (0);
  Wire.beginTransmission (ADG2188_Address);
  Wire.write (X3_To_Y3_Off);
  Wire.write (change_now);
  Wire.write (0);
  delay (1000);
}

I would add at least a few serial print statements to see where your code is . Furthermore you might be able to read something back from the device and display that too?

Hi Rob

I am very new to this, might you be able to give me a few hints? sounds like the right kind of thing.

I really have no idea whats going on there

thanks

Simon

Hi so i have now got it switching which is the good news, but i just don’t understand how to read back the status from the switch.

I have tried (code below) but am just getting nonsense back so guess the syntax is wrong. does anyone have any idea the Datasheet is here

// Arduino Sketch to read / Write to a Analogue Devices  
// ADG 2188 CrossPoint Switch
// It uses the I2C in the Wire Library
// Written by Simon Hill simon(-dot-)hill(-at-)swhill(-dot-)co(-dot-)uk
// 28 November 2014 

int ADG2188_Address = 0x70;  // Addres of ADG2188 Eval board

// Cross point mapping
int X2_To_Y2_On = 0x92;
int X3_To_Y3_On = 0x9B;
int X2_To_Y2_Off = 0x12;
int X3_To_Y3_Off = 0x1B;
int X2_To_Y3_On = 0x93;
int X3_To_Y2_On = 0x9A;
int X2_To_Y3_Off = 0x13;
int X3_To_Y2_Off = 0x1A;

// Cross Point Write Method
int change_now = 0x01;
int Just_load_in = 0x00;

#include <Wire.h>

void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  TWBR = 12;
  Serial.begin(9600);
  Serial.println("\nAnalogue Devices I2C Comms Info");
  
}

void loop() {
  // put your main code here, to run repeatedly:
  byte i2cdata;
  byte data1; 
  byte data2;
  Serial.println("\nMain Loop");
  
  
  Wire.beginTransmission (byte(ADG2188_Address)); // Stereo on 
  Wire.write (byte(X2_To_Y2_On));
  Wire.write (byte(change_now));
  Wire.write (byte(0x00));
  i2cdata = Wire.endTransmission();     // stop transmitting
  Serial.print(i2cdata);
  Wire.beginTransmission (byte(ADG2188_Address));
  Wire.write (byte(X3_To_Y3_On));
  Wire.write (byte(change_now));
  Wire.write (byte(0x00));
  i2cdata = Wire.endTransmission();     // stop transmitting
  Serial.print(i2cdata);
  Wire.beginTransmission (byte(ADG2188_Address)); // Stereo on 
  //Wire.write (byte(0x74));
  //Wire.write (byte(0x00));
  //re.write (byte(change_now));
  Wire.requestFrom(0x74,0x00, 2);
  data1 = Wire.read();
  data2 = Wire.read();
  Serial.print(data1);
  Serial.print(data2);
  delay (1000);
  Wire.beginTransmission (byte(ADG2188_Address)); //Stereo off
  Wire.write (byte(X2_To_Y2_Off));
  Wire.write (byte(change_now));
  Wire.write (byte(0x00));
  i2cdata = Wire.endTransmission();     // stop transmitting
  Serial.print(i2cdata);
  Wire.beginTransmission (byte(ADG2188_Address));
  Wire.write (byte(X3_To_Y3_Off));
  Wire.write (byte(change_now));
  Wire.write (byte(0x00));
  i2cdata = Wire.endTransmission();     // stop transmitting
  Serial.print(i2cdata);
  
  delay (1000);
  Wire.beginTransmission (byte(ADG2188_Address)); //Stereo Reverse
  Wire.write (byte(X2_To_Y3_On));
  Wire.write (byte(change_now));
  Wire.write (byte(0x00));
  i2cdata = Wire.endTransmission();     // stop transmitting
  Serial.print(i2cdata);
  Wire.beginTransmission (byte(ADG2188_Address));
  Wire.write (byte(X3_To_Y2_On));
  Wire.write (byte(change_now));
  Wire.write (byte(0x00));
  i2cdata = Wire.endTransmission();     // stop transmitting
  Serial.print(i2cdata);
  delay (1000);
  Wire.beginTransmission (byte(ADG2188_Address)); // Stereo Reverse Off
  Wire.write (byte(X2_To_Y3_Off));
  Wire.write (byte(change_now));
  Wire.write (byte(0x00));
  i2cdata = Wire.endTransmission();     // stop transmitting
  Serial.print(i2cdata);
  Wire.beginTransmission (byte(ADG2188_Address));
  Wire.write (byte(X3_To_Y2_Off));
  Wire.write (byte(change_now));
  Wire.write (byte(0x00));
  i2cdata = Wire.endTransmission();     // stop transmitting
  Serial.print(i2cdata);
  delay (1000);
}

thanks for any help offered its appreciated

Simon

hi chaps

I am struggling an hope someone can help

i just don’t understand how to read back form the cross point switch can you tell me what i am doing wrong please?

//zoomkat 12-08-12
//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a '
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 

#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xB8, 0xF2 }; //physical mac address
byte ip[] = { 10, 99, 32, 25 }; // ip in lan
byte gateway[] = { 10, 99, 32, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84);; //server port

String readString; 
// Addres of ADG2188 Eval board
int ADG2188_Address = 0x70;  
int ADG2188_Address_W = 0x71;
// Cross point mapping
int X2_To_Y2_On = 0x92;
int X3_To_Y3_On = 0x9B;
int X2_To_Y2_Off = 0x12;
int X3_To_Y3_Off = 0x1B;
int X2_To_Y3_On = 0x93;
int X3_To_Y2_On = 0x9A;
int X2_To_Y3_Off = 0x13;
int X3_To_Y2_Off = 0x1A;

// Cross Point readback addresses
int X0 = 0x34;
int X1 = 0x3C;
int X2 = 0x74;
int X3 = 0x7C;
int X4 = 0x35;
int X5 = 0x3D;
int X6 = 0x75;
int X7 = 0x7D;

byte myCPArray[] = {0x34,0x3C,0x74,0x7C,0x35,0x3D,0x75,0x7D};
int cpCount = 8;
// Cross Point Write Method
int change_now = 0x01;
int Just_load_in = 0x00;

int reading = 0;

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("server text box test1"); // so I can keep track of what is loaded
  Wire.begin();
  TWBR = 12;
}

void loop(){
   byte i2cdata;
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //see what was captured

          //now output HTML data header

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>UKRD Audio Router</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>UKRD Audio Router</H1>");

          client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page

          client.println("Routing Options:- <p>speakerson </p>  <p>speakersoff</p> <p>rightonly</p> <p>leftonly</p>  <INPUT TYPE=TEXT NAME='LED' VALUE='' SIZE='25' MAXLENGTH='50'>
");

          client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Change Routing'>");
          client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='speakersoff'>");
          client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='speakerson'>");
         
          client.println("</FORM>");

          client.println("
");

          client.println("</BODY>");
          client.println("</HTML>");

          delay(1);
          //stopping client
          client.stop();

          /////////////////////
          if(readString.indexOf("speakerson") >0)
          {
            Wire.beginTransmission (byte(ADG2188_Address)); // Stereo on 
            Wire.write (byte(X2_To_Y2_On));
            Wire.write (byte(change_now));
            Wire.write (byte(0x00));
            i2cdata = Wire.endTransmission();     // stop transmitting
            Serial.print(i2cdata);
            Serial.print("right");
            Wire.beginTransmission (byte(ADG2188_Address));
            Wire.write (byte(X3_To_Y3_On));
            Wire.write (byte(change_now));
            Wire.write (byte(0x00));
            i2cdata = Wire.endTransmission();     // stop transmitting
            Serial.print(i2cdata);
            Serial.print("left");
          }
          if(readString.indexOf("speakersoff") >0)
          {
            Wire.beginTransmission (byte(ADG2188_Address)); // Stereo on 
            Wire.write (byte(X2_To_Y2_Off));
            Wire.write (byte(change_now));
            Wire.write (byte(0x00));
            i2cdata = Wire.endTransmission();     // stop transmitting
            Serial.print(i2cdata);
            Wire.beginTransmission (byte(ADG2188_Address));
            Wire.write (byte(X3_To_Y3_Off));
            Wire.write (byte(change_now));
            Wire.write (byte(0x00));
            i2cdata = Wire.endTransmission();     // stop transmitting
            Serial.print(i2cdata);
          }
          if(readString.indexOf("leftonly") >0)
          {
            Wire.beginTransmission (byte(ADG2188_Address)); // Stereo on 
            Wire.write (byte(X2_To_Y2_On));
            Wire.write (byte(change_now));
            Wire.write (byte(0x00));
            i2cdata = Wire.endTransmission();     // stop transmitting
            Serial.print(i2cdata);
          }
          if(readString.indexOf("rightonly") >0)
          {
            Wire.beginTransmission (byte(ADG2188_Address)); // Stereo on 
            Wire.write (byte(X3_To_Y3_On));
            Wire.write (byte(change_now));
            Wire.write (byte(0x00));
            i2cdata = Wire.endTransmission();     // stop transmitting
            Serial.print(i2cdata);
          }
          //clearing string for next read
          readString="";
          
          for (int CP = 0; CP < cpCount; CP++)  
          {
          //pinMode(myCPArray[cpCount], OUTPUT);      
  
          Wire.beginTransmission (byte(ADG2188_Address));
          Wire.write (byte(myCPArray[cpCount]));
          Wire.write (byte(change_now));
          i2cdata = Wire.endTransmission();     // stop transmitting
          Serial.print(i2cdata);
          Serial.println("Readback Starte");
          
          //Wire.beginTransmission (byte(ADG2188_Address_W));
          Wire.requestFrom(ADG2188_Address, 2);    // request 2 bytes from slave device #112

          // step 5: receive reading from sensor
          if(2 <= Wire.available())    // if two bytes were received
          {
            Serial.println("2 Bytes Receved");
            reading = Wire.read();  // receive high byte (overwrites previous reading)
            reading = reading << 8;    // shift high byte to be high 8 bits
            reading |= Wire.read(); // receive low byte as lower 8 bits
            Serial.println(reading);   // print the reading
          }


          }
          delay(250);
        }
      }
    }
  }
}

Thanks any help is appreciated

Simon

It’s probably too late for Simon, but I thought people of the future might appreciate the insight since this is the first result that comes up when you google “ADG2188 arduino”.

Here’s a sample program I wrote that will get you up and running with I2C reads and writes:

#include <Wire.h>

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
  Serial.begin(115200);
}


const byte AGD2188_ADDRESS = 0x71;  //Arduino uses 7 bit addresses. If you have an 8 bit address, drop the LSB and shift right
const byte NOW = 0x01;


// Lay out the constants for reading back the switch states
const byte X0 = 0x34;
const byte X1 = 0x3C;
const byte X2 = 0x74;
const byte X3 = 0x7C;
const byte X4 = 0x35;
const byte X5 = 0x3D;
const byte X6 = 0x75;
const byte X7 = 0x7D;

void loop()
{
  // These FOR loops will cycle from X0 - Y0 to X7 - Y7
  // The "x_value" is derived from Table 7 (AX3-AX0).  Note that it's not contiguous because they reserve
  // values for the read register values (seen above).  Kind of a pain.
  // The "y_value" is contiguous, with 0b000 corresonding to Y0 and 0b111 corresponding to Y7

  // This loop pair will ensure everything is initialized to NOT CONNECTED the very first time it runs.
  // It will look like a whole bunch of nothing is happening on the Serial port.
  for(int y = 0; y < 8; y++){  // Set up the Y Loop
    byte y_value = y;
    for(int x = 0; x < 8; x += 1){  // Set up X Loop
      byte x_value;
      int send_value;      
      if (x >= 6){             // This statement accounts for the incongruity due to table 8
        x_value = x + 2;
      }
      else {
        x_value = x;
      }
      
      send_value = x_value*8+y_value;
      write_data(send_value);
      Serial.print("Wrote ");
      Serial.println(send_value);      
      read_data(X0);
      read_data(X1);
      read_data(X2);
      read_data(X3);
      read_data(X4);
      read_data(X5);
      read_data(X6);
      read_data(X7);
      delay(100);
    }
  }


  // This pair of loops is identical to the above, except it adds 128 to the value to signify the "ON" state.
  for(int y = 0; y < 8; y++){
    byte y_value = y;
    for(int x = 0; x < 8; x += 1){
      byte x_value;
      int send_value;      
      if (x >= 6){
        x_value = x + 2;
      }
      else {
        x_value = x;
      }      
      send_value = x_value*8+y_value+128;  // Add 128 here to toggle "ON" (DATA bit in Table 7)
      write_data(send_value);

      Serial.print("Wrote ");
      Serial.println(send_value);
      
      read_data(X0);
      read_data(X1);
      read_data(X2);
      read_data(X3);
      read_data(X4);
      read_data(X5);
      read_data(X6);
      read_data(X7);
      delay(100);
    }
  }
}


void write_data(byte data_input){
  byte data_array[2];
  data_array[0] = data_input;
  data_array[1] = NOW;  // Hardcoded 2nd byte to NOW.  See comment below about DON'T CARE for read address setup.
  Wire.beginTransmission(AGD2188_ADDRESS); // transmit to device
  Wire.write(data_array, 2);
  Wire.endTransmission();    // stop transmitting
}


// To execute a read, you first have to WRITE the address value to the device.
// The second byte of the write is DON'T CARE, but it is necessary.  So we leave it as the "NOW" byte.
// After you setup the read address, all you have to do is request 2 bytes.  The first byte is always all "0".
// (See bottom trace in Figure 35)
void read_data(byte x_address){
  write_data(x_address);
  Wire.requestFrom(AGD2188_ADDRESS, 2);  
  while(Wire.available())
  {
    Serial.print(Wire.read(), BIN);
  }
  Serial.println();  
  
}

This should cycle through all of the possible combinations. From there, you’ll just have to figure out the values for the connections you actually want to make.

The “tables” and “figures” in the comments are referenced from the datasheet here: