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
Many thanks
Teguh