I2C code for Compression Load Cell getting unexpected readings

Hey guys,

I am a complete beginner when it comes to i2c and the Arduino Due, so sorry if this is a dumb question. I am trying to set up i2c communication to a load cell (Datasheet: https://www.te.com/commerce/DocumentDelivery/DDEController?Action=showdoc&DocId=Data+SheetFX29A5pdfEnglishENG_DS_FX29_A5.pdfCAT-FSE0006). When I originally wrote the code for the arduino uno and esp32 and it works for those boards. My code is shown below:

#include <Wire.h>

#define UseDebug 1

#define clockFrequency 400000
#define zeroOffset 970
#define linearity 130.2

int curAddress = 0x28;

void setup() {
  Wire.begin(); //Starts I2C, will need to change these two values (or delete them)
  Wire.setClock(clockFrequency); //Sets I2C frequency to fastest
  Serial.begin(115200);
}

void loop() {
  Wire.beginTransmission(curAddress); //Request Measurement
  Wire.endTransmission();
  
  delay(100); //Delay for measurement to be taken (could be done in IRQ)
  
  Wire.requestFrom(curAddress, 2); //Requests two bytes of data 
  byte msb = Wire.read();
  byte lsb = Wire.read();

  #if (UseDebug)
  byte statusVals = msb/64; //Determines the status values from the measurement to ensure a new measurement was taken
  Serial.print("status:");
  Serial.println(statusVals, BIN);
  Serial.print("msb:");
  Serial.println(msb, BIN);
  Serial.print("lsb:");
  Serial.println(lsb, BIN);
  #endif
  
  int dataVal = (msb%64)*256 + lsb; //Throws out the status bits and converts the measurement data into a single int
  Serial.print("dataValue:");
  Serial.println(dataVal);
  
  float weightVal = (dataVal-zeroOffset)/linearity; //Adjusts the data with the above linearity and zero-offset vals
  Serial.println("Weight: " + String(weightVal) + " lbs"); 
  
  Serial.println();
  delay(1000);
}

When using my uno or esp I get the following output with no load applied:
Status: 0
msb: 11
lsb: 11110011
dataValue: 1011
Weight: 0.31 lbs

While I get this for the due:
Status: 0
msb: 11111
lsb: 10101011
dataValue: 8107
Weight: 54.82 lbs

Thanks for any help and let me know if you need more information.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.