sandeepmistry / arduino-BLEPeripheral

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

Fixes problem when using a Mega2560 board where I had to do pin reass… #214

Open Digital-Thor opened 6 years ago

Digital-Thor commented 6 years ago

…ignments to connect with NRF8001 Bluefruit LE. In that case the code kept restarting. I had to manually set pinMode to solve. This fix will also likely apply to other custom boards which don't use the standard Arduino-to-NRF8001 pin assignment. (Updates are only to in-line comments not code.)

sandeepmistry commented 6 years ago

What values were you using for PIN_REQ and PIN_RST? Where they past into the BLEHIDPeripheral constructor as well?

Any way this can be fixed in the lib itself?

Digital-Thor commented 6 years ago

Below is my code snippet. Yes, it would probably be better to fix the problem upstream so that other dependencies benefit, but I'm not sure where/how to do that. Another option is that I could update the parent readme file.

// Mega Assignments
#define BUTTON_PIN 5
#define ENC_RIGHT_PIN 3
#define ENC_LEFT_PIN  4
#define PIN_REQ 10
#define PIN_RDY 2
#define PIN_RST 9
#define INPUT_POLL_INTERVAL 500

//#define ANDROID_CENTRAL

//custom boards may override default pin definitions with BLEHIDPeripheral(PIN_REQ, PIN_RDY, PIN_RST)
BLEHIDPeripheral bleHIDPeripheral = BLEHIDPeripheral(PIN_REQ, PIN_RDY, PIN_RST);
BLEMultimedia bleMultimedia;
Encoder encoder(ENC_RIGHT_PIN, ENC_LEFT_PIN);
int buttonState;
unsigned long lastInputPollTime = 0;

void setup() {

   pinMode(PIN_REQ, OUTPUT);
   pinMode(PIN_RST, OUTPUT);
   Serial.begin(9600);

// etc...