Hello guys,
I am trying to connect Adafruit Flora Bluefruit LE module to Lilypad Arduino and send media control commands to my mobile phone. But I have got an issue regarding entering the command mode. When I run the HIDkeyboard sketch from the module tutorials, it says it doesn't recognize the Bluetooth module. I have checked all the wirings and followed all the configuration stuff for pins and UART serial, however, I am still not able to enter command mode, and the application says it's in the data mode. I tried +++ command, but this didn't work either. I am quite confused and stuck on this stage of my prototype. Could anyone help with this?
Adafruit Flora Bluefruit LE Command mode
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Adafruit Flora Bluefruit LE Command mode
Is this the guide and sketch you are following:
https://learn.adafruit.com/adafruit-flo ... idkeyboard
Can you post a photo of your wiring between the Lilypad and Flora BLE?
https://learn.adafruit.com/adafruit-flo ... idkeyboard
Can you post a photo of your wiring between the Lilypad and Flora BLE?
- mpouyakh
- Posts: 8
- Joined: Mon Aug 23, 2021 1:46 pm
Re: Adafruit Flora Bluefruit LE Command mode
https://photos.app.goo.gl/ZPYFWBVJzZhCH6Zx6
Here is the photo of the wiring. Yes, I followed that link and tested the serial and hardware serial but in both of them, the module is not identified and it says please check the wiring or make sure it is in command mode. I have toggled the switch on the Bluetooth module to switch to command mode but it doesn't work either.
Here is the photo of the wiring. Yes, I followed that link and tested the serial and hardware serial but in both of them, the module is not identified and it says please check the wiring or make sure it is in command mode. I have toggled the switch on the Bluetooth module to switch to command mode but it doesn't work either.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Adafruit Flora Bluefruit LE Command mode
Thank you for the photo and clarification.
I think you have the Flora BLE in CMD mode. I can't see the picture clearly enough to be sure.
Since you are using a LilyPad Arduino there could be some difference between that and our Flora Wearable the guide is written for.
If possible it would help if you could do two things:
1) Use a unique colored wire for each type of connection (GND / Vcc / TX / RX) etc. It is not possible for me to follow your wiring with multiple alligator cables of the same color.
2) Write a chart describing the connections you are making between the LilyPad and the Flora BLE with wire colors so we can determine if anything needs to change.
I think you have the Flora BLE in CMD mode. I can't see the picture clearly enough to be sure.
Since you are using a LilyPad Arduino there could be some difference between that and our Flora Wearable the guide is written for.
If possible it would help if you could do two things:
1) Use a unique colored wire for each type of connection (GND / Vcc / TX / RX) etc. It is not possible for me to follow your wiring with multiple alligator cables of the same color.
2) Write a chart describing the connections you are making between the LilyPad and the Flora BLE with wire colors so we can determine if anything needs to change.
- mpouyakh
- Posts: 8
- Joined: Mon Aug 23, 2021 1:46 pm
Re: Adafruit Flora Bluefruit LE Command mode
https://photos.app.goo.gl/QDzM5KCLxBNX5q49A
Sorry I used alligator clips of the same colour and made confusion to you. I used different colours clips, so in the picture, you can find the wiring and pins of the Bluetooth module are attached t the lilypad in this order:
GND <--> +
3.3V <--> -
RX <--> 9
TX <--> 10
MODE <--> 12
And when using Lilypad board this line of code is not executed: #define BLUEFRUIT_HWSERIAL_NAME Serial1
and the error is " 'Serial1' was not declared in this scope ". But in Adafruit board the Serial1 this issue does not exist.
When I change Serial1 to Serial for Hardware serial with Lilypad board, for Keyboard sketch I get this output:
Adafruit Bluefruit HID Keyboard Example
--------------K
I think the problem is the type of board, as I used the Adafruit Flora the Bluetooth module worked and responded correctly. If you could help me to solve this with Lilypad Arduino that would be great. Thanks.
Sorry I used alligator clips of the same colour and made confusion to you. I used different colours clips, so in the picture, you can find the wiring and pins of the Bluetooth module are attached t the lilypad in this order:
GND <--> +
3.3V <--> -
RX <--> 9
TX <--> 10
MODE <--> 12
And when using Lilypad board this line of code is not executed: #define BLUEFRUIT_HWSERIAL_NAME Serial1
and the error is " 'Serial1' was not declared in this scope ". But in Adafruit board the Serial1 this issue does not exist.
When I change Serial1 to Serial for Hardware serial with Lilypad board, for Keyboard sketch I get this output:
Adafruit Bluefruit HID Keyboard Example
--------------K
I think the problem is the type of board, as I used the Adafruit Flora the Bluetooth module worked and responded correctly. If you could help me to solve this with Lilypad Arduino that would be great. Thanks.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Adafruit Flora Bluefruit LE Command mode
I suspect the UART (TX/RX) is not being setup correctly in your example HIDKeyboard script. You need to customize these lines for hardware or software serial. The Lilypad you are using does support either Hardware or Software serial. By default this example code is using SPI not UART.
Code: Select all
// Create the bluefruit object, either software serial...uncomment these lines
/*
SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
*/
/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
// Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);
/* ...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);
- mpouyakh
- Posts: 8
- Joined: Mon Aug 23, 2021 1:46 pm
Re: Adafruit Flora Bluefruit LE Command mode
I have tested hardware and software serial with Lilypad. They didn't work.
The below line of code wouldn't be executed and couldn't identify Serial1 so I had to change to Serial working with Lilypad. I set up the hardware and software serial exactly as what is written in the configuration section of Flora Bluefruit LE and Adafruit Bluefruit LE UART Friend.
#define BLUEFRUIT_HWSERIAL_NAME Serial1
The below line of code wouldn't be executed and couldn't identify Serial1 so I had to change to Serial working with Lilypad. I set up the hardware and software serial exactly as what is written in the configuration section of Flora Bluefruit LE and Adafruit Bluefruit LE UART Friend.
#define BLUEFRUIT_HWSERIAL_NAME Serial1
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Adafruit Flora Bluefruit LE Command mode
Please post the code you running in CODE brackets. Since the Lilypad is a different controller from the Flora I would expect some small changes to be necessary that deviate from our guide.
Is your Lilypad currently running at 5v or 3v3? I ask because you have connected the Lilypad Vcc <--> Flora (3v3) which would be a problem if your Lilypad is being fed 5v.
It appears this will come down to getting serial1 going with your Lilypad 9,10 pins if you are already running @ 3v3 on the Lilypad.
Is your Lilypad currently running at 5v or 3v3? I ask because you have connected the Lilypad Vcc <--> Flora (3v3) which would be a problem if your Lilypad is being fed 5v.
It appears this will come down to getting serial1 going with your Lilypad 9,10 pins if you are already running @ 3v3 on the Lilypad.
- mpouyakh
- Posts: 8
- Joined: Mon Aug 23, 2021 1:46 pm
Re: Adafruit Flora Bluefruit LE Command mode
Code: Select all
#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#if SOFTWARE_SERIAL_AVAILABLE
#include <SoftwareSerial.h>
#endif
/*=========================================================================
APPLICATION SETTINGS
FACTORYRESET_ENABLE Perform a factory reset when running this sketch
Enabling this will put your Bluefruit LE module
in a 'known good' state and clear any config
data set in previous sketches or projects, so
running this at least once is a good idea.
When deploying your project, however, you will
want to disable factory reset by setting this
value to 0. If you are making changes to your
Bluefruit LE device via AT commands, and those
changes aren't persisting across resets, this
is the reason why. Factory reset will erase
the non-volatile memory where config data is
stored, setting it back to factory default
values.
Some sketches that require you to bond to a
central device (HID mouse, keyboard, etc.)
won't work at all with this feature enabled
since the factory reset will clear all of the
bonding data stored on the chip, meaning the
central device won't be able to reconnect.
MINIMUM_FIRMWARE_VERSION Minimum firmware version to have some new features
-----------------------------------------------------------------------*/
#define FACTORYRESET_ENABLE 0
#define MINIMUM_FIRMWARE_VERSION "0.6.6"
#define BUFSIZE 128 // Size of the read buffer for incoming data
#define VERBOSE_MODE true // If set to 'true' enables debug output
#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 -1 // Required for software serial!
#define BLUEFRUIT_UART_RTS_PIN -1
#define BLUEFRUIT_UART_MODE_PIN -1
#define BLUEFRUIT_HWSERIAL_NAME Serial
#define VERBOSE_MODE true // If set to 'true' enables debug output
/*=========================================================================*/
// Create the bluefruit object, either software serial...uncomment these lines
//SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
//Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
// BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);
/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
// Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);
/* ...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);
/* ...software SPI, using SCK/MOSI/MISO user-defined SPI pins and then user selected CS/IRQ/RST */
//Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_SCK, BLUEFRUIT_SPI_MISO,
// BLUEFRUIT_SPI_MOSI, 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)
{
while (!Serial); // required for Flora & Micro
delay(500);
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);
Serial.begin(9600);
Serial.println(F("Adafruit Bluefruit HID Keyboard Example"));
Serial.println(F("---------------------------------------"));
/* Initialise the module */
Serial.print(F("Initialising the Bluefruit LE module: "));
if ( !ble.begin(VERBOSE_MODE,true) )
{
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();
/* Change the device name to make it easier to find */
Serial.println(F("Setting device name to 'Bluefruit Keyboard': "));
if (! ble.sendCommandCheckOK(F( "AT+GAPDEVNAME=Bluefruit Keyboard" )) ) {
error(F("Could not set device name?"));
}
/* Enable HID Service */
Serial.println(F("Enable HID Service (including Keyboard): "));
if ( ble.isVersionAtLeast(MINIMUM_FIRMWARE_VERSION) )
{
if ( !ble.sendCommandCheckOK(F("AT+BleHIDEn=On"))) {
error(F("Could not enable Keyboard"));
}
}else
{
if (! ble.sendCommandCheckOK(F( "AT+BleKeyboardEn=On" ))) {
error(F("Could not enable Keyboard"));
}
}
/* Add or remove service requires a reset */
Serial.println(F("Performing a SW reset (service changes require a reset): "));
if (! ble.reset() ) {
error(F("Couldn't reset??"));
}
Serial.println();
Serial.println(F("Go to your phone's Bluetooth settings to pair your device"));
Serial.println(F("then open an application that accepts keyboard input"));
Serial.println();
Serial.println(F("Enter the character(s) to send:"));
Serial.println(F("- \\r for Enter"));
Serial.println(F("- \\n for newline"));
Serial.println(F("- \\t for tab"));
Serial.println(F("- \\b for backspace"));
Serial.println();
}
/**************************************************************************/
/*!
@brief Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{
// Display prompt
Serial.print(F("keyboard > "));
// Check for user input and echo it back if anything was found
char keys[BUFSIZE+1];
getUserInput(keys, BUFSIZE);
Serial.print("\nSending ");
Serial.println(keys);
ble.print("AT+BleKeyboard=");
ble.println(keys);
if( ble.waitForOK() )
{
Serial.println( F("OK!") );
}else
{
Serial.println( F("FAILED!") );
}
}
/**************************************************************************/
/*!
@brief Checks for user input (via the Serial Monitor)
*/
/**************************************************************************/
void getUserInput(char buffer[], uint8_t maxSize)
{
memset(buffer, 0, maxSize);
while( Serial.available() == 0 ) {
delay(1);
}
uint8_t count=0;
do
{
count += Serial.readBytes(buffer+count, maxSize);
delay(2);
} while( (count < maxSize) && !(Serial.available() == 0) );
}
Here is the code that I am trying to run with Lilypad.
According to the documents of the LilyPad Arduino 328 Main Board, the board will run from 2V to 5V.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Adafruit Flora Bluefruit LE Command mode
The LilyPad you are using can take 2v - 5v. However, the Flora BLE must have 3v which means your LilyPad needs to also be operating at 3v or you need to introduce a level shifter for two way UART communication.
- mpouyakh
- Posts: 8
- Joined: Mon Aug 23, 2021 1:46 pm
Re: Adafruit Flora Bluefruit LE Command mode
Thanks for your response. Would please guide me on which level shifter shall I use?
I have another issue if you could answer that I would appreciate it. I have connected the Bluefruit LE module to the Adafruit Fora board same as the tutorial (https://learn.adafruit.com/adafruit-flo ... -le/sewing) and connected two conductive fabrics to pins D12 and D6 of Flora board. I could send media control commands by touching those fabric sensors to my mobile phone remotely, for example to volume up the sound. But, when I unplug the USB cable used for uploading codes to Flora, then it seems it doesn't work and commands are not sent; however, it works when the USB cable is plugged in. Shouldn't it work with a battery instead of a USB cable?
I have another issue if you could answer that I would appreciate it. I have connected the Bluefruit LE module to the Adafruit Fora board same as the tutorial (https://learn.adafruit.com/adafruit-flo ... -le/sewing) and connected two conductive fabrics to pins D12 and D6 of Flora board. I could send media control commands by touching those fabric sensors to my mobile phone remotely, for example to volume up the sound. But, when I unplug the USB cable used for uploading codes to Flora, then it seems it doesn't work and commands are not sent; however, it works when the USB cable is plugged in. Shouldn't it work with a battery instead of a USB cable?
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Adafruit Flora Bluefruit LE Command mode
You might not need a level shifter if you are successfully using your Flora and the Bluefruit LE as in this cap touch fabric scenario. Was this the same setup we had been discussing in the thread or did something else change tha the BLE module is now being discovered?
When using battery are you getting power to both devices (LEDs on)? I would expect your setup to work just fine on battery. Do you have a multimeter you can use to measure the voltage of Vcc and GND on the Flora and BLE using the two different setups USB vs Bat?
When using battery are you getting power to both devices (LEDs on)? I would expect your setup to work just fine on battery. Do you have a multimeter you can use to measure the voltage of Vcc and GND on the Flora and BLE using the two different setups USB vs Bat?
- mpouyakh
- Posts: 8
- Joined: Mon Aug 23, 2021 1:46 pm
Re: Adafruit Flora Bluefruit LE Command mode
Yes, the same set-up was used for the Flora board and LE module. Actually, I intended to use Lilypad as it has more analog pins to use compared to the Flora module and also the accuracy of touches that could be recognized by lilypad pad was much higher than Flora, I don't know if it is the problem with flora or my set up maybe.
And yes when using the battery, both LEDs on modules were on. You are right I have to measure voltage through a multimeter to see where is the problem.
And yes when using the battery, both LEDs on modules were on. You are right I have to measure voltage through a multimeter to see where is the problem.
Please be positive and constructive with your questions and comments.