Gemma M0 + Flora Bluefruit

Wearable electronics: boards, conductive materials, and projects from Adafruit!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
siz3thr33
 
Posts: 6
Joined: Mon Nov 29, 2021 12:16 am

Gemma M0 + Flora Bluefruit

Post by siz3thr33 »

Hey Adafruit! I am hoping to add some bluetooth to a project I'm working on where the main board is the Gemma M0. It seemed to me like the board was almost identical to the Flora, so I took a leap of faith and picked up some of the flora bluefruit le modules hoping the Gemma would work more or less the same as the Flora.

For the wiring (power and ground excluded from the diagram, I'm assuming I figured that out correctly), I have the "A1" pin(?) on the Gemma hooked up to the "TX" pin(?) on the Bluefruit, and the "A2" pin(?) on the Gemma hooked up to the "RX" pin on the Bluefruit:

Code: Select all

   +--------------------------------+
   |                                |
   |    +-----------------------+   |
   |    |       | USB IN |      |   |
   |    |                       |   |
   |    |         GEMMA         |   |
   |    |                       |   |
   |    | +-------+  +-------+  |   |
   +----| | A1/D2 |  | GRND  |  |   |
        | +-------+  +-------+  |   |
        |                       |   |
        | +-------+  +-------+  |   |
   +----| | A2/D0 |  | D1/A0 |  |   |
   |    | +-------+  +-------+  |   |
   |    |                       |   |
   |    | +-------+  +-------+  |   |
   |    | | 3Vo   |  | VOUT  |  |   |
   |    | +-------+  +-------+  |   |
   |    |                       |   |
   |    |       | USB IN |      |   |
   |    +-----------------------+   |
   |                                |
   |    +-----------------------+   |
   |    |    FLORA BLUEFRUIT    |   |
   |    |                       |   |
   |    | +-------+  +-------+  |   |
   |    | | MODE  |  | 3.3v  |  |   |
   |    | +-------+  +-------+  |   |
   |    |                       |   |
   |    | +-------+  +-------+  |   |
   |    | | GRND  |  | TX    -------+
   |    | +-------+  +-------+  |   
   |    |                       |   
   |    |      +-------+        |   
   |    |      | RX    |        |   
   |    |      +---|---+        |   
   |    +----------|------------+   
   |               |
   +---------------+
For the code itself, I basically have:

Code: Select all

#include <Arduino.h>
#include <SPI.h>

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

Adafruit_BluefruitLE_UART ble(Serial1, 12);
unsigned long previous = 0;

void setup(void) {
  while (!Serial) {
    delay(100);
  }

  if (ble.begin(true)) {
    Serial.println("[bluetooth] ready");
  } else {
    Serial.println("[bluetooth] failed");

    while (true) {
      Serial.println("[bluetooth] failed boot, looping forever");
      delay(1000);
    }
  }

  if (ble.factoryReset()) {
    Serial.println("[bluetooth] reset success");
  } else {
    Serial.println("[bluetooth] reset failed");
  }

  Serial.println("[bluetooth] ble ready, configuring");
  ble.info();
  ble.echo(false);
  ble.verbose(false);
}

void loop(void) {
  unsigned long current = millis();

  if (current - previous < 250) {
    return;
  }

  previous = current;

  if (ble.isConnected() != true) {
    Serial.println("[bluetooth] not connected");
    return;
  }

  Serial.println("[bluetooth] connection established");
  int message = ble.read();

  switch (message) {
    case -1:
      Serial.println("no message");
      break;
    default:
      Serial.println("has message");
      break;
  }

  previous = current;
}
When I run this code, with that circuit in place, I see all of the logs from the setup function that I would expect:

Code: Select all

[bluetooth] ready
[bluetooth] reset success
[bluetooth] ble ready, configuring
Then, once the program enters the main loop, I do see:

Code: Select all

[bluetooth] not connected
Then, after connecting with the BluefruitConnect IOS app I see:

Code: Select all

[bluetooth] connection established
no message
The trouble I'm having is that it seems like the "read" call is never returning anything other than -1. Inside the BluefruitConnect IOS app I've tried both
1. sending text strings using the "UART" UI
2. clicking some of the buttons in the "Controller" -> "Control Pad" UI

Is there something obviously wrong with this setup?

Thank you!

P.S - By trade I've only ever worked with software on web applications, so my electrical engineering knowledge is very limited; I apologize if I'm not even making sense.

User avatar
siz3thr33
 
Posts: 6
Joined: Mon Nov 29, 2021 12:16 am

Re: Gemma M0 + Flora Bluefruit

Post by siz3thr33 »

Also I forgot to mention what I'm even trying to do (sorry!). As a proof-of-concept/learning-exercise, all I'm trying to do currently is be able to receive some kind of string sent over bluetooth (from the BluefruitConnect) and log it out to "Serial.println".

User avatar
siz3thr33
 
Posts: 6
Joined: Mon Nov 29, 2021 12:16 am

Re: Gemma M0 + Flora Bluefruit

Post by siz3thr33 »

also, I just noticed the diagram I posted had a little too much copy/paste, sorry. corrected:

Code: Select all

   +--------------------------------+
   |                                |
   |    +-----------------------+   |
   |    |       | USB IN |      |   |
   |    |                       |   |
   |    |         GEMMA         |   |
   |    |                       |   |
   |    | +-------+  +-------+  |   |
   +----| | A1/D2 |  | GRND  |  |   |
        | +-------+  +-------+  |   |
        |                       |   |
        | +-------+  +-------+  |   |
   +----| | A2/D0 |  | D1/A0 |  |   |
   |    | +-------+  +-------+  |   |
   |    |                       |   |
   |    | +-------+  +-------+  |   |
   |    | | 3Vo   |  | VOUT  |  |   |
   |    | +-------+  +-------+  |   |
   |    |                       |   |
   |    |       | BATT   |      |   |
   |    +-----------------------+   |
   |                                |
   |    +-----------------------+   |
   |    |    FLORA BLUEFRUIT    |   |
   |    |                       |   |
   |    | +-------+  +-------+  |   |
   |    | | MODE  |  | 3.3v  |  |   |
   |    | +-------+  +-------+  |   |
   |    |                       |   |
   |    | +-------+  +-------+  |   |
   |    | | GRND  |  | TX    -------+
   |    | +-------+  +-------+  |   
   |    |                       |   
   |    |      +-------+        |   
   |    |      | RX    |        |   
   |    |      +---|---+        |   
   |    +----------|------------+   
   |               |
   +---------------+

User avatar
siz3thr33
 
Posts: 6
Joined: Mon Nov 29, 2021 12:16 am

Re: Gemma M0 + Flora Bluefruit

Post by siz3thr33 »

I believe I figured out a few answers to my problem that are helpful:

1. The correct constructor to use when using either the flora or the gemma m0 is:

Code: Select all

Adafruit_BluefruitLE_UART ble(Serial1, -1);
2. For the Gemma m0, the definition of "Serial1" comes from this definition, which does map RX to pin 2 and TX to pin 0 (matching the pinout diagram).

3. I believe I was misusing the bluefruit library, the data/command mode switching is pretty confusing. for example, checking isConnected after moving into data mode won't return the expected result as it does not switch itself into command mode before sending.

I'm still hoping to figure out a way to check the connection status during my main "loop", but have yet to figure that out.

Locked
Please be positive and constructive with your questions and comments.

Return to “Wearables”