Hi Everyone!!
i have been working on a project to get my arduino mega to read and display how level it is. i have been using an SCA100t Inclinometer to get the level readings via SPI and using the analog functions. the data sheet is located at:
http://www.muratamems.fi/sites/default/files/documents/sca100t_inclinometer_datasheet_8261800a.pdf
after a lot of work and some help from the forums (love these forums. they are so active and helpful!) i finaly got the SPI to work. my current issue is that my readings are all over the place (+/- 8! and when i was using the analog readings it was even worse!). This is translating into a half degree or more of fluctuation!
i have tried two of SCA100t's on two different arduinos. i have tried hooking the chip up with the recommended capacitors and resistors, and without. i have tried using only the USB power, and i have tried using a powersupply. the only thing that i havent tried that i can think of is powering the sensor with a different power source than the arduino is using, but im not even sure that would work.
does anyone have any other ideas on how to remove this circuit noise?
this is the current code that im using just incase, though im not having any issues with the code:
/*
get the SPI clock to work.
read the x and y information.
Circuit:
sensor attached to pins 50-53:
50:Data IN
51:Data OUT
53:Chip select
52:Serial Clock
*/
// inslude the SPI library:
#include <SPI.h>
// Set pins
const int dataINPin = 50; //MISO
const int dataOUTPin = 51; //MOSI
const int chipSelectPin = 53;//Chip Select Pin
const int serialClockPin = 52;//CSK
//!!!Sets commands according to spec sheet to access memory register addresses
//!!!Commands are 8 bits or one byte
const byte MEAS = B00000000; //Measure mode (normal operation mode after power on)
const byte RWTR = B00001000; //Read and write temperature data register, ONLY WRITE COMMAND, note currently in use
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);
// initialize SPI:
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(0);
// set the input & output:
pinMode (dataINPin, INPUT);
pinMode (dataOUTPin, OUTPUT);
pinMode (chipSelectPin, OUTPUT);
pinMode (serialClockPin, OUTPUT);
//!!!Allow self-test to initialize on start-up
delay(500);
}
void loop() {
//!!!assigns integer to store X axis value, BIN tells function that variable is in binary
int xAxisData = readCommand(RDAX);
Serial.println("X Axis: ");
Serial.println(xAxisData);
//!!!assigns integer to store Y axis value
int yAxisData = readCommand(RDAY);
Serial.println("Y Axis: ");
Serial.println(yAxisData);
for(int i = 0;i<90;i++) {
Serial.println();
}
delay(1000);
}
word readCommand(byte Command) {
byte inByte = 0;
word result = 0; // result to return
// take the chip select high to select the device:
digitalWrite(chipSelectPin, LOW);
//!!!SCAT datasheet specifies a 150 microsecond pause to get correct reading
delay(20);
//!!! Send command to slave(sensor):
SPI.transfer(Command);
//!!!Reads output by using measure command
result = SPI.transfer(MEAS);
// shift the first byte left, then get the second byte:
result = result << 8;
inByte = SPI.transfer(MEAS);
// combine the byte you just got with the previous one:
result = result | inByte;
// Result is in 11 bit word format with MSB first to shift ouput to 11 important bits
result = result >> 5;
// take the chip select high to de-select:
digitalWrite(chipSelectPin, HIGH);
// return the result:
return(result);
}