We have launched a new Community! Please post any new forum topics there. This forum will remain available as an archive, but we hope you enjoy the new experience and feature set the latest NCD Community will offer!

Not connecting to I2C?

Hi,

 

I'm using the generic code from github to connect to a PR17-17_20A using a Photon. I didn't receive any instructions but I assume the Photon is inserted in the pins starting at the edge of the board. 

It doesn't appear as though I'm connecting to the device via i2c as it always reports "No Data". Thoughts on how to troubleshoot?

 

Thanks.

#include  <spark_wiring_i2c.h>
#include <application.h>

// PECMAC125A I2C address is 0x2A(42)
#define Addr 0x2A

unsigned int data[36];
int typeOfSensor = 0;
int maxCurrent = 0;
int noOfChannel = 0;
double current = 0.0;
void setup()
{
  // Set variable
  Particle.variable("i2cdevice", "PECMAC125A");
  Particle.variable("typeOfSensor", typeOfSensor);
  Particle.variable("maxCurrent", maxCurrent);
  Particle.variable("noOfChannel", noOfChannel);
  Particle.variable("Current", current);

  // Initialise I2C communication as MASTER
  Wire.begin();
  // Initialise Serial Communication, set baud rate = 9600
  Serial.begin(9600);

  // Start I2C transmission
  Wire.beginTransmission(Addr);
  // Command header byte-1
  Wire.write(0x92);
  // Command header byte-2
  Wire.write(0x6A);
  // Command 2 is used to read no of sensor type, Max current, No. of channel
  Wire.write(0x02);
  // Reserved
  Wire.write(0x00);
  // Reserved
  Wire.write(0x00);
  // Reserved
  Wire.write(0x00);
  // Reserved
  Wire.write(0x00);
  // CheckSum
  Wire.write(0xFE);
  // Stop I2C transmission
  Wire.endTransmission();

  // Request 6 bytes of data
  Wire.requestFrom(Addr, 6);

  // Read 6 bytes of data
  if (Wire.available() == 6)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
    data[2] = Wire.read();
    data[3] = Wire.read();
    data[4] = Wire.read();
    data[5] = Wire.read();
    Particle.publish("Found Data");
  }
  else {Particle.publish("No Data");}

  typeOfSensor = data[0];
  maxCurrent = data[1];
  noOfChannel = data[2];

  // Output data to dashboard
  Particle.publish("Type Of Sensor : ", String(typeOfSensor));
  delay(1000);
  Particle.publish("Max Current : ", String(maxCurrent));
  delay(1000);
  Particle.publish("No. Of Channel : ", String(noOfChannel));
  delay(1000);
}

void loop()
{

}

 

T

Please ignore. A "reset" produced the expected output.

T

Great!  Please let us know if you run into any other questions.

Thank you,

Travis Elliott