robotastic / ANCS-Library

Library to handle ANCS notifications with an AVR and Nordic's nrf8001
53 stars 8 forks source link

Arduino does not advertise #5

Closed DHayler closed 9 years ago

DHayler commented 9 years ago

Hi, I am trying to get this library working with an Arduino Uno, Adafruit Bluefruit LE and a 2x16 LCD. I have followed the steps in the readme file but the device doesn't advertise and as a result cannot be found by my iPhone however I do see the disconnected symbol on the LCD in the corner.

I have looked at some solutions and have tried putting the pins in on the notif.cpp file but nothing has made a difference. I have tried this on iPhone 4s (iOS7) and iPhone 5 (iOS8).

The pinouts: Bluefruit LE: SCK: 13 MISO: 12 MOSI: 11 REQ: 10 RST: 9 RDY: 2

LCD: lcd(8, 4, 5, 6, 7, 3)

I'm kind of lost for what to do now so any guidance would be greatly appreciated. Thanks

Here's the code 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 <LiquidCrystal.h>

#define LCD_SIZE 16
LiquidCrystal lcd(8, 4, 5, 6, 7, 3);

Notif notif(10,2);
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) {

    /*
     Serial.print (F("["));
     if ((notif->flags & ANCS_EVT_FLAG_SILENT) == ANCS_EVT_FLAG_SILENT)
     Serial.print(F("-"));
     else if ((notif->flags & ANCS_EVT_FLAG_IMPORTANT) == ANCS_EVT_FLAG_IMPORTANT)
     Serial.print(F("!"));
     else
     Serial.print(" ");
     Serial.print (F("] "));
     Serial.print(F("Notif #")); Serial.print( notif->uid); Serial.print( F(" ; from: '"));
     #ifdef ANCS_USE_APP
     Serial.print( notif->app);
     #endif
     Serial.println( F("'"));
     Serial.print(F("   category: "));
     switch (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:
     // Serial.println(F("social msg"));
     break;
     case ANCS_CATEGORY_OTHER:
     // Serial.println(F("other"));
     break;
     case ANCS_CATEGORY_SCHEDULE:
     // Serial.println(F("schedule"));
     break;
     case ANCS_CATEGORY_EMAIL:
     // Serial.println(F("email"));
     break;
     case ANCS_CATEGORY_NEWS :
     // Serial.println(F("news"));
     break;
     case ANCS_CATEGORY_HEALTH_FITNESS:
     // Serial.println(F("health & fitness"));
     break;
     case ANCS_CATEGORY_BUSINESS_FINANCE:
     //  Serial.println(F("business & finance"));
     break;
     case ANCS_CATEGORY_LOCATION:
     // Serial.println(F("location"));
     break;
     case ANCS_CATEGORY_ENTERTAINMENT:
     // Serial.println(F("entertainment"));
     break;
     default:
     Serial.print(F("unknown: "));
     Serial.println(notif->category, DEC);
     break;
     //return;
     }
     Serial.print(F("   title:    '")); Serial.print( notif->title    ); Serial.println("'");
     #ifdef ANCS_USE_SUBTITLE
     Serial.print(F("   subtitle: '")); Serial.print( notif->subtitle ); Serial.println("'");
     #endif
     Serial.print(F("   message:  '")); Serial.print( notif->message  ); Serial.println("'");*/

    current_notif = notif;
    message_char = 0;

}

void setup(void)
{
    Serial.begin(115200);   
    //Wait until the serial port is available (useful only for the Leonardo)
    //As the Leonardo board is not reseted every time you open the Serial Monitor
    /*
#if defined (__AVR_ATmega32U4__)
    while(!Serial)
    {}
#endif*/

    //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);

    Serial.println(F("Arduino setup"));
    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();
}
robotastic commented 9 years ago

Hmm - everything looks about right. I haven’t tried using AdaFruit’s board yet though. Try clearing the EEPROM by adding this into setup for one run: EEPROM.write(0, 0xFF); notif.ccp in the library uses the values defined for MISO and MOSI. It could be that those aren’t equal to what you are using? Maybe hard code them in, instead?

On Jan 2, 2015, at 5:13 PM, DHayler notifications@github.com wrote:

EEPROM.write(0, 0xFF);

DHayler commented 9 years ago

Hey thanks for the quick response. I've tried clearing the EEPROM as you suggested but it doesn't seem to have fixed the issue. I have also coded in the MISO and MOSI pins in the notif.ccp:

    //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;

    //We reset the nRF8001 here by toggling the RESET line connected to the nRF8001
    //and initialize the data structures required to setup the nRF8001
    //The second parameter is for turning debug printing on for the ACI Commands and Events so they be printed on the Serial
    lib_aci_init(&aci_state, false);
    aci_state.bonded = ACI_BOND_STATUS_FAILED;

... but this didn't seem to change anything either.

If there's anything else you suggest I try, that would be much appreciated.

DHayler commented 9 years ago

Closing this issue as it has been resolved. After following the advice given here and the Nordic Developer site, I found that inserting this code:

  pinMode(6, INPUT); //Pin #6 on Arduino -> PAIRING CLEAR pin: Connect to 3.3v to clear the pairing
  if (0x01 == digitalRead(6))
  {
    //Clear the pairing
    Serial.println(F("Pairing/Bonding info cleared from EEPROM."));
    Serial.println(F("Remove the wire on Pin 6 and reset the board for normal operation."));
    //Address. Value
    EEPROM.write(0, 0);
    while(1) {};

... connecting the pin to 3.3v, then resetting the board worked for me