error when reading sensor temperature

Hello guys

I have some error when i tried to read temperature data of my SCA100T

the formula to get the temperature data is T = counts - 197 / 1.083

T is in celcius but i keep get the result more than 1 thousand celcius

and this is the full code :

/*
 12:Data IN
 11:Data OUT
 10:Chip select
 13:Serial Clock
*/

// inslude the SPI library:
#include <SPI.h>

// Set pins
const int dataINPin = 12;     //MISO
const int dataOUTPin = 11;    //MOSI
const int chipSelectPin = 10;//Chip Select Pin
const int serialClockPin = 13;//CSK


const byte MEAS  = B00000000; //Measure mode (normal operation mode after power on)
const byte RWTR  = B00001000; //Read and write temperature data register
const byte RDSR  = B00001010; //Read status register
const byte RLOAD = B00001011; //Reload NV data to memory output register
const byte STX   = B00001110; //Activate Self test for X-channel
const byte STY   = B00001111; //Activate Self test for Y-channel
const byte RDAX  = B00010000; //Read X-channel acceleration through SPI
const byte RDAY  = B00010001; //Read Y-channel acceleration through SPI

void setup() 	{
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(0);

  // set input & output;
  pinMode (dataINPin, INPUT);
  pinMode (dataOUTPin, OUTPUT);
  pinMode (chipSelectPin, OUTPUT);
  pinMode (serialClockPin, OUTPUT);

  delay(500);	
}

void loop() {

  //read x axis
  float xAxisData = readCommand(RDAX);
  float xAxisData1 = asin(-(xAxisData - 1024)/1638)*(180/3.14);
  Serial.println("===========");
  Serial.print("X Axis: ");
  Serial.println(xAxisData1);

  //read y axis
  float yAxisData = readCommand(RDAY);
  float yAxisData1 = asin((yAxisData - 1024)/1638)*(180/3.14);
  Serial.print("Y Axis: ");
  Serial.println(yAxisData1);
  Serial.println("===========");

  //read temperature
  float temp = readCommand(RWTR);
  float temp1 = ((temp - 197)/(-1.083));
  Serial.print("Temperatur = ");
  Serial.print(temp1);
  Serial.print("  Celcius");
  Serial.println("\n");


  delay(1000);
}

word readCommand(byte Command) {

  byte inByte = 0;
  word result = 0;  
  digitalWrite(chipSelectPin, LOW);
  delay(20);
  SPI.transfer(Command);
  result = SPI.transfer(MEAS);
  result = result << 8;
  inByte = SPI.transfer(MEAS);
  result = result | inByte;
  result = result >> 5;
  digitalWrite(chipSelectPin, HIGH);

  return(result);

}

it would be very grateful for any help and guidance on this :slight_smile:

Many thanks
Teguh

Hi,
Can you post links to data on the SCA100T.

Thankyou...Tom.... :slight_smile:

word readCommand(byte Command)
{
}

  float xAxisData = readCommand(RDAX);

The function returns some shit from Redmond which is an integral value. Why are you storing the integer value in a float?

Hi,
When you serial print temp1, also print temp, and do the calculation yourself to see if it is correct
The formula looks okay in your sketch as per the data sheet.
But this quoted in your post

T = counts - 197 / 1.083

is not.

In you sketch and the data sheet, T=(counts-197)/1.083

Tom.... :slight_smile:

@PaulS Should i change it into integer ?

@Tom, oh my mistake, i forgot the bracket :D. what i truly mean is T = (counts-197)/1.083, just like in the sketch and datasheet

Hi,
When you print the calculated temperature also print the raw value that the calculation was derived from?
This will tell you if its a module failure or a calculation.

Tom.... :slight_smile: