Open j980m842 opened 4 years ago
questions:
Hey Ted
Here is the full code I'm using:
MLX90393 mlx; MLX90393::txyz data; //Create a structure, called data, of four floats (t, x, y, and z)
int GAIN = 7; int RES_X = 0; int RES_Y = 0; int RES_Z = 0; int OSR = 2; int DIG_FILT = 7;
void setup() { Serial.begin(9600); Wire.begin();
byte status = mlx.begin(); //iic jumpers set Serial.println(status);
Serial.print("Start status: 0x"); if(status < 0x10) Serial.print("0"); Serial.println(status, BIN);
mlx.setGainSel(GAIN); mlx.setResolution(RES_X, RES_Y, RES_Z); //x, y, z mlx.setOverSampling(OSR); mlx.setDigitalFiltering(DIG_FILT); }
void loop() { mlx.readData(data); //Serial.println("channel1: "); Serial.println(String(millis())+ ","+ data.x+","+data.y+","+data.z); delay(2); }
You can see in the loop there that the serial.println line is commented out which allows the code to work. If I uncomment that it will not work.
I can't reproduce your example exactly here, because the code you supplied doesn't compile -- there's an error on the Serial.println(String(millis()...
However, I was able to see the code fail if I fixed that error and pulled an older version of the code. I believe this error was fixed by 4b044b532be969a4464e58fa488459d97248596d. If I use the code after that fix, I have not been able to reproduce your error.
Please pull the latest and try your code again.
Hello,
I am using an Arduino Uno (IDE version 1.8.12) with an MLX90393 magnetometer. My issue is that I can read from the magnetometer just fine if pretty much ONLY do the readData command and print it such as shown below:
void loop() { mlx.readData(data); Serial.println(String(millis())+ ","+ data.x+","+data.y+","+data.z); delay(500); }
However, If I add other things to the void loop such as also serial printing the channel I am reading from like this:
void loop() { mlx.readData(data); Serial.println("channel1: "); Serial.println(String(millis())+ ","+ data.x+","+data.y+","+data.z); delay(500); }
It not longer reads my data and I get something like "0.75, 0.75, 1.58" for my three data points each time it samples and the values don't change if I wave a magnet over the magnetometer so I know it isn't actually reading anything. This is just an example, there are a host of other strange things that seem to keep the magnetometers from reading when they are compiled on the board. Also, I have noticed that every time I start the serial monitor, the first data point I get is a nonsense data point such as "0.75, 0.75, 1.58" and then after that it begins giving me accurate X, Y, Z values. As an addition, I am also trying to read several MLX90393s using a TCA9548 and I'm having similar problems when using that because even changing the channel to read from will keep all of the magnetometers from reading data and again they just give nonsense numbers. Any suggestions what could be causing this?