Hello there, I was wondering if anyone can help me because I am fighting with this one for a week now. I am interfacing the Arduino with the Analog Devices 362 accelerometer SPI library and I have used the examples that come with the library without any problem. In fact, I was up and running in a matter of days. However, at one point I wanted to go my own way and save the data from the accelerometer on the Arduino using the Ethernet Shield with the SD on it. I played with the Ethernet and the SD routines and they worked pretty well.
My problem is when using the routines ReadXData(int), ReadYData(int), ReadZData(int) or the ReadXYZTData routines. The documentation states that the ReadXData routine for instance returns an integer value that I can capture and convert to a string in order to save on the SD. However, if I declare Data as string and I do data = String(ReadXData(X)) I always get a 0 value. The same goes for the Y and Z axes as well.
I have the same problem using the routine ReadXYZTData(XData, YData, ZData, temperature) which is supposed to return the XData value as integer to me. If a do a String(XData) it is zero as well.
If I print the routines on the Serial Monitor with Serial.print it works very well and I can see the values changing as I move the accelerometer.
Does anyone know how I can take the results from the ReadData routines and convert them to a string so I can store them on the SD Drive ?
However, if I declare Data as string and I do data = String(ReadXData(X)) I always get a 0 value. The same goes for the Y and Z axes as well.
The String class and the string (NULL terminated array of chars) are not the same thing. You can't store a String in a string.
It looks to me like the ReadXData() function takes one argument, where to store the data, and returns nothing. Converting that nothing to a String is a waste of effort.
Of course, since you haven't actually posted any code, I'm just guessing.
If I print the routines on the Serial Monitor with Serial.print it works very well and I can see the values changing as I move the accelerometer.
Hello, thanx for the reply. What I am doing is pretty much slight modifications of existing examples. The example I am working on is the standard example for the ADXl362 accelerometer. The code is as below :
ADXL362 x2;
int temp , index = 0;
int XValue, YValue, ZValue, Temperature;
unsigned long tim ;
void setup(){
Serial.begin(115200);
x2.begin(); // Setup SPI protocol, issue device soft reset
x2.beginMeasure(); // Switch ADXL362 to measure mode
x2.checkAllControlRegs(); // Burst Read all Control Registers, to check for proper setup
Serial.print("\n\nBegin Loop Function:\n");
}
void loop()
{
if (index == 0)
{
tim = millis();
Serial.println(tim);
for (int i=0 ; i < 4;i ++)
{ //Serial.print(i);
x2.readXYZTData(XValue, YValue, ZValue, Temperature);
x2.readXData();
delay(9);
}
tim = millis();
Serial.println(tim);
}
index = 1 ;
}
So, here for instance the ReadXYZTData() is declared as void, but it is supposed to return the integer values of accelerations and Temperature in the XData, YData, ZData, Temperature variables. If I read these variables right after calling the function I do not get anything. However, the function prints fine on the serial monitor as follows :
However, at one point I wanted to go my own way and save the data from the accelerometer on the Arduino using the Ethernet Shield with the SD on it. I played with the Ethernet and the SD routines and they worked pretty well.
If you still have the ethernet shield connected, then you must use something like this setup() function.
void setup(){
Serial.begin(115200);
// disable w5100 SPI
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
// disable SD SPI
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
// now do your x2 stuff
x2.begin(); // Setup SPI protocol, issue device soft reset
x2.beginMeasure(); // Switch ADXL362 to measure mode
x2.checkAllControlRegs(); // Burst Read all Control Registers, to check for proper setup
Serial.print("\n\nBegin Loop Function:\n");
}
this is my first time working with MEMS device (ADXL362). i went to GIThub and download the library of it but library is not working
first i tried to rename it by removing the - sign by _ ,but still it didnt work.
secondly i tried to manually try to put the file in libraries folder but then also it didnt work for me .
the two libraries touchscreen and adxl362 are giving me trouble. i have install other libraries such as freqcount and lowpower they work just fine.
SOS :~ :~ :~ :~ :~ :~ :~
I have a question, what does it mean when you get the problem:
sketch_may23a.ino: In function 'void setup()':
sketch_may23a:7: error: 'x2' was not declared in this scope
sketch_may23a.ino: In function 'void loop()':
sketch_may23a:24: error: 'x2' was not declared in this scope
I am working with annem library of adxl362 with arduino. I am just doing simple read operation but the values that i am getting are wierd. As I know, the sum of the three axis should be 1000mg. But the values are much bigger. In addition, is there any possibility of write register function of this library not working? I put some code and data. Can you comment on what i am doing wrong?
#include <SPI.h>
#include <ADXL362.h>
ADXL362 xl;
int XValue, YValue, ZValue , Temperature;
void setup()
{
Serial.begin(9600);
xl.begin(); // Setup SPI protocol, issue device soft reset
xl.beginMeasure(); // Switch ADXL362 to measure mode
xl.checkAllControlRegs(); // Burst Read all Control Registers, to check for proper setup
Serial.print("\n\nBegin Loop Function:\n");
}
void loop()
{
xl.readXYZTData(XValue, YValue, ZValue, Temperature);
delay(750);
}
Serial Monitor:
Soft Reset
Setting Measurement Mode - Ref 2D before = 0, Reg 2D after = 0 (It is not writing???)
If there is anyone who faces my problem, I found a solution to meaningless values. In sparkfun page of adxl362, one of comments explains it and it worked for me. But if you know any specific problem with that library, please let everyone know...