[Solved] Getting Different Value When Using CT-ARM

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

[Solved] Getting Different Value When Using CT-ARM

Postby JayJoe » Mon Mar 12, 2018 10:55 am

Hi, I am using the coding below to get data from magnetometer (HMC5883L) from GY-80 module.

CODE: SELECT_ALL_CODE
#include <Wire.h> //I2C Arduino Library
#define Magnetometer_mX0 0x03 
#define Magnetometer_mX1 0x04 
#define Magnetometer_mZ0 0x05 
#define Magnetometer_mZ1 0x06 
#define Magnetometer_mY0 0x07 
#define Magnetometer_mY1 0x08 
int mX0, mX1, mX_out;
int mY0, mY1, mY_out;
int mZ0, mZ1, mZ_out;
float Xm,Ym,Zm;
#define Magnetometer 0x1E //I2C 7bit address of HMC5883
void setup(){
  //Initialize Serial and I2C communications
  Serial.begin(9600);
  Wire.begin();
  delay(100);
 
  Wire.beginTransmission(Magnetometer);
  Wire.write(0x02); // Select mode register
  Wire.write(0x00); // Continuous measurement mode
  Wire.endTransmission();
}
void loop(){
 
  //---- X-Axis
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mX1);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)   
  {
    mX0 = Wire.read();
  }
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mX0);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)   
  {
    mX1 = Wire.read();
  }
  //---- Y-Axis
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mY1);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)   
  {
    mY0 = Wire.read();
  }
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mY0);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)   
  {
    mY1 = Wire.read();
  }
 
  //---- Z-Axis
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mZ1);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)   
  {
    mZ0 = Wire.read();
  }
  Wire.beginTransmission(Magnetometer); // transmit to device
  Wire.write(Magnetometer_mZ0);
  Wire.endTransmission();
  Wire.requestFrom(Magnetometer,1);
  if(Wire.available()<=1)   
  {
    mZ1 = Wire.read();
  }
 
  //---- X-Axis
  mX1=mX1<<8;
  mX_out =mX0+mX1; // Raw data
  // From the datasheet: 0.92 mG/digit
  Xm = mX_out*0.00092; // Gauss unit
  //* Earth magnetic field ranges from 0.25 to 0.65 Gauss, so these are the values that we need to get approximately.
  //---- Y-Axis
  mY1=mY1<<8;
  mY_out =mY0+mY1;
  Ym = mY_out*0.00092;
  //---- Z-Axis
  mZ1=mZ1<<8;
  mZ_out =mZ0+mZ1;
  Zm = mZ_out*0.00092;
 
  //Print out values of each axis
  //Serial.print("x: ");
  Serial.print(Xm);
  Serial.print(",");
  Serial.print(Ym);
  Serial.print(",");
  Serial.println(Zm);
 
  delay(50);
}


When I am using Arduino Mega, these are the datas I get:

CODE: SELECT_ALL_CODE
0.03   -0.34   0.16
0.36   -0.18   0.1
0.37   -0.18    0.09
0.37   -0.18   0.09
0.37   -0.18   0.1
0.36   -0.18   0.09
0.36   -0.18   0.09
0.37   -0.18   0.1
0.37   -0.18   0.1
0.37   -0.18   0.1
0.37   -0.18   0.09
0.37   -0.18   0.09
0.37   -0.18   0.09
0.36   -0.18   0.1
0.37   -0.18   0.1
0.37   -0.18   0.1
0.36   -0.18   0.09
0.36   -0.18   0.09
0.36   -0.18   0.1
0.36   -0.18   0.1
0.36   -0.18   0.09
0.36   -0.18   0.1
0.36   -0.18   0.1
0.36   -0.18   0.1
0.36   -0.18   0.1
0.36   -0.18   0.1
0.36   -0.18   0.1
0.37   -0.18   0.1
0.37   -0.18   0.1
0.37   -0.18   0.09
0.37   -0.17   0.1
0.37   -0.18   0.09
0.37   -0.18   0.09
0.37   -0.18   0.09
0.36   -0.18   0.09
0.37   -0.18   0.09
0.37   -0.18   0.09
0.37   -0.18   0.09
0.37   -0.18   0.09
0.37   -0.18   0.09
0.38   -0.16   0.1
0.39   -0.15   0.1
0.4   -0.14   0.11
0.4   -0.13   0.11
0.4   -0.13   0.11
0.41   -0.13   0.11
0.41   -0.12   0.11
0.41   -0.11   0.11
0.42   -0.11   0.11
0.42   -0.11   0.11
0.42   -0.11   0.11
0.43   -0.09   0.12
0.43   -0.08   0.12
0.43   -0.07   0.12
0.44   -0.06   0.12
0.44   -0.06   0.12
0.44   -0.05   0.13
0.44   -0.04   0.12
0.44   -0.02   0.13
0.44   -0.01   0.13
0.44   -0.01   0.13
0.44   -0.01   0.13
0.45   0.03   0.13
0.44   0.06   0.13
0.43   0.09   0.13
0.41   0.13   0.12
0.41   0.13   0.12
0.39   0.16   0.12
0.37   0.18   0.11
0.33   0.22   0.11
0.3   0.24   0.1
0.3   0.24   0.1
0.3   0.24   0.1
0.24   0.26   0.09
0.21   0.27   0.08
0.18   0.27   0.08
0.16   0.27   0.08
0.16   0.27   0.08
0.13   0.27   0.07
0.11   0.27   0.07
0.09   0.26   0.07
0.08   0.26   0.06
0.08   0.26   0.06
0.07   0.26   0.06
0.07   0.26   0.07
0.08   0.26   0.07
0.09   0.26   0.07
0.09   0.26   0.07
0.09   0.26   0.07
0.06   0.25   0.06
0.04   0.24   0.05
0.03   0.24   0.05
0.02   0.23   0.05
0.02   0.23   0.05
0.02   0.23   0.05
0.01   0.22   0.05
0   0.22   0.05
0   0.21   0.04
0   0.21   0.04
0   0.21   0.04
0   0.21   0.05
-0.01   0.21   0.05
0   0.21   0.05
0   0.21   0.05
0   0.21   0.05
0   0.21   0.05
-0.01   0.21   0.05
-0.01   0.21   0.05
-0.02   0.19   0.04
-0.02   0.19   0.04
-0.02   0.19   0.04
-0.06   0.15   0.03
-0.07   0.12   0.03
-0.08   0.11   0.02
-0.08   0.09   0.02
-0.08   0.09   0.02
-0.08   0.08   0.02
-0.08   0.07   0.02
-0.08   0.07   0.02
-0.08   0.07   0.02
-0.08   0.07   0.02
-0.08   0.07   0.02
-0.08   0.06   0.02
-0.08   0.05   0.02
-0.09   0.04   0.02
-0.08   0.02   0.02
-0.08   0.02   0.02
-0.08   0   0.01
-0.07   -0.03   0.01
-0.07   -0.05   0.01
-0.06   -0.06   0.01
-0.06   -0.06   0.01
-0.06   -0.07   0.02
-0.05   -0.08   0.01
-0.04   -0.09   0.01
-0.03   -0.1   0.01
-0.03   -0.1   0.01
-0.03   -0.1   0.01
-0.01   -0.13   0.01
0   -0.14   0.01
0.01   -0.15   0.01
0.03   -0.17   0.01
0.03   -0.17   0.01
0.04   -0.18   0.01
0.05   -0.19   0.01
0.06   -0.2   0.01
0.08   -0.21   0.01
0.08   -0.21   0.01
0.08   -0.21   0.01
0.1   -0.23   0.02
0.11   -0.23   0.02
0.12   -0.24   0.03
0.14   -0.25   0.03
0.14   -0.25   0.03
0.16   -0.25   0.04
0.17   -0.26   0.04
0.19   -0.25   0.05
0.22   -0.26   0.05
0.22   -0.26   0.05
0.22   -0.26   0.05
0.26   -0.25   0.06
0.28   -0.25   0.07
0.28   -0.24   0.07
0.3   -0.23   0.07
0.3   -0.23   0.07
0.32   -0.22 0.07
0.34   -0.21   0.07
0.34   -0.21   0.07
0.35   -0.2   0.08
0.35   -0.2   0.08
0.35   -0.2   0.08
0.36   -0.19   0.08
0.37   -0.18   0.08
0.37   -0.17   0.08
0.38   -0.16   0.08
0.38   -0.16   0.08
0.39   -0.15   0.09
0.39   -0.14   0.09
0.4   -0.13   0.09
0.4   -0.13   0.09
0.4   -0.13   0.09
0.39   -0.13   0.09
0.4   -0.13   0.09
0.4   -0.13   0.09
0.39   -0.13   0.09
0.39   -0.13   0.09
0.4   -0.13   0.09
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.09
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1
0.4   -0.12   0.1

But when I am using CT-ARM, with the same coding, I am getting this:

CODE: SELECT_ALL_CODE
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.19   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.19   56.52
56.52   60.19   56.52
56.52   60.2   56.52
56.52   60.19   56.52
56.52   60.2   56.52
56.52   60.19   56.52
56.52   60.19   56.52
56.52   60.19   56.52
56.52   60.19   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.19   56.52
56.52   60.19   56.52
56.52   60.19   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.21   56.52
56.52   60.21   56.52
56.52   60.22   56.52
56.52   60.23   56.52
56.52   60.23   56.52
56.52   60.23   56.52
56.52   60.24   56.52
56.52   60.25   56.52
56.52   60.26   56.52
56.52   60.26   56.52
56.52   60.26   56.52
56.52   60.27   56.52
56.52   60.27   56.52
56.52   60.27   56.52
56.52   60.27   56.52
56.52   60.27   56.52
56.52   60.28   56.52
56.52   60.28   56.52
56.52   0   56.52
56.52   0.01   56.52
56.52   0.01   56.52
56.52   0.01   56.52
56.52   0.03   56.52
56.52   0.04   56.52
56.52   0.04   56.52
56.52   0.05   56.52
56.52   0.05   56.52
56.52   0.06   56.52
56.52   0.07   56.52
56.52   0.08   56.52
56.52   0.09   56.52
56.52   0.09   56.52
56.52   0.1   56.52
56.52   0.11   56.52
56.52   0.12   56.52
56.52   0.13   56.52
56.52   0.13   56.52
56.52   0.14   56.52
56.52   0.14   56.52
56.52   0.15   56.52
56.52   0.16   56.52
56.52   0.16   56.52
56.52   0.17   56.52
56.52   0.18   56.52
56.52   0.19   56.52
56.52   0.2   56.52
56.52   0.2   56.52
56.52   0.2   56.52
56.52   0.2   56.52
56.52   0.21   56.52
56.52   0.21   56.52
56.52   0.21   56.52
56.52   0.21   56.52
56.52   0.22   56.52
56.52   0.23   56.52
56.52   0.23   56.52
56.52   0.23   56.52
56.52   0.23   56.52
56.52   0.24   56.52
56.52   0.24   56.52
56.52   0.25   56.52
56.52   0.25   56.52
56.52   0.25   56.52
56.52   0.25   56.52
56.52   0.26   56.52
56.52   0.26   56.52
56.52   0.27   56.52
56.52   0.27   56.52
56.52   0.28   56.52
56.52   0.29   56.52
56.52   0.3   56.52
56.52   0.3   56.52
56.52   0.3   56.52
56.52   0.32   56.52
56.52   0.33   56.52
56.52   0.34   56.52
56.52   0.34   56.52
56.52   0.34   56.52
56.52   0.34   56.52
56.52   0.35   56.52
56.52   0.35   56.52
56.52   0.36   56.52
56.52   0.36   56.52
56.52   0.36   56.52
56.52   0.37   56.52
56.52   0.37   56.52
56.52   0.38   56.52
56.52   0.38   56.52
56.52   0.38   56.52
56.52   0.39   56.52
56.52   0.39   56.52
56.52   0.4   56.52
56.52   0.4   56.52
56.52   0.41   56.52
56.52   0.41   56.52
56.52   0.41   56.52
56.52   0.42   56.52
56.52   0.42   56.52
56.52   0.42   56.52
56.52   0.43   56.52
56.52   0.43   56.52
56.52   0.43   56.52
56.52   0.44   56.52
56.52   0.44   56.52
56.52   0.44   56.52
56.52   0.44   56.52
56.52   0.45   56.52
56.52   0.44   56.52
56.52   0.44   56.52
56.52   0.45   56.52
56.52   0.45   56.52
1.86   0.44   56.52
1.85   0.44   56.52
1.85   0.44   56.52
1.84   0.44   56.52
1.84   0.44   56.52
1.82   0.45   56.52
1.82   0.44   56.52
1.82   0.44   56.52
1.81   0.45   56.52
1.79   0.44   56.52
1.79   0.44   56.52
1.79   0.44   56.52
1.79   0.44   56.52
1.76   0.44   56.52
1.74   0.44   56.52
1.74   0.44   56.52
1.74   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.72   0.45   56.52
1.72   0.45   56.52
1.72   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.72   0.44   56.52
1.72   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.73   0.44   56.52
1.71   0.43   56.52
1.7   0.43   56.52
1.68   0.42   56.52
1.68   0.42   56.52
1.67   0.42   56.52
1.67   0.41   56.52
1.66   0.41   56.52
1.64   0.41   56.52
1.64   0.41   56.52
1.63   0.4   56.52
1.63   0.39   56.52
1.61   0.39   56.52
1.6   0.37   56.52
1.6   0.37   56.52
1.58   0.37   56.52
1.57   0.35   56.52
1.56   0.34   56.52
1.56   0.34   56.52
1.56   0.34   56.52
1.54   0.32   56.52
1.53   0.31   56.52
1.52   0.3   56.52
1.52   0.3   56.52
1.52   0.3   56.52
1.52   0.29   56.52
1.51   0.28   56.52
1.51   0.27   56.52
1.51   0.27   56.52
1.5   0.26   56.52
1.5   0.25   56.52
1.49   0.24   56.52
1.49   0.23   56.52
1.49   0.23   56.52
1.48   0.22   56.52
1.48   0.21   56.52
1.48   0.2   56.52
1.48   0.2   56.52
1.48   0.2   56.52
1.47   0.18   56.52
1.47   0.18   56.52
1.47   0.17   56.52
1.47   0.17   56.52
1.47   0.17   56.52
1.46   0.15   56.52
1.46   0.14   56.52
1.46   0.14   56.52
1.46   0.14   56.52
1.46   0.12   56.52
1.46   0.11   56.52
1.46   0.1   56.52
1.46   0.1   56.52
1.46   0.1   56.52
1.46   0.08   56.52
1.45   0.07   56.52
1.46   0.06   56.52
1.46   0.06   56.52
1.46   0.06   56.52
1.45   0.04   56.52
1.45   0.03   56.52
1.46   0.03   56.52
1.46   0.03   56.52
1.46   0.03   56.52
1.46   0.01   56.52
1.46   0.01   56.52
1.46   60.29   56.52
1.46   60.29   56.52
1.46   60.28   56.52
1.46   60.27   56.52
1.46   60.26   56.52
1.47   60.25   56.52
1.47   60.25   56.52
1.47   60.25   56.52
1.48   60.23   56.52
1.48   60.23   56.52
1.48   60.21   56.52
1.48   60.21   56.52
1.48   60.21   56.52
1.49   60.19   56.52
1.5   60.18   56.52
1.51   60.17   56.52
1.51   60.15   56.52
1.52   60.15   56.52
1.53   60.14   56.52
1.54   60.13   56.52
1.54   60.11   56.52
1.55   60.11   56.52
1.55   60.11   56.52
1.57   60.09   56.52
1.58   60.08   56.52
1.59   60.07   56.52
1.6   60.06   56.52
1.6   60.06   56.52
1.61   60.05   56.52
1.62   60.05   56.52
1.64   60.04   56.52
1.65   60.03   56.52
1.65   60.03   56.52
1.67   60.02   56.52
1.68   60.01   56.52
1.7   60.01   56.52
1.72   60   56.52
1.72   60   56.52
1.73   59.99   56.52
1.75   59.99   56.52
1.77   59.98   56.52
1.78   59.98   56.52
1.78   59.98   56.52
1.78   59.98   56.52
1.8   59.97   56.52
1.81   59.97   56.52
1.82   59.97   56.52
1.82   59.97   56.52
1.82   59.97   56.52
1.84   59.96   56.52
1.86   59.97   56.52
56.52   59.97   56.52
56.52   59.97   56.52
56.52   59.97   56.52
56.52   59.97   56.52
56.52   59.97   56.52
56.52   59.97   56.52
56.52   59.98   56.52
56.52   59.98   56.52
56.52   59.98   56.52
56.52   59.98   56.52
56.52   59.98   56.52
56.52   59.99   56.52
56.52   59.99   56.52
56.52   59.99   56.52
56.52   59.99   56.52
56.52   59.99   56.52
56.52   60   56.52
56.52   60   56.52
56.52   60   56.52
56.52   60   56.52
56.52   60.01   56.52
56.52   60.01   56.52
56.52   60.02   56.52
56.52   60.03   56.52
56.52   60.03   56.52
56.52   60.03   56.52
56.52   60.04   56.52
56.52   60.05   56.52
56.52   60.05   56.52
56.52   60.05   56.52
56.52   60.05   56.52
56.52   60.06   56.52
56.52   60.07   56.52
56.52   60.07   56.52
56.52   60.08   56.52
56.52   60.08   56.52
56.52   60.08   56.52
56.52   60.09   56.52
56.52   60.09   56.52
56.52   60.1   56.52
56.52   60.1   56.52
56.52   60.1   56.52
56.52   60.11   56.52
56.52   60.11   56.52
56.52   60.11   56.52
56.52   60.12   56.52
56.52   60.12   56.52
56.52   60.12   56.52
56.52   60.13   56.52
56.52   60.13   56.52
56.52   60.14   56.52
56.52   60.15   56.52
56.52   60.15   56.52
56.52   60.15   56.52
56.52   60.16   56.52
56.52   60.16   56.52
56.52   60.17   56.52
56.52   60.17   56.52
56.52   60.17   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.18   56.52
56.52   60.2   56.52
56.52   60.2   56.52
56.52   60.21   56.52
56.52   60.22   56.52
56.52   60.22   56.52
56.52   60.23   56.52
56.52   60.24   56.52
56.52   60.25   56.52
56.52   60.25   56.52
56.52   60.26   56.52
56.52   60.26   56.52
56.52   60.26   56.52
56.52   60.26   56.52
56.52   60.27   56.52
56.52   60.28   56.52
56.52   60.28   56.52
56.52   60.28   56.52
56.52   0   56.52
56.52   0.01   56.52
56.52   0.02   56.52
56.52   0.02   56.52
56.52   0.02   56.52
56.52   0.03   56.52
56.52   0.03   56.52
56.52   0.03   56.52
56.52   0.03   56.52
56.52   0.03   56.52

These are the data for one turn - 360 degree. Why am I not getting negative value when using CT-ARM? I have tried change <<8 to <<32 because CT-ARM is 32-bit? Anyway it does not work. Need help and need some explanation. Thanks in advanced.
I am sorry for the long post.
JayJoe
Novice
 
Posts: 23
Joined: Thu Nov 09, 2017 4:52 pm

Re: Getting Different Value When Using CT-ARM

Postby Idris » Mon Mar 12, 2018 2:42 pm

Hi JayJoe,

Great findings!

As I know, CT-ARM doesn't have ability to pull-up at I2C pin. So could you try to put a 1k pull up resistor at I2C pin? Please update us any results.

Thanks.
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: Getting Different Value When Using CT-ARM

Postby JayJoe » Mon Mar 12, 2018 3:38 pm

Hi Idris, thanks for your reply :)

In my project, I use I2C for OLED too and it works flawlessly. If CT-ARM is not able to pull-up as what you said, then I expect I am having error with the OLED too?

Thanks
JayJoe
Novice
 
Posts: 23
Joined: Thu Nov 09, 2017 4:52 pm

Re: Getting Different Value When Using CT-ARM

Postby bengchet » Mon Mar 12, 2018 5:13 pm

HI,

May be you can view the data from Wire.read() directly first before further processing to check if both CT-ARM and Mega give same value. Of course you can follow Idris's advice to add pullup resistor to I2C lines.

OLED is not needed because it has already pull-up resistors onboard.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Getting Different Value When Using CT-ARM

Postby JayJoe » Wed Mar 14, 2018 6:16 pm

Hi,

I have checked some documentation and previous works done by others. HMC5883L needs pull up whereas GY-80 module already has pull-up built in. Thanks Idris for pointing this out.

Thanks to bengchet for showing the direction on how to debug this issue. I have solved the issue and the coding now is as followed:

CODE: SELECT_ALL_CODE
  mX1=mX1<<8;

  value_mX1 = mX1 & 1023; //extract the first 10 bits for CT-ARM. These are bits for data value

  sign_mX1 = mX1 & 1024; //extract only the 11th bit for CT-ARM. This is the bit for sign (+/-)

   if(sign_mX1 == 1024)
  {
    mX1=value_mX1 * -1;
  }

  else
  {
    mX1=value_mX1;
  }


I realized that in Arduino, it works with 10 bit for value and 1 bit for sign, whereas CT-ARM isn't so. It works up to 32 bit for value. That's why previously in CT-ARM, it shows all positive values - because the sign bit becomes value bit in CT-ARM.

So it works now and should be no problem. If there's any, I will update here.

And one more thing is, at first, instead of using

CODE: SELECT_ALL_CODE
  if(sign_mX1 == 1024)
  {
    mX1=value_mX1 * -1;
  }

 else
  {
    mX1=value_mX1;
  }


I use:

CODE: SELECT_ALL_CODE
   sign_mX1 = sign_mX1 << 22;
   mX1=sign_mX1 + value_mX1;


to shift the sign bit (the 11th bit) to the sign bit of CT-ARM (the 33rd bit). I expect it to work but it doesn't. So, where is the sign bit for CT-ARM?

Thanks.
JayJoe
Novice
 
Posts: 23
Joined: Thu Nov 09, 2017 4:52 pm

Re: Getting Different Value When Using CT-ARM

Postby bengchet » Thu Mar 15, 2018 10:53 am

Hi,

From your steps, your final approach is to get high byte and low byte values and combined into one single value.

In this case, you might just need to do the following.

CODE: SELECT_ALL_CODE
int16_t mZ_out = 0;
float Zm;
...
mZ_out = 0;
...
while(Wire.available()) { // Data Output Z LSB Register 0x06
  uint8_t c = Wire.read();
  mZ_out |= c;
}
...
while(Wire.available()) { // Data Output Z MSB Register 0x05
  uint8_t c = Wire.read();
  mZ_out |= (c << 8);
}
...
Zm = (float)mZ_out *0.0092;



Please refer to this thread to what is the actual size of int in CT-ARM. So to avoid confusion, I would strongly suggest using something like uint8_t, int8_t, int32_t etc because they are universal in most platforms.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Getting Different Value When Using CT-ARM

Postby JayJoe » Thu Mar 15, 2018 2:31 pm

Thanks bengchet. So the int for CT-ARM is 32-bit whereas for Arduino is 16-bit right. These are the most updated coding:

CODE: SELECT_ALL_CODE
...
int16_t mX1, mX_out;
uint8_t mX0;
...

...
mX1=mX1<<8;
mX_out =mX0+mX1;
Xm = mX_out*0.00092;
...


Things are solved by just doing so. Just that simple :roll: Haha
Once again, thanks !
JayJoe
Novice
 
Posts: 23
Joined: Thu Nov 09, 2017 4:52 pm


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 14 guests

cron