Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Crashes?? #8

Closed
elitewill1200 opened this issue Jul 16, 2018 · 13 comments
Closed

Random Crashes?? #8

elitewill1200 opened this issue Jul 16, 2018 · 13 comments

Comments

@elitewill1200
Copy link

Hello,

I am unsure why this is happening, but the example seems to crash at random times and hang the Arduino. This is repeatable on both the QMC588L's I have. Any idea why?

-Will

@dthain
Copy link
Owner

dthain commented Jul 16, 2018

Hard to say, I haven't seen this behavior.
What's your hardware setup?

@elitewill1200
Copy link
Author

I am using an Ardunio UNO hooked up to Sparkfun's GPS Mouse that has one of these onboard (although their documentation doesn't say how to interface with it, it's there and on the SCL and SDA lines).

@dthain
Copy link
Owner

dthain commented Jul 17, 2018

Just for comparison, I have been using this code for on an Arduino Nano, Ardunio Mega, and Teensy-2.0 on a soldered circuit board with a short (centimeters) I2C bus with three devices (BMP-180, MPU-6050, QMC5883L), and haven't observed any hanging problems.

For reference, I assume you are using this, right?
https://cdn.sparkfun.com/assets/learn_tutorials/5/7/1/GPM-808G--UAV_GNSS_receiver_ublox8030_QMC5883.pdf

It possible there is a problem in the QMC5883L driver. As a first debugging step, I would suggest adjusting your sketch to use readRaw() and print out the raw compass values instead of the calibrated values. If that runs stably for a long time, then it means there is some problem in the calibrated readHeading().

It's also possible there is a problem in the hardware. From the picture in the datasheet, I am somewhat concerned about the length of the leads: I2C isn't really designed to be used as an off-board connection, although it can work sometimes. You may also need to add (or adjust or remove) the termination resistors on the bus: some devices have them built in, and some don't. Sometimes the termination needs to be adjusted depending on the bus voltage.

And, just to eliminate all the possibilities, you might just try some other simple long running sketch (e.g. just print out the time once per second) and see if the board crashes. If that's the case, then you have some other underlying issue.

Hope that helps, let me know what you find.

@elitewill1200
Copy link
Author

I did some digging and it turns out I was using 5 volt logic to the chip, however it was being powered with 3.3v. Now that I added a level shifter, the chip wont even init which is annoying. I am a little over my head here

@dthain
Copy link
Owner

dthain commented Jul 18, 2018

This seems to be a pretty common arrangement -- the chip runs at 3.3v, but the board has a regulator (and sometimes) a level shifter for the signals, so it appears as a 5V device externally.

@AugustineSena
Copy link

Yeah, I have same problem. For my case, i'm using Arduino Mega 2650 R3, I put directly SCL and SDA (that two without number - close to ICSP port). It works for me.
Arduino-MEGA-pinout

@dthain
Copy link
Owner

dthain commented Jun 25, 2019

Let's try to narrow down the source of the crash by eliminating some code.
This sketch just reads and prints the raw values, without calibrating.
If you run this, does it still crash?

#include <QMC5883L.h>
#include <Wire.h>

QMC5883L compass;

void setup()
{
        Wire.begin();
	compass.init();
	compass.setSamplingRate(50);

	Serial.println("QMC5883L Compass Demo");
	Serial.println("Turn compass in all directions to calibrate....");
}

void loop()
{
    int16_t x, y, z, t;
		compass.readRaw(&x,&y,&z,&t);
    Serial.print(x);
    Serial.print(" ");
    Serial.print(y);
    Serial.print(" ");
    Serial.print(z);
    Serial.print("\n");
}

@turnimator
Copy link

The code above still crashes on my Wemos Mega after about 20 values have been printed.

@turnimator
Copy link

turnimator commented Apr 11, 2020

I moved the QMC5883L closer to the SCL,SDA pins on the Wemos Mega.
Now, it appears to run like a dream.
The funny thing is, I didn't shorten the cable.
I'm a programmer, not an electronics engineer, so I'll just write that up as 'Spooky Hardware At A Distance'.

@Seabrand
Copy link

Seabrand commented Apr 11, 2020

😀I like spooky hardware, but for an engineer this smells like drawing current from an internal pull resistor. Are you sure nothing is shortning, or an LED perhaps?

@turnimator
Copy link

turnimator commented Apr 11, 2020

I swear by my mother's cold, dark grave. With the cable attached, I moved the sensor closer to the board. Values are still ticking out. I can move it, I can shake it, I can rattle it.
Before I moved it, it would barely print 20 values before locking up.
It's probably something with picoFarads, but to me, it's magic.
Or microHenries? The cable was straight, now it's arced.
The sensor was at the other side of an L298N motor driver board, but I ran the Wemos Mega off the USB, so the L298N should be powered down.
Others have had similar experiences in the distant past:
http://www.catb.org/~esr/jargon/html/magic-story.html

@dthain
Copy link
Owner

dthain commented May 4, 2020

Ok, I think we have established that it's a hardware problem.
I2C was really designed as an on-board communication mechanism.
It can be carried by wires off-board, but they have to be kept very
short, otherwise strange things can happen...

@Seabrand
Copy link

Seabrand commented May 4, 2020

Ok, I think we have established that it's a hardware problem.
I2C was really designed as an on-board communication mechanism.
It can be carried by wires off-board, but they have to be kept very
short, otherwise strange things can happen...

Are you sure you are using the right pullup resistors on both the SDA&SCL pins? See https://en.m.wikipedia.org/wiki/I%C2%B2C, physical layer: measure the line capacitance C and pick a high resistance R allowing a bitrate up to 1/RC

@dthain dthain closed this as completed Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants