PROBLEMS INTERFACING WITH THE ADXL362 SPI LIBRARY readXYZData ROUTINE

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 ?

Regards
MP

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.

Using what code?

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 :

XDATA = 127 YDATA = -164 ZDATA = 1107 Temperature = 412
XDATA = 70 YDATA = -220 ZDATA = 1319 Temperature = 415
XDATA = 71 YDATA = -221 ZDATA = 1327 Temperature = 412
XDATA = 71 YDATA = -223 ZDATA = 1328 Temperature = 412

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 :~ :~ :~ :~ :~ :~ :~

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

Maybe you should be a bit more specific about "not working", a link to the touchscreen hardware, and how all is wired up.

Hello,

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

And how can i solve it?

Greetz,

GSterken

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???)

Start Burst Read of all Control Regs - Library version 6-24-2-12
Reg 20 = 0
Reg 21 = 0
Reg 22 = 0
Reg 23 = 0
Reg 24 = 0
Reg 25 = 0
Reg 26 = 0
Reg 27 = 0
Reg 28 = 0
Reg 29 = 80
Reg 2A = 0
Reg 2B = 0
Reg 2C = 4
Reg 2D = 0
Reg 2E = 0

Begin Loop Funciton:
XDATA = -881 YDATA = 16 ZDATA = 127 Temperature = 0
XDATA = -1893 YDATA = 1856 ZDATA = -26081 Temperature = 0
XDATA = 176 YDATA = 440 ZDATA = -32705 Temperature = -32768
.....

Check if it is the same library as in this thread:

http://forum.arduino.cc/index.php?topic=243810.msg1745870#msg1745870

That library does not work!

Hackscribble:
Check if it is the same library as in this thread:

ADXL362 accelerometer problem - Programming Questions - Arduino Forum

That library does not work!

Yes. It is the same library. Even if so, in the page you have shared the values look good. But in mine, they are meaningless.

Do you know another working library for adxl362 or do you have any simple read code? Thanks.

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...

Regards.

I wrote the library. I am admittedly a hack when it comes to C code.

But, if you have a problem with the library, file an issue on the Github repo.

Also, the library has been recently updated to incorporate pull requests.
-Anne