Author Topic: Motors interference for I2C in balancing robot  (Read 7070 times)

hubert9999

  • Newbie
  • *
  • Posts: 9
    • View Profile
Motors interference for I2C in balancing robot
« on: July 15, 2014, 01:54:57 AM »
Hi.
I'm trying to make self-balancing robot just something like Balanduino. I use Arduino, Pololu motor shield, and Pololu DC motors with encoders. Something like that:
 http://www.pololu.com/product/1442

Unfortunately, they generate a noise which breaks the communication between MPU-6050 and Arduino. I use a Kalman filter library from Balanduino project and it works pretty well until I push a robot quite strongly  for instance. When it tries to stay balanced in such situation and motors rotations become faster it stops working. When I use Serial Monitor at such moment I see errors: "i2cRead timeout" or "i2cRead failed: 2" or just it stops displaying new values without any error- it freezes and it has to be restarted.  I think the reason are motors because when I turn them off there aren't any problems with sensor. I2C freezes usually when the robot is shakeing - when motors are changing direction of rotation rapidly. Arduino and shield are supplied from USB, but the power supply for motors(12V) is delivered separately from battery pack. So the problem exist despite the fact that uC and MPU-6050 are supplied from another power source than motors. My first thought was that there must be some noise which is induced by motors and it affects  3V3 line which is used by MPU-6050.  I tried some methods of dealing with this issue like soldering 0,1 uF capacitors between terminals of motors. I also tried to solder capacitor between each terminal and case of the motor but none of these methods helped. Then I connected 10k and then 2k2 pull-ups to SDA and SCL ports, twisted cables which connect motor driver and motors (high current), but my problem still exist. I cannot go ahead with my project because robot is balancing when it stands steady on the ground but when it is pushed and tries to keep balance by doing quick move it immediately stops working and it must be restarted. Now it can do only very slight moves (when the current is low). I wanted to add a feedback from encoders to enhance the ability to balance but when I did it, robot bacame more "nervous" so it was very hard to keep it working for longer than few seconds.  I'm even thinking of replacing MPU-6050 with some analog sensor, because propably motors wouldn't affect analog readings.
For now I'd rather stay with my MPU-6050. Does anyone know how to deal with this problem?  Maybe somebody had similar... I noticed that the motors used in Balanduino are nearly identical or maybe even the same. I wonder why this problem doesn't exist in Balanduino and it does in my robot. The hardware is almost the same, software too. I also haven't noticed any special wires in Balanduino like shielded cables etc. For this moment I have no idea what am I doing wrong :(
I would be very grateful for any help.
« Last Edit: July 15, 2014, 02:04:11 AM by hubert9999 »

Lauszus

  • Administrator
  • Full Member
  • *****
  • Posts: 131
    • View Profile
Re: Motors interference for I2C in balancing robot
« Reply #1 on: July 16, 2014, 03:45:13 AM »
Hi,

Have you tried to shorten the SCL and SDA wires?

Also try to lower the I2C frequency to 100kHz by replacing:
Code: [Select]
TWBR = ((F_CPU / 400000L) - 16) / 2; // Set I2C frequency to 400kHz
With:
Code: [Select]
TWBR = ((F_CPU / 100000L) - 16) / 2; // Set I2C frequency to 100kHz
It is located at the following line: https://github.com/TKJElectronics/Balanduino/blob/master/Firmware/Balanduino/Balanduino.ino#L209.

Regards
Lauszus

hubert9999

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Motors interference for I2C in balancing robot
« Reply #2 on: July 16, 2014, 12:17:46 PM »
Thank you a lot !

Didn't have to change frequency. I just eliminated SDA and SCL wires and plugged a chip with MPU-6050 directly into Arduino and it works without any problems. Thanks to you this issue is solved :)

Lauszus

  • Administrator
  • Full Member
  • *****
  • Posts: 131
    • View Profile
Re: Motors interference for I2C in balancing robot
« Reply #3 on: July 17, 2014, 07:54:27 AM »
Okay super! :) I'm happy I could help!

Regards
Lauszus

Jimmy

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Motors interference for I2C in balancing robot
« Reply #4 on: July 22, 2014, 05:18:48 AM »
@Hubert9999, Can you show your creation in a video? Love to see it!

hubert9999

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Motors interference for I2C in balancing robot
« Reply #5 on: July 28, 2014, 11:04:01 PM »
Haven't recorded a video yet and I cannot do it now, because I discharged my battery and I haven't got a charger. I will have it in few days. When it comes I will post a video :)