 
   for (byte port = 0; port <= 0xf; port++) {
     uint16_t portByte = ~(1 << port);
-    //  debug("Checking port ");
-    //  debugln(port);
-    //  debug("portByte ");
-    //  debugln2(portByte, HEX);
-    // set all echos high
+    uint16_t echoByte = 0xffff;
+    debug("Checking port ");
+    debugln(port);
+    debug("portByte ");
+    debugln2(portByte, HEX);
     // set all echos high
     Wire.beginTransmission(JIGADDR_E);
-    Wire.write(0xff);
-    Wire.write(0xff);
+    Wire.write((uint8_t)(echoByte & 0xff));
+    Wire.write((uint8_t)((echoByte >> 8) & 0xff));
     error = Wire.endTransmission(true);
+    if ( error ) {
+      Serial.print("Failed to write to jig E  = ");
+      Serial.println(error);
+      digitalWrite(RED_LED, ON);
+      return;
+    }
 
     // enable the port
 
     Wire.beginTransmission(OCTO_ADDR);
+    Wire.write((uint8_t)(portByte & 0xff));
     Wire.write((uint8_t)((portByte >> 8) & 0xff));
-    Wire.write((uint8_t)(portByte & 0xff));
     error = Wire.endTransmission(true);
     if ( error ) {
       Serial.print("Failed to write to OctoSonar error = ");

    return;

  }
  retVal = Wire.read() << 8;
  retVal += Wire.read();

  if (retVal != 0xffff) {
    Serial.print("Error T_READ ");

    //   debugln("No interference from other echoes");

    // drop self
    echoByte &= ~(1 << port);
    Wire.beginTransmission(JIGADDR_E);
    Wire.write((uint8_t)(echoByte & 0xff));
    Wire.write((uint8_t)((echoByte >> 8) & 0xff));
    error = Wire.endTransmission(true);
    while (digitalRead(INT_PIN) == HIGH) {
      Serial.println("Error: INT is high when echo is low");
      Serial.print("echo ");
      Serial.println(echoByte, HEX);
      Serial.print("port ");
      Serial.println(portByte, HEX);
        Wire.requestFrom(JIGADDR_T, 2);
        retVal = Wire.read();
        retVal = Wire.read() << 8;
        error = Wire.endTransmission(true);
        Serial.print("I see trigs ");
        Serial.println(retVal, HEX);
        error = Wire.endTransmission(true);
        if ( error ) {
          Serial.print("Failed to read from jig error = ");
          Serial.println(error);
          digitalWrite(RED_LED, ON);
          return;
        }
      digitalWrite(RED_LED, ON);
      // return;
    }
    debugln("Low gives low");
  }

  // if we got here, we passed
  Serial.println("PASS");
  digitalWrite(GREEN_LED, ON);
  digitalWrite(RED_LED, OFF);
}


