Giter VIP home page Giter VIP logo

mprograms / qmc5883lcompass Goto Github PK

View Code? Open in Web Editor NEW
88.0 5.0 37.0 68 KB

QMC5883L Compass is a Arduino library for using QMC5583L series chip boards as a compass. Supports: - Getting values of XYZ axis. - Calculating Azimuth. - Getting 16 point Azimuth bearing direction (0 - 15). - Getting 16 point Azimuth bearing Names (N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW) - Smoothing of XYZ readings via rolling averaging and min / max removal. - Optional chipset modes

License: GNU General Public License v3.0

C++ 100.00%
qmc5883l arduino compass azimuth xyz bearing heading qmc5883l-library

qmc5883lcompass's People

Contributors

mprograms avatar paulosincos avatar thenitek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

qmc5883lcompass's Issues

Bearing angle is not correct, except North=0

Hi ,
At first , I run the calibration.ino ont the GY-271(QMC5883L). and get the calibration data.
I copy its to bearing.ino.

And then I run the bearing.ino.
The North is 0 deg, NE=2 deg, E=4, SE=5, S=6, SW=7, W=4, NW=8.
Does it SW or HW issue??

=== bearing.ino ==
#include <QMC5883LCompass.h>
QMC5883LCompass compass;
void setup() {
Serial.begin(9600);
compass.init();
compass.setCalibrationOffsets(41.00, -159.00, -436.00);
compass.setCalibrationScales(1.09, 0.93, 0.99);
}
void loop() {
compass.read();

byte a = compass.getAzimuth();
// Output here will be a value from 0 - 15 based on the direction of the bearing / azimuth.
byte b = compass.getBearing(a);

Serial.print("B: ");
Serial.print(b);
Serial.println();

delay(250);
}

mgPerDigit

compared to other libraries (for HMC5883) not found the normalization function with respect to offset and gain, or am I doing something wrong?

GetAzimuth does not change with, and can not get my magnetic heading.

Hello, I am looking to build a prototype for an autopilot for a boat. I am using the knock off gy-271 and this library to get the magenetic heading of the boat, in degrees (for example heading 176 degrees) so that I can plug in my actual heading to the PID controller to steer towards my desired heading.

The problem I have is that every time I call compass.getAzimuth(), it returns a consitent value, no mater what direction I point the chip in. The value does change based on the calibration settings of the compass. For example, with this calibration: [[-19061,23237],[416,27639],[-3631,432]] the chip returns 280. I have tried to change the smoothing, mode and read the documenation, but I can not figure out what I am doing wrong. Here is the code I am writing: https://github.com/radding/Autopilot. Specifically, here is where I am setting up the compass: https://github.com/radding/Autopilot/blob/main/microcontroller/microcontroller.ino#L57.

I have the chip upright, and SDA is connected to PIN A4, and SCL is connected to pin A5 on my arduino uno. Any pointers would be appreciated!

error: narrowing conversion of '65000' from 'long int' to 'int'

When trying to compile using platformIO and lgt8f328p I get the following error:
.pio/libdeps/program_via_ArduinoISP/QMC5883LCompass/src/QMC5883LCompass.cpp:152:80: error: narrowing conversion of '65000' from 'long int' to 'int' inside { } [-Wnarrowing]

I changed line 152 of QMC5883LCompass.cpp from
int calibrationData[3][2] = {{65000, -65000}, {65000, -65000}, {65000, -65000}};
to
int calibrationData[3][2] = {{32767, -32768}, {32767, -32768}, {32767, -32768}};

and that solved the error and seemed to give the correct results in my test code. I haven't studied the code so I don't know if this is a viable solution.

Negative azimuth numbers make bearing and "NNW" ect not work.

The bearing calculation barfs on negative azimuth numbers, bearing code should be modified to:

byte QMC5883LCompass::getBearing(int azimuth){
unsigned long a = ( azimuth > -0.5 ) ? azimuth / 22.5 : (azimuth+360)/22.5;
unsigned long r = a - (int)a;
byte sexdec = 0;
sexdec = ( r >= .5 ) ? ceil(a) : floor(a);
return sexdec;

which produces the correct bearings of 0-15. Previously all W headings were clipped to 0 so only half the rose worked. The second line was my modification. Seems someone changed the bearings over 180' to negative numbers and caused this problem. It may be a difference in QMC5883 that I have too I suppose. Seems other folks online have had this issue. If I compared azimuth to 0, I got a 16 occasionally from the bearing, hence the -0.5' offset.

confusion between N and S

hello,
i am having funny error with the compass directions.
when turning on compass and calibrating it like the example shows sometimes i read N as S and others N as true N.
is there any reason for this behavior? and how can i fixed it ?
Thanks,

QMC5883 library to Attiny85

Since the wire.h library dont work with Attiny85, we need to use TinyWireM lib.
What do I need to change at QMC5883 library to wok with Attiny85?
Could you help me?
Thank you.

Need help with applying calibration data

I am trying to convert your QMC5883LCompass.cpp calibration code to run in a multi-threaded application on a Raspberry Pi. The problem I am having is the use of the calibration data.

To illustrate by way of an example - and I'll restrict it to the x axis for simplicity.

Let xMin = 102 and xMax = 108, this gives xOffset = 105, xDelta = 3 and xScale = 1.

Now assume that xRaw = 103. Therefore xRaw - xOffset = -2 and then xCalibrated = -2!!!!.

What have I misunderstood?

TIA,
Kevin Gilbert

The i2c scanner don’t find QMC5883LCompass and it don’t work on ESP32

Hi!
I used this code to find QMC5883L Compass, but don’t found.
The code compile on ESP32, but don’t show data.
What can I do to test it ?

`#include <Wire.h>

// Set I2C bus to use: Wire, Wire1, etc.
#define WIRE Wire

#define SDA 14 //3 // para teste 14
#define SCL 2 // para teste 2

void setup() {
Wire.begin(SDA, SCL);
//Wire.begin();

Serial.begin(9600);
while (!Serial)
delay(10);
Serial.println("\nI2C Scanner");
}

void loop() {
byte error, address;
int nDevices;

Serial.println("Scanning...");

nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
WIRE.beginTransmission(address);
error = WIRE.endTransmission();
Serial.print (" # ");
Serial.print (address);
if (error == 0)
{
Serial.print("\n I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");

  nDevices++;
}
else if (error==4) 
{
  Serial.print("Unknown error at address 0x");
  if (address<16) 
    Serial.print("0");
  Serial.println(address,HEX);
}    

}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");

delay(5000); // wait 5 seconds for next scan
}`

How to detect a car around the sensor

Hi.
This is not an issue, but an advice request or an example request.

Firstly, this library is quite awesome and I can make it work with the QMC5883L sensor, but I need an action that does not exist in any example, as I see. Maybe I'm wrong, cause I'm still new in the Arduino code world, so please excuse me if there is already there.

So, what I need is to be able to detect the presence of a car above the sensor.
I am working on an application that basically detects a car in front of the gate and triggers the gate to open, so the driver doesn't have to get out and open the gate. I am also new in the magnetometry field, but I researched a bit and it seems that you can detect the car by determining the change that it triggers in the magnetic field around the sensor.
Is there an example of that or can you possibly give some advice in that direction?
Thank you very much for your time and support!

Filtering the Influence of Surrounding Objects

Hi,

Thank you for writing this useful library.

When I am operating the compass, I noticed that the readings of the compass is vulnerable to surrounding objects. The readings are very different when I put the compass on my table and 30 centimeters above the table, while keeping the compass pointing to the same direction. Also, when I move the compass to different places (and the same height) on my table, the readings are also quite different.

I am already doing the calibration and reading smoothing. Do you think there is a way to filter out the influence of surrounding objects, and make the compass only respond to the magnetic field of the Earth?

Thank you for your assistance.

All the best,
HC

Wemos D1 Mini usage

Hey, i have this chip and would like to use it in combination with my wemos d1 mini, i used the pinout d1 -> scl d2 -> sda and 5v and gnd but i'm not getting any output at all except for 0's. any idea?

solving hangup of the sensor (in continuous mode)

sometimes the sensor hangs, resetting or init doesn´t solve the problem. There are 2 ways to solve the problem:

  1. powercycle the sensor
  2. modify the Data_Ready method as shown below

bool QMC5883LCompass::Data_Ready () {
Wire.beginTransmission ( _ADDR ) ;
Wire.write ( 0x06 ) ;
int err = Wire.endTransmission();
if (!err) {
Wire.requestFrom(_ADDR, (byte)1);
uint8_t Status = Wire.read() ;
if ( ( Status & 0x01 ) > 0 ) return true ;

// *********************************************************************
//SM: to prevent hangup, if skipbit DOR (0x04) is set
// youe to perform a read to get it working again (but data will be invalid)
if ( ( Status & 0x04 ) > 0 ) read() ;
// *********************************************************************

}
return false ;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.