Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
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: 21577
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: 21577
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: 21577
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: 763
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: 21577
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

Re: Using a library variable

by Bbowie on Wed Jun 03, 2020 6:41 pm

I am having difficulty getting readings to display from my electronic compass: HMC5883L

When I compile and upload the program to my arduino I only get the following displayed on my PC:

14:36:31.410 ->
14:36:31.410 -> ------------------------------------
14:36:31.450 -> Sensor: HMC5883
14:36:31.450 -> Driver Ver: 1
14:36:31.490 -> Unique ID: 12345
14:36:31.490 -> Max Value: 800.00 uT
14:36:31.530 -> Min Value: -800.00 uT
14:36:31.570 -> Resolution: 0.20 uT
14:36:31.570 -> ------------------------------------
14:36:31.610 ->

The HMC5883 pins are connected to the Arduino as follows:

+5Vols-pin 5V
Ground-pin GND
SCL - pin A5
SDA - pin A4

Why doesn't the program display X:, Y:, and Z: values?
Thank you for you help!
Bob Bowie
bbowie@yahoo.com

Here are the error messages:

Arduino: 1.8.8 (Windows 10), Board: "Arduino/Genuino Uno"

compass5:75:25: error: expected constructor, destructor, or type conversion before ';' token

displaySensorDetails();

^

compass5:76:1: error: expected declaration before '}' token

}

^

exit status 1
expected constructor, destructor, or type conversion before ';' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.[code][/code]

Attached is the code (compass5.ino )

contact me at : bbowie@yahoo.com
Thank you,
Bob Bowie
Attachments
compass5.ino
(4.23 KiB) Downloaded 1 time

Bbowie
 
Posts: 1
Joined: Wed Jun 03, 2020 9:21 am

Re: Using a library variable

by oesterle on Wed Jun 03, 2020 7:23 pm

Hi, Bob!

This is an old thread; on the Adafruit Forums, the best practice is to create a new thread with your issue, especially as your hardware will likely be different than the original poster's, and solving issues with two different configurations, yours and the original poster's, gets confusing.

That said, since this is your first post here (welcome!), let's take a look!

  • Can you post a sharp picture or two of your wiring? (800x600 works best. You can use the File Upload here to add pictures to your post.)
  • Your code looks nearly identical to the sample code in the adafruit/Adafruit_HMC5883_Unified library, and should work with Adafruit's (discontinued) Triple-axis Magnetometer (Compass) Board - HMC5883L.
  • Which specific HMC5883L product are you using? Can you include a link to its product page? If it's not from Adafruit, it may or may not work out of the box with Adafruit's library.

What are you making?

Cheers,

Eric

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

Please be positive and constructive with your questions and comments.