Read in X, Y and Z values from magnometer? (really a question about getting multiple values into a function)


#1

All of the examples show how to deal with a single variable input – for example, to take a temperature reading and modify it into a nice string. But what I need to do is take in a X and Y value and pump it into a custom function (I’ll calculate ARCTAN2 (X, Y) to get the orientation angle).

How is this done? When I make a function, it only has one input. How do I get both the X and Y values?


#2

Hi,

If you call the “Get Magnetometer Data” ability of the sensor, the resulting output is a struct of type ATMO_3dFloatVector_t. This is true for any 3 axis sensor (accelerometer, magnetometer, gyroscope).

In your function element, you can use something like this to get the raw values:

ATMO_3dFloatVector_t values;
ATMO_Get3dVectorFloat(in, &values);
char testStr[64];
sprintf(testStr, "X: %f\r\nY:%f", values.x, values.y);
ATMO_CreateValueString(out, testStr);

This code parses out the raw values, then generates a string and outputs it to the next element in the chain. I’ve attached a working example for the NXP RapidIoT kit that displays this string on the display every second.

Hope that helps!
-Nick
Magnetometer_Values.atmo (373.5 KB)