I'm trying to create a "reaction wheel balancing cube" using an Arduino, IMU and dc motor.
I'm using an MPU6050 IMU through a GY-521 breakout board, powered directly from the 5V line on the arduino (a Smakn Beetle/Leonardo).
I have the basic wiring done. I've confirmed I can get a roll reading from the IMU, and then switch the speed and direction of the motor based on the roll reading.
However, I'm noticing that after about a minute, the MPU6050 begins sending back garbage and seemingly random readings. What could be causing this?
I only started noticing this problem when testing it with a running motor, so I suspect it's due to electrical noise from the motor, either:
distorting the i2c data
distorting the MEMS sensor in the chip
polluting the power going to the chip
I'm not sure what I can do about any of these. The cube is fairly small (100mm on each side, so it's difficult to electrically isolate everything. The motor and electronics are on opposite sides of the cube, to minimize interference.
I'm also running the motor off it's own power supply, so it's noise shouldn't be interfering with the Arduino or IMU's supply.
I've already added a 0.1uF capacitor across the motor's leads to reduce noise.
I read in a research paper for a similar project that the MPU6050 is very sensitive to a noisy 5V line, and the Arduino's power regulator isn't great. They claim to have solved it by placing a capacitor across the GY-521's power pins, but they didn't say what value. What would be a good capacitor value to use here?
jremington:
The MPU-6050 is a 3.3V device. If your particular module does not have level shifting circuitry on it (most of them do not), that is a problem.
Like my title and initial post description said, I'm using the GY-521 breakout board. It shifts logic levels to 5V.
Cerin, the CY-521 has a voltage regulator, but not a logic level shifter for the I2C bus.
Can you make a photo of ? I would like to see the value of the pullup resistors.
Can you show a schematic ? How is the motor connected ?
Can you show a photo of your whole project ?
It can be electric/inductive noise through air, but it is more likely current pulses through wires that influence other things. Current through GND wires can cause a lot of trouble. Good grounding is a real craftsmanship (that is probably not good English, but you get the idea).
Do you use a breadboard ? There are more and more problems each year on this forum with bad contacts of breadboards and broken jumper wires.
Idahowalker:
If the motor is not connected does the thing run for more than a minute?
Yes. It's even fine when the motor is turning under load. It's only when I remove the flywheel and the motor spins at full speed for about 10 seconds does the IMU begin returning random readings.
Cerin, the CY-521 has a voltage regulator, but not a logic level shifter for the I2C bus.
Can you make a photo of ? I would like to see the value of the pullup resistors.
That's interesting. You may be right that it's outputting 3V logic levels after all. However, I think that's fine since 3V qualifies as a logic High for the 5V Arduino, and the open-drain design of I2C means the Arduino never drives the pins to 5V itself. See Wiring a GY-521 to an Arduino Uno R3? - Electrical Engineering Stack Exchange
I'm not using any breadboards. Just wires going directly from the battery->Arduino->motor controller->motor.
You may be right that it's outputting 3V logic levels after all.
Koepel did not say or imply that.
I2C is an open drain bus that requires pullup resistors to establish a safe HIGH logic level. If the pullups are to 5V, that is a problem. I2C bus basics.
The best approach is to use a 3.3V processor with that sensor.
Manufacturer's page of the ATmega32U4: https://www.microchip.com/wwwproducts/en/ATmega32u4.
Open the "Complete Datasheet", go to page 387, and you see that VIH is 0.7VCC. That means the input should be at least 3.5V to be a valid high level for the I2C bus.
The Wire library enables the internal pullup resistors. They are 20kΩ to 50kΩ, see RPU at page 384. That is a high value, but enough to damage a sensor that uses almost no current (for example because it is in sleep mode).
The I2C bus is not a open-drain bus. Every microcontroller/processor/sensor has ESD protection diodes. That means a higher voltage at the SDA and SCL pins can lift the voltage of the VCC of a sensor and damage it.
Since the module has onboard pullup resistors to 3.3V, there will be a voltage divider between the internal pullup resistors of the ATmega32U4 and the onboard pullup resistors. So if you do the math, and carefully read the datasheets, then there might be a sweet spot that is barely within the specifications and might work for some time.
However, the I2C bus already troubles enough with its weak high level. If the voltage levels match, then it is less sensitive for noise on the bus. A I2C level shifter can solve the voltage level problem, but a I2C level shifter makes the signal also a little weaker.
Short version of this story: A 3.3V Arduino board is better as jremington wrote
Cerin:
Yes. It's even fine when the motor is turning under load. It's only when I remove the flywheel and the motor spins at full speed for about 10 seconds does the IMU begin returning random readings.
That the project works until subjected to a condition indicates that logic levels are not at fault. Will it be normal operations that the project will be running and at some random time the flywheel will be removed?
I am using the same sensor board on a promini and created some model aircraft gyros. I have to put a 1000 microFarad capacitor between the promini's VCC and GND, and I am feeding the 3.3v regulator of the sensor board from the promini VCC. If I omit the capacitor the sensor or promini will crash as soon as I start moving the servos in the airplane.
The promini's RAW pin is fed by the powersource in the plane that also powers the servo's and the receiver.
BTW I never had any problems mixing the 3.3 V sensors with 5V Arduino's. Apparently the pull up resistors on the 3.3V device are sufficient.
I admit, you may be right. According the datasheet I should get into trouble beyond 3.8 volt.
When the weird stuff starts to happen I will change the design. I use the gyro in combat planes, so maybe they never live long enough to suffer malfunctions that come from the inside.
If you refer to the Datasheet on page 20 you will see that the input pins namely SDA, SCL, and INTshould not get more voltage than VDD + 0.5v this means that the highest voltage that you can send to the MPU6050 module is 3.8v as the voltage regulator regulates the voltage to 3.3v your pull-ups alone are able to damage the pins on the MPU6050
Although connecting it directly to your Arduino Uno works sometimes you should consider putting a logic level converter in there to be on the safe side, Also it is seen as "good practice" to keep in mind all of the Maximum voltages of every component in your design and adjust the voltages accordingly
for breadboarding and hobby purpose I personally believe that the design of the MPU6050 modules are wrong and they should have a built-in logic level converter as it is very deceptive when reading all of the documentation on the modules, It always makes you believe that connecting a 5v MCU to the Module is fine but really it is not