Hi, I’m having an incredible amount of difficulty getting two of these magnetometers connected properly to my Arduino. Please also be aware that this is my first Arduino project so I have been trying to stumble my way through all of this and read all the resources but I can’t see why I am having this problem.
It was a challenge a few weeks ago to get them to work independently but I eventually figured out that I would connect both by connecting one of the magnetometers to SDO pins to ground. Then the data they provided was really weird and somehow tied together. I then worked out that I could init() each magnetometer separately with a few second delays between them and remove the SDA connection from the other to ensure that the Arduino did not get mixed up between the two sensors. Hopefully, that makes sense. I guess the important bit, however, is that it worked perfectly. Both sensors giving individual data. It was brilliant.
Then this week, I soldered them onto my robot and for some reason, the second magnetometer now will not have its address changed through grounding the SDO pin. I have tried switching the SDO pin on the other as well. I have tried using an I2C scanner provided by Arduino to check the addresses and it seems that I am only ever getting the one address no matter what I do (before I used this to check the Arduino could identify two separate addresses for the two sensors and it worked perfectly). I really am at my wit’s end. I’ve read everything I can but my novice level of knowledge really prevents me from getting too technical.
Is there something that could have happened during the soldering process that could have wrecked the sensors ability to be grounded. I’ve checked the pins and soldering looks perfect so I don’t believe it is something we have done.
I can’t think of anything else. It couldn’t really be the software as I have not changed it since it was working.
I did, however, change the way I initialize them in an effort to get them to work by specifying the SA1 state but that does not seem to work either, now the 2nd magnetometer just fails to initialize.
I really hope someone can help me out with this. This project’s deadline is coming up soon and its really stressing me out.
Any advice is appreciated. Perhaps I am doing something completely wrong (though I did have it working perfectly before).
Please let me know if you need more information or would like to look at my code or something. I hope however this is a smaller issue than that. The code is simple and the wiring seems simple as well.
Thanks a lot!
Use the I2C interface, and on one magnetometer, wire the SA1 input high and on the other, low.
Then each of the two will respond to different I2C addresses. See the instructions on use of the LIS3MDL library to properly create the two instances of the compass. https://github.com/pololu/lis3mdl-arduino
You have picked a very challenging project for a beginner, so expect a steep learning curve.
Oh wow, I haven’t tried wiring the second magnetometer high yet. I will give it a go when I get home. I really hope it works. Thanks a lot.
By the way, I’m only doing this for my engineering course. It’s really not my choice.
Thanks heaps! I’ll let you know how I go
Ok actually I remembered I have this stuff with me so I tried it just now. It still doesn’t seem to work though. By using an i2c scanner provided by Arduino I checked the addresses because I use to be able to see the two different addresses at the same time. I can only see 1, and it is the address: 0x1E if that means anything to you.
I connected the SDO pin to ground and I connected the other SDO to my 5V (the same as the power for the sensors). It didn’t change anything. I tried inititialising my sensors while setting the SA1 setting to low and the other to high in the method but it only lets me initialise 1 and not the other.
I really can’t work out what is going on.
Maybe there is something I have to do. Perhaps reset them or something? So sorry for being a pain
SDO/SA1 is a 3.3V ONLY input, with no level shifter, and by connecting it to 5V, you may have destroyed the sensor. Most of us have done that at one time or another.
That pin already has a resistor connected to 3.3V on the module, so if you leave it open (unconnected), the default input state is high. Connect the pin to GND to set it low, in which case the sensor should respond to I2C address 1C.
Oh now I feel stupid. It seems like they are both still connecting though. The one I did that to seems to be getting pretty dodgy data now. I’m not really sure why it wasn’t working before I did that though, I’ve always had the other just connected to ground and this one left untouched.
I will just have to get another kind of magnetic sensor so I can avoid this confusion. Hopefully I can still achieve what I wanted like that. I’m still not sure why they just stopped working properly out of the blue. Anyway, thanks for you help Jim, I really appreciate it. You’ve cleared a few things up.
You should be able to get two good modules working independently as I described.
They aren’t that expensive, so throw the damaged one away and chalk it up to experience. Believe me, I have made similar mistakes many times, and I still do it from time to time.
In fact, just yesterday I accidentally swapped power and ground on a Real Time Clock module and the chip got hot enough to burn my thumb. Still seems to work, though!
Hi Jim, I just wanted to update you on my progress since you were so kind and helpful. I picked up a few new sensors and rigged them up the same as before (and as you described) and they are working perfectly now. We think we may have heated them up before when we attached pins to them which somehow wrecked their SDO functionality if you get what I mean.
Anyways, thanks so much for the tips and advice. I really appreciate it.