Problem with robot project (motors)

Hi, I built a robot using RFRobot Pirate 4WD with Arduino UNO, a Redbear BLE Shield in the middle and an Adafruit Motorshield on top. I have seperate battery packs for Arduino + BLE Shield and the Motorshield. With an iPhone app I can control the Arduino - no problem. However, when I drive the wheels, the Bluetooth connection becomes very sensitive and will drop out after awhile. It happens quick if I drive the robot fast, but even at low speeds it usually drops out within a minute. I have soldered 3 capacitors to each motors to reduce noise, I think it helped a bit but not much.

Anything obvious I could be doing wrong here? Any tips on how to troubleshoot this/what to check for?

Quite frustrating, so thankful for any hints/ideas.

Thanks

Please supply your code in code tags. (</> icon), a link to the parts you are using and a circuit.

Weedpharma

phenrikand: a Redbear BLE Shield in the middle and an Adafruit Motorshield on top.

Would it work better with the BLE shield on top and further from possible interference?

...R

weedpharma:
Please supply your code in code tags. (</> icon), a link to the parts you are using and a circuit.

Weedpharma

Thanks, this is some more details.

Parts:

DFRobot: http://www.dfrobot.com/index.php?route=product/product&path=37_69&product_id=97#.VxdspJN95TZ

Arduino Uno

RedBearLab BLE Shield v2.1 http://redbearlab.com/bleshield/

Adafruit MotorShield v.2.3 ad https://www.adafruit.com/products/1438

Assembly:

Platform assembled according to https://programmingelectronics.com/assemble-dfrobot-pirate-4wd-mobile-platform/

BLE Shield stacked on top of Arduino, stackable headers on top of BLE Shield, Motorshield soldered on top. Power supply to Arduino either via printer cable to computer or 9V battery pack. Power to Motorshield via 5 AA battery holder (no jumper on the motor shield).

I soldered 3 0.1uF ceramic capacitors on each motor, according to:

Test1: Robot runs without problem when not using BLE control, only Arduino instructions for the DC motors.

Test2: Using the RedBear BLEControllerSketch BLEShield/Arduino/libraries/RBL_BLEShield/examples/BLEControllerSketch at master · RedBearLab/BLEShield · GitHub with BLEController found on the app store to control the motors.

Bluetooth connection is solid of not running the motors.

If running the motors, it disconnects after awhile, quicker if wheels are running faster.

Test3: Arduino code + iOS code on this page: How to build a wheeled robot and control it with your iPhone

Bluetooth connection is solid of not running the motors.

If running the motors, it disconnects after awhile, quicker if wheels are running faster.

Any ideas what could be going wrong here? Electrical brush noise from the motors? Anything I can do about that?

Many thanks.

Please post the code here to make it easy for people to help you.

It will also be a lot easier of you focus your questions on a single program.

...R

Robin2:
Please post the code here to make it easy for people to help you.

It will also be a lot easier of you focus your questions on a single program.

…R

Thanks, this is a test code. If I increase speed to above 40, the interference seems too much and Bluetooth disconnects. By connecting a LED I can see that I start getting signals from pins at high speeds (at around above 40).

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

Adafruit_DCMotor *myMotorBackL = AFMS.getMotor(1);
Adafruit_DCMotor *myMotorBackR = AFMS.getMotor(2);
Adafruit_DCMotor *myMotorFrontR = AFMS.getMotor(3);
Adafruit_DCMotor *myMotorFrontL = AFMS.getMotor(4);


//"RBL_nRF8001.h/spi.h/boards.h" is needed in every new project
#include <SPI.h>
#include <EEPROM.h>
#include <boards.h>
#include <RBL_nRF8001.h>


void setup() {

 Serial.begin(9600);
ble_begin();

 AFMS.begin(); 

 delay(100);

}

void loop() {

 
while (ble_available())


 {
  
   byte data = ble_read();


int leftWheelVelocity=40;
int rightWheelVelocity=40;

      
   if (data == 0x71)  // Command is to control digital out pin
   {
     myMotorBackL->setSpeed(leftWheelVelocity);
     myMotorFrontL->setSpeed(leftWheelVelocity);
     myMotorBackR->setSpeed(rightWheelVelocity);   
     myMotorFrontR->setSpeed(rightWheelVelocity);    
    myMotorBackL->run(FORWARD);
 myMotorBackR->run(FORWARD);
 myMotorFrontR->run(FORWARD);
 myMotorFrontL->run(FORWARD);
 
 
   }
 
   else if (data == 0x72)
   {
      myMotorBackL->setSpeed(leftWheelVelocity);
     myMotorFrontL->setSpeed(leftWheelVelocity);
     myMotorBackR->setSpeed(rightWheelVelocity);   
     myMotorFrontR->setSpeed(rightWheelVelocity);
 myMotorBackL->run(FORWARD);
 myMotorBackR->run(BACKWARD);
 myMotorFrontR->run(BACKWARD);
 myMotorFrontL->run(FORWARD);

   }
   else if (data == 0x73)
   {
       myMotorBackL->setSpeed(leftWheelVelocity);
     myMotorFrontL->setSpeed(leftWheelVelocity);
     myMotorBackR->setSpeed(rightWheelVelocity);   
     myMotorFrontR->setSpeed(rightWheelVelocity);
   myMotorBackL->run(BACKWARD);
 myMotorBackR->run(BACKWARD);
 myMotorFrontR->run(BACKWARD);
 myMotorFrontL->run(BACKWARD);


   }
   else if (data == 0x74)
   {
     myMotorBackL->setSpeed(leftWheelVelocity);
     myMotorFrontL->setSpeed(leftWheelVelocity);
     myMotorBackR->setSpeed(rightWheelVelocity);   
     myMotorFrontR->setSpeed(rightWheelVelocity);
  myMotorBackL->run(BACKWARD);
 myMotorBackR->run(FORWARD);
 myMotorFrontR->run(FORWARD);
 myMotorFrontL->run(BACKWARD);


 
   }
   else if (data == 0x75)
   {
       myMotorBackR->setSpeed(rightWheelVelocity);   
     myMotorFrontR->setSpeed(rightWheelVelocity);
     myMotorBackL->run(RELEASE);
 myMotorBackR->run(FORWARD);
 myMotorFrontR->run(FORWARD);
 myMotorFrontL->run(RELEASE);


   }
   else if (data == 0x76)
   {
           myMotorBackL->run(RELEASE);
 myMotorBackR->run(RELEASE);
 myMotorFrontR->run(RELEASE);
 myMotorFrontL->run(RELEASE);

   }
   else if (data == 0x77)
   {
           myMotorBackR->setSpeed(rightWheelVelocity);   
     myMotorFrontR->setSpeed(rightWheelVelocity);
     myMotorBackL->run(RELEASE);
 myMotorBackR->run(BACKWARD);
 myMotorFrontR->run(BACKWARD);
 myMotorFrontL->run(RELEASE);

   }
   else if (data == 0x78)
   {
       myMotorBackL->setSpeed(leftWheelVelocity);   
     myMotorFrontL->setSpeed(leftWheelVelocity);
   myMotorBackL->run(FORWARD);
 myMotorBackR->run(RELEASE);
 myMotorFrontR->run(RELEASE);
 myMotorFrontL->run(FORWARD); 

   }
   else if (data == 0x79)
   {
           myMotorBackL->setSpeed(leftWheelVelocity);   
     myMotorFrontL->setSpeed(leftWheelVelocity);
   myMotorBackL->run(BACKWARD);
 myMotorBackR->run(RELEASE);
 myMotorFrontR->run(RELEASE);
 myMotorFrontL->run(BACKWARD);
 
   }
  
 }
ble_do_events();

}

Please put your code in its own window as seen in other posts. This can be done by placing     [code]  and [/code]  around the code or use the </> icon. This makes it easier for others to read.

How to use this forum

You can edit the post above to put the tags before and after the code.

Weedpharma

weedpharma:
Please put your code in its own window as seen in other posts. This can be done by placing     [code]  and [/code]  around the code or use the </> icon. This makes it easier for others to read.

How to use this forum

You can edit the post above to put the tags before and after the code.

Weedpharma

Done, thanks

What does the ble_do_events(); do?

I don't understand the use of while (ble_available())

If it is functionally the same as while (Serial.available()) it is not a robust way to receive data and you should look at and adopt and adapt the examples in Serial Input Basics

You have lots of code like myMotorBackR->run(FORWARD); Wouldn't it be much simpler just to have one of each of these in loop() - certainly save a lot of typing.

...R

Robin2: What does the ble_do_events(); do?

I don't understand the use of while (ble_available())

If it is functionally the same as while (Serial.available()) it is not a robust way to receive data and you should look at and adopt and adapt the examples in Serial Input Basics

You have lots of code like myMotorBackR->run(FORWARD); Wouldn't it be much simpler just to have one of each of these in loop() - certainly save a lot of typing.

...R

ble_available() returns the the number of bytes ready for reading

ble_do_events() allows the BLE to process its events

I dont really understand how it can be a software issue since it is working perfectly when power to wheels are off and when running at low speeds.

The official RedBearLab examples use ble_available so I'm not sure why it wouldnt be the way to go.

phenrikand: I dont really understand how it can be a software issue since it is working perfectly when power to wheels are off and when running at low speeds.

I don't know either but it occurs to me that the Arduino may be much busier at higher speeds and can't keep up with everything.

Have you tried my hardware suggestion from Reply #2 ?

...R

Robin2:
I don’t know either but it occurs to me that the Arduino may be much busier at higher speeds and can’t keep up with everything.

Have you tried my hardware suggestion from Reply #2 ?

…R

I didn’t really understand Reply #2. I guess the possible interference is coming from the MotorShield, so you are suggesting having the MotorShield at the bottom with Arduino in the middle? Or do you mean to have the BLE Shield physically on the top ‘rack’ of the platform?

phenrikand: I didn't really understand Reply #2. I guess the possible interference is coming from the MotorShield, so you are suggesting having the MotorShield at the bottom with Arduino in the middle? Or do you mean to have the BLE Shield physically on the top 'rack' of the platform?

I mean having the BLE shield as far as possible from whatever might be causing wireless interference. Having it and its antenna hidden away in the middle of other metal and electric apparatus does not seem ideal.

...R

Robin2: I mean having the BLE shield as far as possible from whatever might be causing wireless interference. Having it and its antenna hidden away in the middle of other metal and electric apparatus does not seem ideal.

...R

Is the interference wireless (electromagnetic field from the motors?) or are we talking about wired interference causing the wireless shield (Bluetooth) shield act strangely? Anything else I can do about interference than to physically move the shield (it is soldered down, and I will probably not bother to move it). Thank you

phenrikand: Is the interference wireless (electromagnetic field from the motors?) or are we talking about wired interference causing the wireless shield (Bluetooth) shield act strangely?

That sounds like the sort of thing you should be telling us.

If it was my project I would experiment by moving things around.

...R