0

Using a library variable
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Using a library variable

by Snaresman on Mon Jul 29, 2019 11:41 pm

I'm new to this and I need help on how to use a variable I've found in a library. I'm making a compass using the Adafruit_Senson.h library on an Arduino Mega 2560. Here are the sections of the library they are in:

/** struct sensors_vec_s is used to return a vector in a common format. */
typedef struct {
union {
float v[3];
struct {
float x;
float y;
float z;
};
/* Orientation sensors */
struct {
float roll; /**< Rotation around the longitudinal axis (the plane body, 'X axis'). Roll is positive and increasing when moving downward. -90°<=roll<=90° */
float pitch; /**< Rotation around the lateral axis (the wing span, 'Y axis'). Pitch is positive and increasing when moving upwards. -180°<=pitch<=180°) */
float heading; /**< Angle between the longitudinal axis (the plane body) and magnetic north, measured clockwise when viewing from the top of the device. 0-359° */
};


I want to use the "Heading" variable at the end. I also want to use this one:


/* Sensor event (36 bytes) */
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
typedef struct
{
int32_t version; /**< must be sizeof(struct sensors_event_t) */
int32_t sensor_id; /**< unique sensor identifier */
int32_t type; /**< sensor type */
int32_t reserved0; /**< reserved */
int32_t timestamp; /**< time is in milliseconds */
union
{
float data[4];
sensors_vec_t acceleration; /**< acceleration values are in meter per second per second (m/s^2) */
sensors_vec_t magnetic; /**< magnetic vector values are in micro-Tesla (uT) */

The sensors_vec_t magnetic; variable.

How do I use them in a sketch?

Snaresman
 
Posts: 6
Joined: Mon Jul 29, 2019 11:30 pm

Re: Using a library variable

by franklin97355 on Tue Jul 30, 2019 12:47 am

Have you looked at the library example code yet?

franklin97355
 
Posts: 21217
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Using a library variable

by Snaresman on Tue Jul 30, 2019 6:45 pm

There isn't one with the download. There is Adafruit_Sensor.h, library properties and README.md.

Snaresman
 
Posts: 6
Joined: Mon Jul 29, 2019 11:30 pm

Re: Using a library variable

by franklin97355 on Tue Jul 30, 2019 7:19 pm

Which compass board are you using?

franklin97355
 
Posts: 21217
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Using a library variable

by Snaresman on Tue Jul 30, 2019 10:58 pm

The GY-271 H5883L magnetometer.

Snaresman
 
Posts: 6
Joined: Mon Jul 29, 2019 11:30 pm

Re: Using a library variable

by franklin97355 on Wed Jul 31, 2019 12:58 am


franklin97355
 
Posts: 21217
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Using a library variable

by oesterle on Wed Jul 31, 2019 1:20 am

Hi, Snaresman.


Adafruit used to sell the Triple-axis Magnetometer (Compass) Board - HMC5883L.

A picture of the front and back of your compass breakout would help to figure out the version you have.

If yours is marked GY-271, it's from another vendor – possibly Robotpark's GY-271 HMC5883L 3-Axis Magnetic Electronic Compass Module.

Their product page links to a GY-271 Datasheet. Inside that PDF, you'll find a link to their HMC5883L library. And in that library, you'll find an example that includes calculating and reporting heading.


Cheers,

Eric

oesterle
 
Posts: 656
Joined: Tue Sep 17, 2013 11:32 pm

Re: Using a library variable

by Snaresman on Thu Aug 01, 2019 7:38 pm

I can't get a good picture of it, but this is the one I bought:

https://smile.amazon.com/gp/product/B07 ... UTF8&psc=1

Comidox 1PCS HMC5883L GY-271 3V-5V Triple Axis Digital Compass Magnetometer Sensor Module Three-axis Magnetic Field Compass Module for Arduino IIC Board

Everything I look up says it's a HMC5883L. I can't find any libraries that work with it or that will import and work.

I'll look into the link mentioned.

Snaresman
 
Posts: 6
Joined: Mon Jul 29, 2019 11:30 pm

Re: Using a library variable

by Snaresman on Thu Aug 01, 2019 7:46 pm

I followed the link and the ones from it. It looks like my module and I've been into the links on the page. The library download doesn't work. I get the error:

Invalid library found in /Users/(xxxxxxx)/Documents/Arduino/libraries/HMC5883: no headers files (.h) found in /Users/(xxxxxxxx)/Documents/Arduino/libraries/HMC5883

I download the zip file and import it into the library. Then when I try to run it, I get the above error. It says it uploaded, but it's running a sketch that was in it before.

Snaresman
 
Posts: 6
Joined: Mon Jul 29, 2019 11:30 pm

Re: Using a library variable

by franklin97355 on Thu Aug 01, 2019 8:10 pm

This isn't an Adafruit product so I doubt our libraries will work without some modification. You should ask the maker of the board or try to find a generic library for the chip itself.

franklin97355
 
Posts: 21217
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Using a library variable

by Snaresman on Fri Aug 02, 2019 9:52 am

Thank you. I'll see if I can find one.

Snaresman
 
Posts: 6
Joined: Mon Jul 29, 2019 11:30 pm

Please be positive and constructive with your questions and comments.