0

exchanging data between Arduino and Bluefruit LE SPI Friend
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

exchanging data between Arduino and Bluefruit LE SPI Friend

by Zant67 on Sat Aug 03, 2019 2:24 am

Hello every one !

As I am a newbie, I present myself briefly:

I am a French teacher, teaching engineering sciences to students aged 15 to 19 years old.

Currently, I am working on a project that aims at controlling a servo-motor with a vocal command on a smartphone. For this project, I use an Arduino UNO with a BlueFruit LE SPI Friend and a smartphone on Android. I program the smartphone with MIT App Inventor.

I have found tutorials that have achieved me to connect the BlueFruit LE SPI Friend to App Inventor and I manage to read the UUID Services and Characteristics of the BlueFruit. So I suppose that the connection is functional.

Now, I am trying to exchange a string from Arduino to the smartphone. And I don't manage to. And I don't understand why.

I have read different posts on this forum but I don't find my mistake. I think it's on my arduino code since when I try the function "ble.isConnected()" the answer is "No". However, App Inventor says "Yes".

If anyone could take the time to read my codes, this would be very useful to me and I would appreciate it.

Hope reading you soon, thank you ! Zant67

Code: Select all | TOGGLE FULL SIZE

#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"

// SETTINGS

// Define the parameters for a hardware SPI
#define BLUEFRUIT_SPI_CS               8
#define BLUEFRUIT_SPI_IRQ              7
#define BLUEFRUIT_SPI_RST              4

#define VERBOSE_MODE                   true  // If set to 'true' enables debug output (mais ça surcharge la communication)


#define FACTORYRESET_ENABLE      1


// Create the bluefruit object, for hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);


// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}

  //  @brief  Sets up the HW an the BLE module (this function is called automatically on startup)

void setup(void)
{
  delay(500);

  Serial.begin(115200);
 
  // Initialise the module
  Serial.print(F("Initialising the Bluefruit LE module: "));

  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  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() ){
      error(F("Couldn't factory reset"));
    }
  }

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

  Serial.println("Requesting Bluefruit info:");
  // Print Bluefruit information
  ble.info();

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

}

void loop(void)
{
      // Test if the bluefruit is connected and send the status on the monitor
      if (!ble.isConnected()){Serial.println("not connected");
      delay(1000);
      }
      else {Serial.println("OK, connected");
      delay(1000);}

      // Send "Hello from Monserrat" to the phone
      ble.print("BONJOUR de M. Monserrat/n");
      delay(3000);
}
Attachments
Screenshot App Inventor.png
Screenshot App Inventor.png (701.97 KiB) Viewed 460 times

Zant67
 
Posts: 1
Joined: Thu Aug 01, 2019 7:41 am

Please be positive and constructive with your questions and comments.