Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days.
0

Motor Shield V2 and Bluefruit LE
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Motor Shield V2 and Bluefruit LE

by aabate1203 on Mon May 22, 2017 11:19 pm

Hello, I am trying to build a project where I have an Arduino UNO, stacked on top of that is a Bluefruit LE shield, and then on the very top is a Motor Shield V2. The goal is to be able to use BLE in UART Mode to send data from an iPhone app to the Arduino to remotely control motors. I have the BLE connection from the iOS app working fine and can send data to the UNO. I also have the Motor Shield Sketch working fine (DC Motor 1) and can control the speed of the motor.

The problem I run into is doing them both at once. I make the BLE connection (blue LED turns on) but when I send a MOTOR(RELEASE) or MOTOR(FORWARD) from the Sketch, the BLE connection disconnects.

I looked through the pinouts and cannot see an obvious conflict. Can anyone tell me what may be happening and thoughts on how to correct it?

Thanks!
Anthony

aabate1203
 
Posts: 14
Joined: Fri Jan 02, 2015 3:58 pm

Re: Motor Shield V2 and Bluefruit LE

by adafruit_support_bill on Tue May 23, 2017 6:08 am

DC motors are electrically very noisy and that noise can disrupt other circuitry. You might try adding some capacitors to the motors to suppress some of that noise at the source. https://learn.adafruit.com/adafruit-mot ... all#faq-17

adafruit_support_bill
 
Posts: 82893
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 and Bluefruit LE

by aabate1203 on Tue May 23, 2017 9:38 am

This is not a motor noise issue. It happens even if a motor is not physically connected to the shield. It is a direct result of the motor.run(release) or motor,run(forward) command.

aabate1203
 
Posts: 14
Joined: Fri Jan 02, 2015 3:58 pm

Re: Motor Shield V2 and Bluefruit LE

by adafruit_support_bill on Tue May 23, 2017 9:43 am

There should not be any pin conflicts. The motor shield communicates entirely via i2c. The BLE shield communicates via SPI. These use completely separate pins on the UNO.

If you post photos showing the fronts and backs of both shields we can look for any assembly issues.

Also please post the code you are using.

adafruit_support_bill
 
Posts: 82893
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 and Bluefruit LE

by aabate1203 on Tue May 23, 2017 12:09 pm

Attached are the requested photos. I believe the assembly is clean, but certainly let me know if you see anything wrong. The point of the project is that the iOS app sends a number from 0 through 255 to the UNO via the BLE UArt. The UNO then sets that number as the motor's speed.

Here is the sketch code:

Code: Select all | TOGGLE FULL SIZE
#include <AFMotor.h>
#include <SPI.h>
#include <SoftwareSerial.h>

#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"

// COMMON SETTINGS
// ----------------------------------------------------------------------------------------------
// These settings are used in both SW UART, HW UART and SPI mode
// ----------------------------------------------------------------------------------------------
#define BUFSIZE                        128   // Size of the read buffer for incoming data
#define VERBOSE_MODE                   true  // If set to 'true' enables debug output
#define BLE_READPACKET_TIMEOUT         500   // Timeout in ms waiting to read a response


// SOFTWARE UART SETTINGS
// ----------------------------------------------------------------------------------------------
// The following macros declare the pins that will be used for 'SW' serial.
// You should use this option if you are connecting the UART Friend to an UNO
// ----------------------------------------------------------------------------------------------
#define BLUEFRUIT_SWUART_RXD_PIN       9    // Required for software serial!
#define BLUEFRUIT_SWUART_TXD_PIN       10   // Required for software serial!
#define BLUEFRUIT_UART_CTS_PIN         11   // Required for software serial!
#define BLUEFRUIT_UART_RTS_PIN         -1   // Optional, set to -1 if unused


// HARDWARE UART SETTINGS
// ----------------------------------------------------------------------------------------------
// The following macros declare the HW serial port you are using. Uncomment
// this line if you are connecting the BLE to Leonardo/Micro or Flora
// ----------------------------------------------------------------------------------------------
#ifdef Serial1    // this makes it not complain on compilation if there's no Serial1
  #define BLUEFRUIT_HWSERIAL_NAME      Serial1
#endif


// SHARED UART SETTINGS
// ----------------------------------------------------------------------------------------------
// The following sets the optional Mode pin, its recommended but not required
// ----------------------------------------------------------------------------------------------
#define BLUEFRUIT_UART_MODE_PIN        12    // Set to -1 if unused


// SHARED SPI SETTINGS
// ----------------------------------------------------------------------------------------------
// The following macros declare the pins to use for HW and SW SPI communication.
// SCK, MISO and MOSI should be connected to the HW SPI pins on the Uno when
// using HW SPI.  This should be used with nRF51822 based Bluefruit LE modules
// that use SPI (Bluefruit LE SPI Friend).
// ----------------------------------------------------------------------------------------------
#define BLUEFRUIT_SPI_CS               8
#define BLUEFRUIT_SPI_IRQ              7
#define BLUEFRUIT_SPI_RST              4    // Optional but recommended, set to -1 if unused

// SOFTWARE SPI SETTINGS
// ----------------------------------------------------------------------------------------------
// The following macros declare the pins to use for SW SPI communication.
// This should be used with nRF51822 based Bluefruit LE modules that use SPI
// (Bluefruit LE SPI Friend).
// ----------------------------------------------------------------------------------------------
#define BLUEFRUIT_SPI_SCK              13
#define BLUEFRUIT_SPI_MISO             12
#define BLUEFRUIT_SPI_MOSI             11

#define FACTORYRESET_ENABLE         1
#define MINIMUM_FIRMWARE_VERSION    "0.6.6"
#define MODE_LED_BEHAVIOUR          "MODE"

#define PACKET_ACC_LEN                  (15)
#define PACKET_GYRO_LEN                 (15)
#define PACKET_MAG_LEN                  (15)
#define PACKET_QUAT_LEN                 (19)
#define PACKET_BUTTON_LEN               (5)
#define PACKET_COLOR_LEN                (6)
#define PACKET_LOCATION_LEN             (15)

//    READ_BUFSIZE            Size of the read buffer for incoming packets
#define READ_BUFSIZE                    (20)

//-----------------------------------------------------------

int speed = 0;

AF_DCMotor motor(1);
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

// BLE Packet Buffer
uint8_t packetbuffer[READ_BUFSIZE];

void setup()
{
  // initialize serial communication at 57600 bits per second:
  Serial.begin(57600);

  // Initialize the motor controller
  motor.setSpeed(0);     // Begin with motor stopped
  motor.run(RELEASE);
 
  // Initialize the BLE Module
  initBLE();
}

// the loop routine runs over and over again forever:
void loop()
{
  /* Wait for new data to arrive */
  if (ble.available())
  {
    speed = ble.read();   // desired speed is in the first byte of the message
   
    while (ble.available())
    {
      ble.read();  // clear out unused message bytes
    }
   
    Serial.print("New Speed: ");
    Serial.println(speed);
   
    if (speed == 0)
    {
      motor.run(RELEASE);    // AS SOON AS EITHER OF THESE COMMANDS IS EXECUTED
    }                                        // THE BLE CONNECTION DISCONNECTS
    else
    {
      motor.run(FORWARD);
    }

    motor.setSpeed(speed);
  }
}

void initBLE()
{
  /* Initialise the module */
  Serial.print(F("Initialising the Bluefruit LE module: "));

  if ( !ble.begin(VERBOSE_MODE) )
  {
    Serial.println(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
    return;
  }
 
  Serial.println( F("OK!") );

  if ( FACTORYRESET_ENABLE )
  {
    /* Perform a factory reset to make sure everything is in a known state */
    Serial.println(F("Performing a factory reset: "));
    if ( ! ble.factoryReset() )
    {
      Serial.println(F("Couldn't factory reset"));
      return;
    }
  }

  /* Disable command echo from Bluefruit */
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");

  ble.info();
  ble.verbose(false);  // debug info is a little annoying after this point!

  /* Wait for connection */
  while (! ble.isConnected())
  {
      delay(500);
  }

  Serial.println(F("******************************"));

  // LED Activity command is only supported from 0.6.6
  if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )
  {
    // Change Mode LED Activity
    Serial.println(F("Change LED activity to " MODE_LED_BEHAVIOUR));
    ble.sendCommandCheckOK("AT+HWModeLED=" MODE_LED_BEHAVIOUR);
  }

  // Set Bluefruit to DATA mode
  Serial.println( F("Switching to DATA mode!") );
  ble.setMode(BLUEFRUIT_MODE_DATA);

  Serial.println(F("BLE Ready!")); 
}
Last edited by adafruit_support_bill on Tue May 23, 2017 1:18 pm, edited 1 time in total.
Reason: Please use [code] tags when submitting code to the forums

aabate1203
 
Posts: 14
Joined: Fri Jan 02, 2015 3:58 pm

Re: Motor Shield V2 and Bluefruit LE

by adafruit_support_bill on Tue May 23, 2017 1:21 pm

Code: Select all | TOGGLE FULL SIZE
#include <AFMotor.h>


AFMotor.h is an obsolete library for the discontinued V1 motor shield. You need to use the V2 library linked in the guide for the V2 shield:
https://learn.adafruit.com/adafruit-mot ... l-software

adafruit_support_bill
 
Posts: 82893
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 and Bluefruit LE

by aabate1203 on Tue May 23, 2017 1:37 pm

Hi again, sorry I gave bad information. Upon further inspection I actually have a V1 motor shield.

Sorry again for the confusion!

aabate1203
 
Posts: 14
Joined: Fri Jan 02, 2015 3:58 pm

Re: Motor Shield V2 and Bluefruit LE

by adafruit_support_bill on Tue May 23, 2017 1:52 pm

The V1 shield will be a problem. It has pin conflicts with the SPI on the UNO.

adafruit_support_bill
 
Posts: 82893
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 and Bluefruit LE

by aabate1203 on Tue May 23, 2017 4:36 pm

Aha! That makes sense now. Is there any way I can rework the board to resolve the conflicts or so i need a V2? I'm pretty good at electronics so is there a way to rework the V1 board to be compatible with the V2 library for example?

aabate1203
 
Posts: 14
Joined: Fri Jan 02, 2015 3:58 pm

Re: Motor Shield V2 and Bluefruit LE

by adafruit_support_bill on Tue May 23, 2017 4:46 pm

You would have to re-route the pins that conflict with hardware SPI. Pin 11 (MOSI) is used for PWM speed control of Motor 1 and Pin 12 (MISO) is used for controlling the shift-register that drives the H-bridges. Since the PWM logic involves Arduino timers which are specific to those pins, this would involve substantial modifications to the AFMotor library as well.

adafruit_support_bill
 
Posts: 82893
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 and Bluefruit LE

by aabate1203 on Tue May 23, 2017 6:03 pm

If i use motor 2 or 3 or 4 instead of motor 1, would that relieve the issue with the pwm control on pin 11? If so, that would just leave the conflict with pin 12. Is that as significant a change to the library?

Or, is there a way to modify the pin layout to just work with the new v2 library?

aabate1203
 
Posts: 14
Joined: Fri Jan 02, 2015 3:58 pm

Re: Motor Shield V2 and Bluefruit LE

by adafruit_support_bill on Tue May 23, 2017 8:28 pm

Avoiding motor1 and pin 11 would probably simplify things quite a bit. Rewiring to replace pin 12 would be a easier change to deal with in the library.

The V2 control architecture is entirely different, so there is no commonality at all between the libraries.

adafruit_support_bill
 
Posts: 82893
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 and Bluefruit LE

by aabate1203 on Tue May 23, 2017 9:35 pm

Thanks for all your help. I'll give it a try

aabate1203
 
Posts: 14
Joined: Fri Jan 02, 2015 3:58 pm

Re: Motor Shield V2 and Bluefruit LE

by aabate1203 on Thu May 25, 2017 11:02 am

Just to close the loop, I rewired the Motor Shield V1 to use pin A3 instead of pin 12 to control the latch. I updated the AFMotor library to reflect that pin change as well as comment out any use of pin 11 (basically made M1 defunct). I moved my motor to M2 and all is working exactly as expected now.

Thank you for your assistance!
Anthony

aabate1203
 
Posts: 14
Joined: Fri Jan 02, 2015 3:58 pm

Re: Motor Shield V2 and Bluefruit LE

by adafruit_support_bill on Thu May 25, 2017 11:57 am

Good to hear. Thanks for the follow-up.

adafruit_support_bill
 
Posts: 82893
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.