Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
0

Issue with Bluetooth on Flora v3
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Issue with Bluetooth on Flora v3

by horizons on Mon Apr 26, 2021 3:46 am

Hello All,

I am using the Flora v3 https://www.adafruit.com/product/659?gclid=Cj0KCQjwppSEBhCGARIsANIs4p6P1eI93clqpMZdv3x2Q8gPbZAsBYgbrvkAruq3589FOVoskJJMQp4aAvlPEALw_wcB and the Flora Wearable Bluefruit LE Module https://www.adafruit.com/product/2487

I am also using the Flora accelerometer. The purpose of this code is to calculate the number of steps that the user is taking. As the step count is calculated/updated, I want to send it to the Adafruit Bluefruit Android app over UART using the Bluefruit LE Module. Below I have provided the code I am working with:

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_ATParser.h>
#include <Adafruit_BLE.h>
#include <Adafruit_BLEBattery.h>
#include <Adafruit_BLEEddystone.h>
#include <Adafruit_BLEGatt.h>
#include <Adafruit_BLEMIDI.h>
#include <Adafruit_BluefruitLE_SPI.h>
#include <Adafruit_BluefruitLE_UART.h>

#define BUFSIZE                        128   // Size of the read buffer for incoming data
#define VERBOSE_MODE                   true  // If set to 'true' enables debug output

#define BLUEFRUIT_UART_CTS_PIN         -1   // Not required for Flora
#define BLUEFRUIT_UART_RTS_PIN         -1    // Optional, set to -1 if unused
#define BLUEFRUIT_UART_MODE_PIN        -1    // Not required for Flora


#define BLUEFRUIT_HWSERIAL_NAME           Serial1
Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);


#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>


int steps = 0;

/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);

void setup(void)
{
#ifndef ESP8266
  while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
#endif
  Serial.begin(9600);

  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    //Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
}

void loop(void)
{
 
  //if (millis() >= 30000) exit(0); //end in half a minute
  /* Get a new sensor event */
  sensors_event_t event;
  accel.getEvent(&event);

  float average;
  average = sqrt(pow(event.acceleration.x, 2) + pow(event.acceleration.y, 2) + pow(event.acceleration.z, 2));
  if (average > 9.00)
  {
    steps = steps + 1;
  }

  char *myChar;
  char str[10];
  myChar = itoa(steps,str,10);
  //Serial.write("steps:"); 
  //Serial.write(" ");
  Serial.write(myChar);
  //Serial.write("\n");
 
   

  delay(1000);
}


Problem: I can see my step count in the Arduino serial monitor, however, not in the UART on the Bluefruit app. I know that it is not a setup issue because I am able to see the steps with the app with this code (minus the bluefruit specifics of course) with an Arduino Mega and Nano. I have also swapped out my Flora and Bluefruit LE for new components and it still did not work so I also know that I am not using any defective parts. The Flora is transmitting the steps to the Bluefruit since I can see the TX light blinking but the app is not showing what is received. This also should not be a mode issue because I have mode grounded and I can see via the LED that it is in data mode.

I am assuming that the issue is the configuration of the Bluetooth for the Flora but I am not sure what I am lacking as I have followed the tutorials provided in regard to setting up hardware UART for the Flora: https://learn.adafruit.com/adafruit-flora-bluefruit-le/example-code

Any advice or suggestions would be appreciated. I've also tried other Adafruit wearable boards and I've run into similar issues.

horizons
 
Posts: 3
Joined: Sun Apr 25, 2021 11:00 pm

Re: Issue with Bluetooth on Flora v3

by adafruit_support_carter on Mon Apr 26, 2021 12:14 pm

You create a BLE instance:
Code: Select all | TOGGLE FULL SIZE
    Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);

but then never use it. Then only thing in your loop is an output to the Serial Monitor:
Code: Select all | TOGGLE FULL SIZE
      Serial.write(myChar);

adafruit_support_carter
 
Posts: 20354
Joined: Tue Nov 29, 2016 2:45 pm

Re: Issue with Bluetooth on Flora v3

by horizons on Mon Apr 26, 2021 12:24 pm

adafruit_support_carter wrote:You create a BLE instance:
Code: Select all | TOGGLE FULL SIZE
    Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);

but then never use it. Then only thing in your loop is an output to the Serial Monitor:
Code: Select all | TOGGLE FULL SIZE
      Serial.write(myChar);


Thank you for the response. I was using Serial.write because that is what worked previously for bluetooth on other devices. I've tried using "ble.write(myChar)" and "ble.println(myChar)" like the examples do sometimes but neither yields any output to UART. Is there another way to "use" this instance I've created?

horizons
 
Posts: 3
Joined: Sun Apr 25, 2021 11:00 pm

Re: Issue with Bluetooth on Flora v3

by adafruit_support_carter on Mon Apr 26, 2021 12:44 pm

See if you can get the example sketch to work first:
https://learn.adafruit.com/adafruit-flo ... le/bleuart

adafruit_support_carter
 
Posts: 20354
Joined: Tue Nov 29, 2016 2:45 pm

Re: Issue with Bluetooth on Flora v3

by horizons on Tue Apr 27, 2021 4:51 pm

I was able to run that example and both send and receive between the app and the serial monitor.
I have identified the following lines as the main drivers for the sending of information from the Flora to the app:
Code: Select all | TOGGLE FULL SIZE
    // Send characters to Bluefruit
    Serial.print("[Send] ");
    Serial.println(inputs);

    ble.print("AT+BLEUARTTX=");
    ble.println(inputs);


I don't think I need to use:
Code: Select all | TOGGLE FULL SIZE
bool getUserInput(char buffer[], uint8_t maxSize)

Because I am not trying to send user input, just the steps calculated.

So the problem is probably not the way I am configuring the bluetooth but these ble functions instead. They continue to not produce any outputs to UART when incorporated into my code. Is there anywhere I can read further about these functions? I am still unsure about what I am missing here.
Edit: I've also noticed that the examples use CMD mode and a baud rate of 112500 but I am using data mode and a rate of 9600 for my project; would this be an issue? (I've tried changing the mode and rate and it has not yielded any results.)

Thank you.

horizons
 
Posts: 3
Joined: Sun Apr 25, 2021 11:00 pm

Re: Issue with Bluetooth on Flora v3

by adafruit_support_carter on Wed Apr 28, 2021 11:02 am

Edit: I've also noticed that the examples use CMD mode and a baud rate of 112500 but I am using data mode and a rate of 9600 for my project; would this be an issue?

Yes, it can. See here:
https://learn.adafruit.com/adafruit-flo ... -2177193-6

So running that example is a good way to do a basic sanity check that things are working. For your actual application, you may want to do something more like this:
https://learn.adafruit.com/adafruit-flo ... /data-mode
Then you'd just do serial writes from the Flora and the BLE module would pass them on to the BLE app.

adafruit_support_carter
 
Posts: 20354
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.