ANCS-Library icon indicating copy to clipboard operation
ANCS-Library copied to clipboard

Cannot connect to phone (does not advertise?)

Open adamzaninovich opened this issue 10 years ago • 14 comments

Hi, I'm trying to get this library to work with an Arduino Micro, an Adafruit nRF8001 Breakout and an OLED 16x2 display. I removed the code from the example that was specific to the lcd shield used in the original example, and I do see the disconnected icon flashing in the corner of the display, but I can't get the project to show up on my iPhone under the bluetooth settings.

I've tried both iOS 7 (iPhone 5) and iOS8 (iPhone 6). I also pulled the latest library code as of a few hours ago (Fixed for iOS 8 - dff14e9)

I'm not sure what else to try. Any ideas? Any help would be greatly appreciated.

Here is the sketch I'm using:

//
//  ancs_lcd.ino
//
//
//  Created by Luke Berndt on 8/24/14.
//
//
#include <lib_aci.h>
#include <SPI.h>
#include <EEPROM.h>

#include <notif.h>
#include <Adafruit_CharacterOLED.h>

#define LCD_SIZE 16
#define BLE_REQ 10
#define BLE_RDY 2

Adafruit_CharacterOLED lcd(OLED_V2, 6, 7, 8, 4, 5, 11, 12);

Notif notif(BLE_REQ, BLE_RDY);
ancs_notification_t* current_notif = NULL;
uint8_t message_char = 0;

byte antenna_char[8] = {
    B00000,
    B00000,
    B00000,
    B00100,
    B00100,
    B00100,
    B01110,
};

byte connected_char[8] = {
    B00000,
    B01110,
    B10001,
    B00100,
    B00100,
    B00100,
    B01110,
};

byte disconnected_char[8] = {
    B00000,
    B01010,
    B00100,
    B01010,
    B00100,
    B00100,
    B01110,
};

byte text_char[8] = {
    B00000,
    B01110,
    B01110,
    B01010,
    B01010,
    B01110,
    B00000,
};

byte email_char[8] = {
    B00000,
    B11111,
    B11011,
    B10101,
    B10001,
    B11111,
    B00000,

};

char wait = ' ';
unsigned long screen_update_timer = 0;
boolean connected = false;

void ancs_connected() {
    connected = true;
}
void ancs_disconnected() {
    connected = false;
}

void ancs_reset() {
    connected = false;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(" Bond Cleared ");
    lcd.setCursor(0,1);
    lcd.print("Please Reset");
}

void ancs_notifications(ancs_notification_t* notif) {
    current_notif = notif;
    message_char = 0;
}

void setup(void) {
    //If things get really crazy, uncomment this line. It wipes the saved EEPROM information for the Nordic chip. Good to do this if the services.h file gets updated.
    //After it is wiped, comment and reupload.
    //EEPROM.write(0, 0xFF);

    notif.setup();
    notif.set_notification_callback_handle(ancs_notifications);
    notif.set_connect_callback_handle(ancs_connected);
    notif.set_disconnect_callback_handle(ancs_disconnected);
    notif.set_reset_callback_handle(ancs_reset);
    lcd.begin(LCD_SIZE, 2);
    lcd.createChar(0, antenna_char);
    lcd.createChar(1, connected_char);
    lcd.createChar(2, disconnected_char);
    lcd.createChar(3, text_char);
    lcd.createChar(4, email_char);

    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    Apple iOS   ");
    lcd.setCursor(0,1);
    lcd.print(" Notifications  ");
}

void update_lcd() {
    lcd.clear();

    if (current_notif) {

        lcd.setCursor(2,0);
        lcd.print(current_notif->title);
        lcd.setCursor(0,0);

        switch (current_notif->category) {
            case ANCS_CATEGORY_INCOMING_CALL:
                //Serial.println(F("incoming call"));
                break;
            case ANCS_CATEGORY_MISSED_CALL:
                //Serial.println(F("missed call"));
                break;
            case ANCS_CATEGORY_VOICEMAIL:
                // Serial.println(F("voicemail call"));
                break;
            case ANCS_CATEGORY_SOCIAL:
                lcd.print((char)3);
                break;
            case ANCS_CATEGORY_OTHER:
                // Serial.println(F("other"));
                break;
            case ANCS_CATEGORY_SCHEDULE:
                // Serial.println(F("schedule"));
                break;
            case ANCS_CATEGORY_EMAIL:
                lcd.print((char)4);
                break;
        }

        lcd.setCursor(0,1);
        lcd.print(&(current_notif->message[message_char]));
        if (strlen(current_notif->message) >= LCD_SIZE) {
            message_char++;
            if (message_char == strlen(current_notif->message)) {
                message_char = 0;
            }
        }
    }

    lcd.setCursor(15,0);
    lcd.print(wait);
    if (wait == 0) {
        if (connected){
            wait = 1;
        }else {
            wait = 2;
        }
    } else {
        wait=0;
    }
    screen_update_timer = millis();
}

void loop() {
    if((millis() - screen_update_timer) > 1000) {
        update_lcd();
    }    
    notif.ReadNotifications();
}

adamzaninovich avatar Sep 21 '14 10:09 adamzaninovich

That’s awesome, definitely let me know how it goes. There are a couple things you might want to try. In Notif.cpp there are the lines around 793 that handle the setup of the nRF8001. I haven’t used the breakout board. Right now it is setup to use the SPI pins. You might be using different pins, so probably best to hardwire everything in there. Also, if you have anything stored in EEPROM, try clearing it out. Try uncommenting line 218 in the .INO file: EEPROM.write(0, 0xFF);

Since it is not showing up on the iOS, there is some basic stuff not working. I would look into the library files. Turn on the logging in Notif.cpp and see if there are any clues there.

On Sep 21, 2014, at 6:11 AM, Adam Zaninovich [email protected] wrote:

Hi, I'm trying to get this library to work with an Arduino Micro, an Adafruit nRF8001 Breakout https://www.adafruit.com/product/1697 and an OLED 16x2 display https://www.adafruit.com/products/823. I removed the code from the example that was specific to the lcd shield used in the original example, and I do see the disconnected icon flashing in the corner of the display, but I can't get the project to show up on my iPhone under the bluetooth settings.

I've tried both iOS 7 (iPhone 5) and iOS8 (iPhone 6). I also pulled the latest library code as of a few hours ago (Fixed for iOS 8 - dff14e9 https://github.com/robotastic/ANCS-Library/commit/dff14e98cf0374b38902777bb0d0d7412c7eba45)

I'm not sure what else to try. Any ideas? Any help would be greatly appreciated.

Here is the sketch I'm using:

// // ancs_lcd.ino // // // Created by Luke Berndt on 8/24/14. // // #include <lib_aci.h> #include <SPI.h> #include <EEPROM.h>

#include <notif.h> #include <Adafruit_CharacterOLED.h>

#define LCD_SIZE 16 #define BLE_REQ 10 #define BLE_RDY 2

Adafruit_CharacterOLED lcd(OLED_V2, 6, 7, 8, 4, 5, 11, 12);

Notif notif(BLE_REQ, BLE_RDY); ancs_notification_t* current_notif = NULL; uint8_t message_char = 0;

byte antenna_char[8] = { B00000, B00000, B00000, B00100, B00100, B00100, B01110, };

byte connected_char[8] = { B00000, B01110, B10001, B00100, B00100, B00100, B01110, };

byte disconnected_char[8] = { B00000, B01010, B00100, B01010, B00100, B00100, B01110, };

byte text_char[8] = { B00000, B01110, B01110, B01010, B01010, B01110, B00000, };

byte email_char[8] = { B00000, B11111, B11011, B10101, B10001, B11111, B00000,

};

char wait = ' '; unsigned long screen_update_timer = 0; boolean connected = false;

void ancs_connected() { connected = true; } void ancs_disconnected() { connected = false; }

void ancs_reset() { connected = false; lcd.clear(); lcd.setCursor(0,0); lcd.print(" Bond Cleared "); lcd.setCursor(0,1); lcd.print("Please Reset"); }

void ancs_notifications(ancs_notification_t* notif) { current_notif = notif; message_char = 0; }

void setup(void) { //If things get really crazy, uncomment this line. It wipes the saved EEPROM information for the Nordic chip. Good to do this if the services.h file gets updated. //After it is wiped, comment and reupload. //EEPROM.write(0, 0xFF);

notif.setup();
notif.set_notification_callback_handle(ancs_notifications);
notif.set_connect_callback_handle(ancs_connected);
notif.set_disconnect_callback_handle(ancs_disconnected);
notif.set_reset_callback_handle(ancs_reset);
lcd.begin(LCD_SIZE, 2);
lcd.createChar(0, antenna_char);
lcd.createChar(1, connected_char);
lcd.createChar(2, disconnected_char);
lcd.createChar(3, text_char);
lcd.createChar(4, email_char);

lcd.clear();
lcd.setCursor(0,0);
lcd.print("    Apple iOS   ");
lcd.setCursor(0,1);
lcd.print(" Notifications  ");

}

void update_lcd() { lcd.clear();

if (current_notif) {

    lcd.setCursor(2,0);
    lcd.print(current_notif->title);
    lcd.setCursor(0,0);

    switch (current_notif->category) {
        case ANCS_CATEGORY_INCOMING_CALL:
            //Serial.println(F("incoming call"));
            break;
        case ANCS_CATEGORY_MISSED_CALL:
            //Serial.println(F("missed call"));
            break;
        case ANCS_CATEGORY_VOICEMAIL:
            // Serial.println(F("voicemail call"));
            break;
        case ANCS_CATEGORY_SOCIAL:
            lcd.print((char)3);
            break;
        case ANCS_CATEGORY_OTHER:
            // Serial.println(F("other"));
            break;
        case ANCS_CATEGORY_SCHEDULE:
            // Serial.println(F("schedule"));
            break;
        case ANCS_CATEGORY_EMAIL:
            lcd.print((char)4);
            break;
    }

    lcd.setCursor(0,1);
    lcd.print(&(current_notif->message[message_char]));
    if (strlen(current_notif->message) >= LCD_SIZE) {
        message_char++;
        if (message_char == strlen(current_notif->message)) {
            message_char = 0;
        }
    }
}

lcd.setCursor(15,0);
lcd.print(wait);
if (wait == 0) {
    if (connected){
        wait = 1;
    }else {
        wait = 2;
    }
} else {
    wait=0;
}
screen_update_timer = millis();

}

void loop() { if((millis() - screen_update_timer) > 1000) { update_lcd(); }
notif.ReadNotifications(); } — Reply to this email directly or view it on GitHub https://github.com/robotastic/ANCS-Library/issues/1.

robotastic avatar Sep 21 '14 11:09 robotastic

Thanks! I will try all that and report back.

adamzaninovich avatar Sep 21 '14 14:09 adamzaninovich

I was able to get it to work!

Notif working

I had to edit the code in notif.cpp around line 799 and tell it to use the reset pin and interrupt mode:

aci_state.aci_pins.reset_pin              = 9; // was UNUSED
aci_state.aci_pins.active_pin             = UNUSED;
aci_state.aci_pins.optional_chip_sel_pin  = UNUSED;

aci_state.aci_pins.interface_is_interrupt = true; // was false
aci_state.aci_pins.interrupt_number       = 1; // (on the Micro/Leo, pin2 is int1) was UNUSED

adamzaninovich avatar Sep 21 '14 15:09 adamzaninovich

Great to hear!

That looks really slick too. Now I want to get an OLED.

I will add a section to the readme.md

On Sep 21, 2014, at 11:30 AM, Adam Zaninovich [email protected] wrote:

I was able to get it to work!

https://camo.githubusercontent.com/2e8f98af12c6a6c995cc974f3a37329002e4e68d/687474703a2f2f692e696d6775722e636f6d2f634539367a32642e706e67 I had to edit the code in notif.cpp around line 799 and tell it to use the reset pin and interrupt mode:

aci_state.aci_pins.reset_pin = 9; // was UNUSED aci_state.aci_pins.active_pin = UNUSED; aci_state.aci_pins.optional_chip_sel_pin = UNUSED;

aci_state.aci_pins.interface_is_interrupt = true; // was false aci_state.aci_pins.interrupt_number = 1; // (on the Micro/Leo, pin2 is int1) was UNUSED — Reply to this email directly or view it on GitHub https://github.com/robotastic/ANCS-Library/issues/1#issuecomment-56302259.

robotastic avatar Sep 21 '14 18:09 robotastic

Actually, if you get a chance to try it out with iOS 8, can you test something?

When I reset the arudino / ble board, my iPhone connects and sees it, but ANCS isn't turned on and it doesn't work again until I turn bluetooth off and on in iOS. Does it work for you?

let me know if you come across any bugs.

robotastic avatar Sep 21 '14 18:09 robotastic

I have the same problem. My phone not detect any new bluetooth device. I have iOS 8 on iPhone 5. I'll try the new version you have uploaded and see if the problem is corrected. I use an Adafruit nRF8001.

Thanks for de code!

M0dusFRee avatar Sep 22 '14 23:09 M0dusFRee

which version of Arduino are you using? 1.0.5, 1.0.6 or 1.5.7 BETA?

M0dusFRee avatar Sep 23 '14 12:09 M0dusFRee

I am using 1.0.5 - what are you using for Bluetooth LE HW? Make sure you have all the pins declared correctly. With the shield the req and redy pins are settable, so make sure you are passing your config. Also try uncommenting the line that clears the EEPROM on the arduino. You could have something funky there.

On Tue, Sep 23, 2014 at 8:30 AM, M0dusFRee [email protected] wrote:

which version of Arduino are you using? 1.0.5, 1.0.6 or 1.5.7 BETA?

— Reply to this email directly or view it on GitHub https://github.com/robotastic/ANCS-Library/issues/1#issuecomment-56512159 .

robotastic avatar Sep 23 '14 13:09 robotastic

Im having problems whilst using the Red Bear Labs shield. The jumpers are set to REQN = 12 and RDYN = 11. I have then set these values in the Arduino sketch and in the notif.cpp file accordingly. My Ipad (ios 7) doesn't see the Arduino and shield as a bluetooth device. I have tried clearing the EEPROM but no change.

Any help would be greatly appreciated.

ece00244 avatar Sep 25 '14 12:09 ece00244

Hi I am trying to reproduce the connection with an iphone 6 plus (ios 8.2) and the nrf8001 from adafruit and I couldn't get this work. (I am using IDE 1.0.6)

I can't even find the bluetooth module under the devices section on the iphone setting.

Here is my Arduino code, I am trying a simple code at least to detect my bluetooth with my phone

#include "lib_aci.h"
#include "SPI.h"
#include "EEPROM.h"
#include "notif.h"

Notif notif(10,2);

void setup()
{

  Serial.begin(9600);
//  EEPROM.write(0, 0xFF);
  notif.setup();
  notif.set_notification_callback_handle(ancs_notifications);
  notif.set_connect_callback_handle(ancs_connected);
  notif.set_disconnect_callback_handle(ancs_disconnected);
}

void loop()
{
  notif.ReadNotifications();
}
void ancs_notifications(ancs_notification_t* notif) {
  Serial.println('1');
}
void ancs_connected() {
    Serial.println('2');
}
void ancs_disconnected() {
  Serial.println('3');
}

And I modified the Notif.cpp line:795

//Tell the ACI library, the MCU to nRF8001 pin connections
    aci_state.aci_pins.board_name = BOARD_DEFAULT; //See board.h for details
    aci_state.aci_pins.reqn_pin   = 10;            //The REQN and RDYN jumpers are settable, make sure this is the same
    aci_state.aci_pins.rdyn_pin   = 2;
    aci_state.aci_pins.mosi_pin   = 11;
    aci_state.aci_pins.miso_pin   = 12;
    aci_state.aci_pins.sck_pin    = 13;

    aci_state.aci_pins.spi_clock_divider      = SPI_CLOCK_DIV8;//SPI_CLOCK_DIV8  = 2MHz SPI speed
    //SPI_CLOCK_DIV16 = 1MHz SPI speed

    aci_state.aci_pins.reset_pin              = 9; //4 for Nordic board, UNUSED for REDBEARLABS
    aci_state.aci_pins.active_pin             = UNUSED;
    aci_state.aci_pins.optional_chip_sel_pin  = UNUSED;

    aci_state.aci_pins.interface_is_interrupt = true;
    aci_state.aci_pins.interrupt_number       = 2;

Can anyone help ? (I did the reset thing and still nothing...) Thank you

DokRaphael avatar Apr 10 '15 09:04 DokRaphael

@DokRaphael I would double all the pins you put down. Are you using pin 2, twice? Are you able to get the Nordic examples running? https://github.com/NordicSemiconductor/ble-sdk-arduino My code is based on that.

robotastic avatar Apr 10 '15 11:04 robotastic

@ece00244 Did you ever get things working?

robotastic avatar Apr 10 '15 11:04 robotastic

@robotastic I did pull again and updated to 8.3 and now it works. I think that ios 8.2 has a problem with pairing with new devices.

Now I can pair with my iPhone but it disconnects right away with a error code :

Evt Command Response: : Error 8D

and sometimes

Advertising started. Bonding. Dissconnect status: 3
BTLE status: 24
Evt Command Response: : Success!
Bond

DokRaphael avatar Apr 10 '15 12:04 DokRaphael

Finally i did "forget this device" on the iphone settings and paired it again, now it works ! thank you !

DokRaphael avatar Apr 10 '15 12:04 DokRaphael