sandeepmistry / arduino-BLEPeripheral

An Arduino library for creating custom BLE peripherals with Nordic Semiconductor's nRF8001 or nR51822.
MIT License
463 stars 179 forks source link

Adafruit Feather 32u4 Bluefruit LE #69

Closed orcinz closed 8 years ago

orcinz commented 8 years ago

Hi.

I have an Adafruit Feather 32u4 Bluefruit LE use nRF51822 chipset.

Their official software doesnt support to modify HID. They just have mouse and keyboard option.

But i need to use my nRF51822 as gamepad device. So I tried to upload your code on my Adafruit Feather, but nothing changed. It seems like they dont communicate with each other. Is this maybe because of BLE_REQ, BLE_RDY, BLE_RST keys?

If so, how can I find my Adafruit Feather's pin combination?

Thanks in advance.

zrecore commented 8 years ago

When you open up an Adafruit Feather M0 Bluefruit LE example (Arduino IDE), it also opens up a config file. Check the values in the config file "BluefruitConfig.h" that is included in each example.

zrecore commented 8 years ago

Additionally, the example sketches from Adafruit are configured to use hardware SPI near the top of each sketch.

orcinz commented 8 years ago

Hi. Thank you for your answer @zrecore Yes, I have checked the sketch; https://cdn-learn.adafruit.com/assets/assets/000/030/930/original/adafruit_products_2889_pinout_v1_0.png?1457306365

That shows RST, CS and IRQ pins.

And BluefruitConfig.h has these pins;

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 11 // Required for software serial!

define BLUEFRUIT_UART_RTS_PIN -1 // Optional, set to -1 if unused

define BLUEFRUIT_UART_MODE_PIN 12 // Set to -1 if unused

define BLUEFRUIT_SPI_CS 8

define BLUEFRUIT_SPI_IRQ 7

define BLUEFRUIT_SPI_RST 4 // Optional but recommended, set to -1 if unused

Any opinion if which one is what?.. Or how should I configure?..

zrecore commented 8 years ago

They can't both act as peripherals and talk to each other (yet). You need them to talk to a central device.

https://learn.adafruit.com/introduction-to-bluetooth-low-energy/gatt On Jun 14, 2016 10:20 AM, "orcinz" notifications@github.com wrote:

Hi. Thank you for your answer @zrecore https://github.com/zrecore Yes, I have checked the sketch;

https://cdn-learn.adafruit.com/assets/assets/000/030/930/original/adafruit_products_2889_pinout_v1_0.png?1457306365

That shows RST, CS and IRQ pins.

And BluefruitConfig.h has these pins;

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 11 // Required for software serial!

define BLUEFRUIT_UART_RTS_PIN -1 // Optional, set to -1 if unused

define BLUEFRUIT_UART_MODE_PIN 12 // Set to -1 if unused

define BLUEFRUIT_SPI_CS 8

define BLUEFRUIT_SPI_IRQ 7

define BLUEFRUIT_SPI_RST 4 // Optional but recommended, set to -1 if

unused

Any opinion if which one is what?.. Or how should I configure?..

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sandeepmistry/arduino-BLEPeripheral/issues/69#issuecomment-225952714, or mute the thread https://github.com/notifications/unsubscribe/AAaLbCbQwH9mZJ4ajpYe1i67ZeY1C40vks5qLuL4gaJpZM4I1jOk .

orcinz commented 8 years ago

I have read it now. But couldnt be sure to understand exactly. It says, bluetooth device should connect to a centeral device such as mobile phone etc..

So, that means, my adafruit feather and my pc can't connect to each other as a HID gamepad?..

orcinz commented 8 years ago

Any opinion @zrecore ?

zrecore commented 8 years ago

Yes, a BLE peripheral can connect to a PC, or a smart device (assuming BLE support).

The PC or smartphone would act as the central device. The Bluefruit LE board would act as the peripheral.

Do you have your source code on github? Maybe taking a look at it will help. On Jun 14, 2016 10:42 AM, "orcinz" notifications@github.com wrote:

Any opinion @zrecore https://github.com/zrecore ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sandeepmistry/arduino-BLEPeripheral/issues/69#issuecomment-225959073, or mute the thread https://github.com/notifications/unsubscribe/AAaLbGGLUPKCW8pIssimvWtCmUXM5eDZks5qLugcgaJpZM4I1jOk .

orcinz commented 8 years ago

Well, that is the problem already @zrecore

Adafruit official library dont let me configure my device as HID gamepad.

bleHIDPeripheral.setLocalName("HID Keyboard");
  bleHIDPeripheral.addHID(bleKeyboard);

  bleHIDPeripheral.begin();

  Serial.println(F("BLE HID Keyboard"));

This is the code for HID Keyboard configuration. But there is no such code for HID gamepad.

Thats why I wanted to use arduino-BLEPeripheral library. So that i could connect my adafruit feather as a HID Gamepad..

"The hardware can do it, but we don't have any existing code that configures the nRF51822 to act like a joystick."

Thats what support told me when I ask Adafruit forums..

orcinz commented 8 years ago

Any idea @zrecore ?

zrecore commented 8 years ago

Most likely, you will need to create an HID Joystick profile (either with the BLEPeripheral API, or with the Nordic Semiconductor Developers Kit)

Your device must provide the correct descriptor for an HID Joystick. Perhaps you can research this a bit further. https://github.com/troystribling/nordic-ble-sdk-examples

Any idea @zrecore https://github.com/zrecore ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sandeepmistry/arduino-BLEPeripheral/issues/69#issuecomment-225991278, or mute the thread https://github.com/notifications/unsubscribe/AAaLbLB25Hq1VhPnsEwzDwMoBTYUwvVuks5qLwHqgaJpZM4I1jOk .

orcinz commented 8 years ago

Tried that too.. Not working..

Do you have any idea about REQ, RDY and RST pins of adafruit feather according to that sketch;

https://cdn-learn.adafruit.com/assets/assets/000/030/930/original/adafruit_products_2889_pinout_v1_0.png?1457306365

Are they RST, CS and IRQ pins?

If so, even I tried all combinations between these 3 pins, why doesnt that work?

I am suffering here and requesting your little help @zrecore

zrecore commented 8 years ago

Yes, by default. The Adafruit examples (such as the data mode example) use hardware SPI with those pons as the default.

Without any idea of how your board is wired up, what firmware is on the BLE module, what your code looks like, etc... I can't really help you further.

Pictures, code, video, etc. will help further investigate the issue. On Jun 15, 2016 8:45 AM, "orcinz" notifications@github.com wrote:

Tried that too.. Not working..

Do you have any idea about REQ, RDY and RST pins of adafruit feather according to that sketch;

https://cdn-learn.adafruit.com/assets/assets/000/030/930/original/adafruit_products_2889_pinout_v1_0.png?1457306365

Are they RST, CS and IRQ pins?

If so, even I tried all combinations between these 3 pins, why doesnt that work?

I am suffering here and requesting your little help @zrecore https://github.com/zrecore

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sandeepmistry/arduino-BLEPeripheral/issues/69#issuecomment-226229361, or mute the thread https://github.com/notifications/unsubscribe/AAaLbIzHN4vfLK0LFh5Xgd8Y8jwlM4ylks5qMB4DgaJpZM4I1jOk .

zrecore commented 8 years ago

... additionally, please mention what operating system you are using for this, what Bluetooth hardware you have on your machine, etc. Details are needed. On Jun 15, 2016 9:31 AM, "Alex Albino" webmaster@alexventure.com wrote:

Yes, by default. The Adafruit examples (such as the data mode example) use hardware SPI with those pons as the default.

Without any idea of how your board is wired up, what firmware is on the BLE module, what your code looks like, etc... I can't really help you further.

Pictures, code, video, etc. will help further investigate the issue. On Jun 15, 2016 8:45 AM, "orcinz" notifications@github.com wrote:

Tried that too.. Not working..

Do you have any idea about REQ, RDY and RST pins of adafruit feather according to that sketch;

https://cdn-learn.adafruit.com/assets/assets/000/030/930/original/adafruit_products_2889_pinout_v1_0.png?1457306365

Are they RST, CS and IRQ pins?

If so, even I tried all combinations between these 3 pins, why doesnt that work?

I am suffering here and requesting your little help @zrecore https://github.com/zrecore

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sandeepmistry/arduino-BLEPeripheral/issues/69#issuecomment-226229361, or mute the thread https://github.com/notifications/unsubscribe/AAaLbIzHN4vfLK0LFh5Xgd8Y8jwlM4ylks5qMB4DgaJpZM4I1jOk .

orcinz commented 8 years ago

Ok. I am using Macbook Air & Windows 8 x64 with Bootcamp. My bluetooth hardware is Apple Broadcom Built-in Bluetooth.

I connected an MPU-6050 sensor to my adafruit feather to receive X and Y variables.

I use that code;

#include <Arduino.h>
#include <SPI.h>
#if not defined (_VARIANT_ARDUINO_DUE_X_) && not defined(ARDUINO_ARCH_SAMD)
  #include <SoftwareSerial.h>
#endif

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

#include "BluefruitConfig.h"

#include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY;
int16_t BcX,BcY;
int16_t CcX,CcY;
int16_t i,x,y;

    #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)
{
  while (!Serial);  // required for Flora & Micro
  delay(500);

  Serial.begin(115200);
  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) )
  {
    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();

     Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);

}

/**************************************************************************/
/*!
    @brief  Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{

/**************************************************************************/
/*!
    @brief  Checks for user input (via the Serial Monitor)
*/
/**************************************************************************/

Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers

/********************THIS IS FOR FIRST CALIBRATION*********************/
if (i<2){

    AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
    AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
    }
else {}
if (i<2){
i=i+1;
} else {}
/************************************************************************/

  BcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
  BcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)

if ((AcX-BcX)> 500) 
  {
  Serial.print("W");
  ble.println("AT+BleKeyboard=W");
    Serial.print(",");

  }

if ((AcX-BcX)< -500) 
  {
     ble.println("AT+BleKeyboard=S");
  Serial.print("S"); 
  Serial.print(",");
  }

if ((AcY-BcY)> 500) 
  {
     ble.println("AT+BleKeyboard=A");
  Serial.print("A"); 
  Serial.print(",");
  }

if ((AcY-BcY)< -500) 
  {
     ble.println("AT+BleKeyboard=D");
  Serial.print("D"); 
  Serial.print(",");
  }

  digitalWrite(13, HIGH);
   delay(50);

}

With that code, I connect my Adafruit Feather As Bluetooth HID Keyboard.

But in Adafruit Feather Library there is no option to configure my device as Bluetooth HID Gamepad.

I tried to use code shared here.

I downloaded the zip, copied library and examples to my arduino folder, opened HID Keyboard example and uploaded to my feather device.

Code uploaded without any errors.

As I open the serial, (in 115200 or 9600 tried both) there is nothing happening at the serial screen.

Then I search bluetooth devices with my PC and I see that my Adafruit Feather still shows itself as "Adafruit Bluetooth Device"

I mean, uploading the code which I downloaded from here, doesnt change my device's bluetooth settings.

I thought that may because of Bluetooth pins, I tried many combinations, but couldnt succeeded..

I dont know what else I need to share with my experience, but these are all I can tell you about.

I just want to configure my adafruit feather as Bluetooth HID Gamepad.

But couldnt succeeded for many days...

I hope you can help me with these informations I shared @zrecore

sandeepmistry commented 8 years ago

@zrecore thanks for helping out!

@orcinz unfortunately this library only supports the Bluefruit LE based on the nRF8001. I think this is pretty clear in the read me. There was some discussion in #34 to support Adafruit board based on the nRF51822, however the conclusion wasn't possible to fully support it without running custom firmware.

However, if you're feeling adventurous you can try to load custom firmware on it using arduino-nRF5 with and external programmer and the nRF5 branch of this repo.

Givy commented 6 years ago

Hi,

I am trying to get the Adafruit Feather 32u4 Bluefruit LE working with RPi and I2C. How do I put it into Slave mode or I2C mode or what is the Slave address on this module?! I have it connected without the pull up resistors to the RPi. I have other components attached to RPi with I2C and when I run "i2cdetect -y 1" from RPi, I do see the slave addresses of the other components (see below), but none for the "Adafruit Feather 32u4 Bluefruit LE ".

I also loaded the "Atcommand" sketch into Arduino and tried to use the "AT+HWI2CSCAN" from the serial line, but nothing comes back.

i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- 34 -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --

Thank you for your help.

Regards,

Givi