I got a compass GY-652 and it says it has HMC5983 chip , does it work similar with HMC5883L or a total different function? If it works can somebody tell me which libraries should i use it with to make it work with GPS.
Sorry i'm really new to Arduino and i tried searching topic like
https://forum.arduino.cc/index.php?topic=447560.0
but i can't seem to find an answer.
You can make a compass with that chip. Study the datasheet, available here.
It is 3.3V only, unless the module has a 5V regulator.
Obviously untested and to be avoided Arduino library here: GitHub - arduino/HMC5983: Proof of concept of an Arduino library for Honeywell's HMC5983 magnetic sensor.
BTW where does "Arduino LLC" find such incompetent programmers, who set such terrible examples?
Just look at this unworkable mess mixing floats and integer constants! And use atan2() for chrissakes.
* (c) 2014 David Cuartielles, Arduino LLC
*/
// calculate the heading values for all the three sensors
// range is 0xF800 to 0x07FF or -2048 to 2047
float HX = (X_MSB << 8) + X_LSB;
float HZ = (Z_MSB << 8) + Z_LSB;
float HY = (Y_MSB << 8) + Y_LSB;
// convert the numbers to fit the (WTF? JR)
if (HX > 0x07FF) HX = 0xFFFF - HX;
if (HZ > 0x07FF) HZ = 0xFFFF - HZ;
if (HY > 0x07FF) HY = 0xFFFF - HY;
// declare the heading variable we'll be returning
float H = 0;
if (HY == 0 && HX > 0) H = 180.0;
if (HY == 0 && HX <= 0) H = 0.0;
if (HY > 0) H = 90 - atan(HX/HY) * 180 / PI;
if (HY < 0) H = 270 - atan(HX/HY) * 180 / PI;
return H;
Better, but far from perfect code here: arduinosensors.nl - arduinosensors Resources and Information.
Finally, be sure to calibrate your compass. Overview here: Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers
jremington:
You can make a compass with that chip. Study the datasheet, available here.
It is 3.3V only, unless the module has a 5V regulator.
Obviously untested and to be avoided Arduino library here: GitHub - arduino/HMC5983: Proof of concept of an Arduino library for Honeywell's HMC5983 magnetic sensor.
BTW where does "Arduino LLC" find such incompetent programmers, who set such terrible examples?
Just look at this unworkable mess mixing floats and integer constants! And use atan2() for chrissakes.
* (c) 2014 David Cuartielles, Arduino LLC
*/
// calculate the heading values for all the three sensors
// range is 0xF800 to 0x07FF or -2048 to 2047
float HX = (X_MSB << 8) + X_LSB;
float HZ = (Z_MSB << 8) + Z_LSB;
float HY = (Y_MSB << 8) + Y_LSB;
// convert the numbers to fit the (WTF? JR)
if (HX > 0x07FF) HX = 0xFFFF - HX;
if (HZ > 0x07FF) HZ = 0xFFFF - HZ;
if (HY > 0x07FF) HY = 0xFFFF - HY;
// declare the heading variable we'll be returning
float H = 0;
if (HY == 0 && HX > 0) H = 180.0;
if (HY == 0 && HX <= 0) H = 0.0;
if (HY > 0) H = 90 - atan(HX/HY) * 180 / PI;
if (HY < 0) H = 270 - atan(HX/HY) * 180 / PI;
return H;
Better, but far from perfect code here: http://blog.arduinosensors.nl/2016/11/04/gy-282-compass-arduino-processing/
Finally, be sure to calibrate your compass. Overview here: https://edwardmallon.wordpress.com/2015/05/22/calibrating-any-compass-or-accelerometer-for-arduino/
From what i've seen the first one is a library which you said to be avoided but the 2nd one is not a library , isn't it?
Rather it's .ino file which seems to be the main coding file? If i'm not wrong how do i use this? use the whole codes or make my own library?
If i'm not wrong how do i use this?
Just use the .ino file as it is. But that code could be vastly improved, because you can read out all six bytes of the data in one set of calls to Wire, rather than address and read each byte individually.
You might study the "to be avoided" library to see how that is done.