I am putting together a small arduino-controlled boat project. I have been struggling with a problem for a few months (!) now. The whole thing 'freezes', more or less regularly, when I start motor control in PWM. I ran a small debug session and found out that is the digital compass (LSM303) giving me trouble. it gets stuck while retrieving compass data. Again, this only happens while i run the motors. no problem when motors are off.
After spending a lot of time trying to troubleshoot this, I went and borrowed an old oscilloscope to see what was going on. I am connected to the LSM303 (whose breakout board, I understand, has a built-in logic level converter) directly from my 5V Arduino Mega 2560 board. Analyzing the SDA/SCL signals, SCL looks fine (nice square waves at the right levels 0-5V), but SDA looks a bit scary, as you can see in the image: Please note that here the motors are off. I was simply running the sample sketch to retrieve continuosly data from the compass. The high levels have all those ripples that I was not expecting. This scope is very old and has some issues. the selection is supposed to be .2V per div while in the end it is like 2V per div. So it is a big ripple.
- Now, is this an OK I2C data signal? (this is my main question, but if you want you can read further and help me troubleshooting the damn thing)
When the motors are on, the PWM dirtens the power supply quite a bit, like in the following image, that shows 7.2V unregulated and 5V regulated power supply (used to power arduino and all logic electronics):
so I thought that this ripple, on top of the dirty I2c signal, kills communication between compass and arduino.
so I went ahead and used a separate battery for supplying power to the arduino Mega, compass, gps, etc.., while the original battery gives power to the motors only. the result is as follows:
(this is the 'logic' battery, unregulated and regulated). not perfect, but much better. But still hangs in the tests. Damn! I thought I figured it out... So, desperate and clueless.
What do you guys think? Thanks, Andrea