I am using the MMC5983MA magnetometer for a rocket computer brain. We have a flight friday morning and need to have it giving proper outputs. Initially I had problems with it, but the other day I uploaded the following code and it magically started working. Fast forward to today, I soldered on a few other components to out protoboard and it suddenly stops working. It will give one angle constantly with a little bit of noise. The weird thing is that it is still showing up on the i2c scanner. If more info is required for good debugging I am happy to provide it.
#include <Wire.h>
#include <SparkFun_MMC5983MA_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_MMC5983MA
SFE_MMC5983MA myMag;
void setup()
{
Serial.begin(115200);
Serial.println("MMC5983MA Example (Z-Axis Based)");
Wire.begin();
if (myMag.begin() == false)
{
Serial.println("MMC5983MA did not respond - check your wiring. Freezing.");
while (true)
;
}
myMag.softReset();
Serial.println("MMC5983MA connected");
}
void loop()
{
uint32_t rawValueX = 0;
uint32_t rawValueY = 0;
uint32_t rawValueZ = 0;
double scaledX = 0;
double scaledY = 0;
double scaledZ = 0;
double heading = 0;
// Read all three channels simultaneously
myMag.getMeasurementXYZ(&rawValueX, &rawValueY, &rawValueZ);
// Scale the raw values to +/- 1.0
scaledX = (double)rawValueX - 131072.0;
scaledX /= 131072.0;
scaledY = (double)rawValueY - 131072.0;
scaledY /= 131072.0;
scaledZ = (double)rawValueZ - 131072.0;
scaledZ /= 131072.0;
// Magnetic north is now oriented with the Z axis
// Convert the Z and X fields into heading using atan2
heading = atan2(scaledX, scaledZ);
// atan2 returns a value between +PI and -PI
// Convert to degrees
heading /= PI;
heading *= 180;
heading += 180;
Serial.print("Heading:");
Serial.println(heading, 1);
delay(100);
}
So the problem is not the code. It is what you did to the hardware.
So can you post a schematic of what you have along with some photographs so we can verify if there is anything wrong with the soldering?
I can, but it is the least organized jumble of wires. I can confirm however that the only difference that would be of issue to my knowledge is the addition of another device on the I2C line. These are the connections I followed when soldering the board together.
- Magnetometer 0x30
- SCL - SCL
- SDA - SDA
- 3.3v - VDD
- GND - GND
- Barometer 0x77
- 3.3v - VCC
- GND - GND
- SCL - SCL
- SDA - SDA
- (Needs to be connected directly to SDA SCL lines. Most likely a weak signal and cannot reach further)
- Accelerometer 0x18
- SCL - SCL
- SDA - SDA
- 3.3v - 3.3v
- GND - GND
- CS - 3.3v
- SA0 - GND
- 16G IMU 0x6B
- SCL - SCL
- SDA - SDA
- 3.3v - VCC
- GND - GND
- GPS 0x42
- 3.3v - 3.3v
- GND - GND
- SCL - SCL
- SDA - SDA
- Flash Chip
- 3.3v - 3V
- GND - G
- (M) 10 - CS
- (L) 11 - IO0
- (K) 12 - IO1
- (K other side) 13 - CLK
I do not have a schematic for this. But I have a 10k pull up resistor on both SDA and SCL lines. I have, like I said before, have communication between all sensors with an i2c scanner. As for the scoped signals, I only have a very cheap oscilloscope, so I did my best to get signal image for you, but this is the best I could do.
Unfortunately I dont have those resistors on hand, but when I get a chance I will try them. If I may ask though, would you know why it was working before? Are you thinking it was because of the added I2C line and the resistance was too much??
I never cease to be amazed at the number of people who think they can make anything without a schematic.
You certainly can't communicate with anyone about what you have made without one. It is the universal language of electronics.
1 Like
Ok. Could it at all be the fault of a faulty sensor? Because I was having trouble even when it was a standalone device, and then one day without changing anything on a breadboard it started working again.
As I was responding to this I got it to work again. I unplugged and plugged it back in again for the 100th time and it just magically just started working again. No change to hardware. No change to software. Hope this helps with figuring out the cause. I'm leaning to a weird sensor and might just not use this one in the future.