Attempting to use a Feather 32u4 Bluefruit LE to communicate over Bluetooth as a wireless "keyboard" / controller with a touchscreen device. Here are some details:
Commands work over a wired USB connection when buttons pressed using "Keyboard." library prefix w/ print command. Commands print right to page.
Commands work only on serial monitor when buttons pressed using "ble." library prefix w/ print command. The desired effect is to get these "ble" commands to print characters wirelessly to touchscreen device. However, these commands don't print to page, only to serial monitor [the serially relevant part of the software has been omitted for reading brevity, hopefully it is not important for this particular issue]
Bluefruit Feather is Visible to Bluetooth touchscreen device I want the commands sent to while Feather only on battery power (When Feather is not wired to the device the commands are sent to), so am assuming the feather module has a working Bluetooth means of sending data to the touchscreen device.
Maybe there is a line commented out somewhere that should not be or vice versa? I have tried many such variations and variations of the .ble command though so far am assuming my problem is that of a general lack of expertise.
Apologies for the Large amount of code below, would provide less if I believed it could provide full context as to the current situation. Thanks and Cheers!
#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#include "BluefruitConfig.h"
#if SOFTWARE_SERIAL_AVAILABLE
#include <SoftwareSerial.h>
#endif
int pinA = 5; //Declaring variables for the pins
/*=========================================================================
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"
/*=========================================================================*/
// 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);
/* ...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)
{
pinMode(pinA, INPUT_PULLUP);
//Setting up the internal pull-ups resistors
}
/**************************************************************************/
/*!
@brief Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{ if (digitalRead(pinA) == LOW){
delay(90);
ble.println("Hello"); //Sending a string
delay(50);}
}
It is my understanding of the Feather32u4 Bluefruit LE is that the communication between the 32u4 and the nrf ble module is over the SPI bus, and I have created my bluefruit object with hardware spi.
This board and the Adafruit BLE library used are not that widely used by people on this forum. Your use as a keyboard controller is even more unique. You might have better responses through an Adafruit Forum.
Switching to uncomment the referred SPI interface setup line made the bluefruit feather show as "not connected" both in the bluefruit config app and the bluetooth device menu of the touchscreen device. Also, the blue led on the feather has changed in flashing from long to short blue pulses.
Per suggestion will post updated situation to Adafruit's forum. Thanks again!
Sorry for First-time Poster error, the entirety of this modified sketch is now here.
/*********************************************************************
This is an example for our nRF51822 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
/*
This example shows how to send HID (keyboard/mouse/etc) data via BLE
Note that not all devices support BLE keyboard! BLE Keyboard != Bluetooth Keyboard
*/
#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#include "BluefruitConfig.h"
#if SOFTWARE_SERIAL_AVAILABLE
#include <SoftwareSerial.h>
#endif
int pinA = 5; //Declaring variables for the pins
/*=========================================================================
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"
/*=========================================================================*/
// 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);
/* ...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)
{
ble.begin();
ble.factoryReset();
pinMode(pinA, INPUT_PULLUP); //Setting up the internal pull-ups resistors
}
/**************************************************************************/
/*!
@brief Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{ if (digitalRead(pinA) == LOW){
delay(90);
ble.println("Hello"); //Sending a string
delay(50);}
}
When I take the last posted sketch (with the BluefruitConfig.h tab included)
I can see "Hello" output in the lightblue phone app under a characteristic name TXD when I make this modification to loop().
I can also see it printing "Hello" when I use the Kai Morich Serial Bluetooth Terminal with BLE. The Feather is using a Nordic UART service as default.
void loop(void)
{
if (digitalRead(pinA) == HIGH) {
delay(90);
ble.print("AT+BLEUARTTX=");
ble.println("Hello"); //Sending a string
delay(50);
}
}
You need to spend some time with the Adafruit examples to learn the syntax.
In my opinion the Feather32u4 Bluefruit LE is difficult to use and you may do better with a Nano33BLE or an ESP32. I don't know about the applicability of either of those devices to your usb keyboard usage.
Thank you again! my apologies for the delayed reply. I was able to send/view a Bluetooth command from the 32u4 controller through the Adafruit Bluefruit app UART. However, the general response was quite laggy, so I have switched to an ESP32, which I am still trying to figure out how to send/receive data using bleKeyboard.