Finding true north on a Photon / Electron

I’m working on a wearable project that requires me to be able to detect where north is, in relation to my Particle Photon (Or Electron - I’m working on the photon for now, but I’m planning on porting it to an Electron eventually).

I have an HMC5883L breakout but there are 2 issues:

  1. I can’t be able to find a library that works for it.
  2. Even if I do - from looking at outputs of this breakout, I don’t know how to convert that information to a direction.

Any suggestions on how I can proceed? I’m not married to the 5883 if you have other ideas on how to do this.

Please help,
Noam

Have you had a look at the Adafruit or SparkFun libraries?

And there is a port of the Adafruit library available for Particle

(no guaranties about the quality tho', since it was last updated over a year ago)

If that library does not work then let me know because I got this library working with the Photon.

The compass only really works well if it's completely flat if you tilt it in any direction it throws off the reading pretty good which is frustrating.

Hopefully, it works better for you, but I find these hard to use. My goal was also to find true north but all the compasses I have tried were not stable enough.

I’ve been trying to use the Adafruit library but it won’t compile.

In file included from /src/heaters_v2.cpp:2:0:
lib/Adafruit_HMC5883/src/Adafruit_HMC5883.h:113:10: error: conflicting return type specified for 'virtual void Adafruit_HMC5883_Unified::getEvent(sensors_event_t*)'
void getEvent(sensors_event_t*);
^

In file included from lib/Adafruit_Sensor/src/Adafruit_Sensor/Adafruit_Sensor.h:1:0,
from lib/Adafruit_HMC5883/src/Adafruit_HMC5883.h:28,
from /src/heaters_v2.cpp:2:
lib/Adafruit_Sensor/src/Adafruit_Sensor/…/Adafruit_Sensor.h:149:16: error: overriding 'virtual bool Adafruit_Sensor::getEvent(sensors_event_t*)'
virtual bool getEvent(sensors_event_t*) = 0;
^

/src/heaters_v2.cpp: In function ‘void setup()’:
/src/heaters_v2.cpp:16:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
int onOff;
^
/src/heaters_v2.cpp: In function ‘int heat(String)’:
/src/heaters_v2.cpp:39:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

                           ^

/src/heaters_v2.cpp:54:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

                               ^

/src/heaters_v2.cpp:67:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
int wasFound = searchArray(onOff);
^
/src/heaters_v2.cpp: In function ‘int searchArray(int)’:
/src/heaters_v2.cpp:91:51: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

                                           ^

make[1]: *** […/build/target/user/platform-6src/heaters_v2.o] Error 1
make: *** [user] Error 2

looks like getEvent() cannot make up its mind what it wants to be when it grows up...

Perhaps check the functions to see if they intend to return a bool or are indeed void & edit accordingly.

you can probably ignore the warnings...

I can’t compile the library in Particle DEV anymore either since it defaults to 0.6.1 firmware.

No clue on how to do that. Can you help?

Try to compile using the WebIDE but compile for firmware 0.6.0 instead of 0.6.1. That may help since 0.6.1 is having issues with libraries that normally compile just fine.

I tried that with all the versions down to 0.5.3 before putting this on the forum.

Fixed in library version 1.0.9. Thanks for reaching out over email, @zomerfeld.