robotastic / ANCS-Library

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

IPhone Connection Issue #17

Open walle515 opened 3 years ago

walle515 commented 3 years ago

Hi, i was having a problem with the code. Before i get into that, i want to thank you for posting this code to the public. I am really appreciating the use of the code.

I understand its been a couple years since this has gotten an update, but i was having some issues and i was hoping you could help. I took your code and have been trying to convert it to work with a 128x64 OLED screen. I had to swap to an Arduino Mega 2560 in order to handle the memory. I am also trying to use the Bluefruit chip, the "Adafruit Bluefruit LE SPI Friend" which seemed to be similar to what was mentioned in the previous discussions and in the code.

The issue im having is i cannot see the device on my phone. I even uploaded the example and made sure it wouldnt conflict with the hardware, and still no luck. Im not sure if i just have something wired wrong or if there is a bug in either the library or in my code. I have also tried everything ive seen on the ReadMe and in the discussions. Nothing has seemed to work for me

If you are willing and able to help, it would be much appreciated. Below will be how im wiring it and the code i have

SCK, MOSI, MISO connected to 52, 51, 50 respectively IRQ on pin 20 (pinout shows it to be int1 for Mega) CS on pin 3 RST on pin 9 DFU unused

Here is my code. Again, its a work in progress, and I dont mean to have the notifications working perfectly yet, but i just want to at least connect.

include

include

include

include

include

include

include

define SCREEN_WIDTH 128 // OLED display width, in pixels

define SCREEN_HEIGHT 64 // OLED display height, in pixels

define charPerLine1 25

define charPixelHeight1 7

define charPixelWidth1 5

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)

define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

define LOGO_HEIGHT 64

define LOGO_WIDTH 44

static const unsigned char PROGMEM logo_bmp[] = { 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x61, 0xff, 0xf8, 0x60, 0x00, 0x01, 0x81, 0xff, 0xf8, 0x18, 0x00, 0x03, 0x01, 0xff, 0xf8, 0x0c, 0x00, 0x04, 0x01, 0xff, 0xf8, 0x03, 0x00, 0x08, 0x00, 0xff, 0xf0, 0x01, 0x80, 0x10, 0x00, 0xff, 0xf0, 0x00, 0x80, 0x10, 0x00, 0xff, 0xf0, 0x00, 0x40, 0x10, 0x00, 0xff, 0xf0, 0x00, 0x40, 0x10, 0x00, 0x7f, 0xe0, 0x00, 0x40, 0x10, 0x00, 0x7f, 0xe0, 0x00, 0x40, 0x10, 0x00, 0x7f, 0xe0, 0x00, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x70, 0x63, 0xe0, 0x00, 0x00, 0x3e, 0x70, 0x67, 0xff, 0xff, 0xff, 0xff, 0x70, 0x67, 0xff, 0xc0, 0x1f, 0xff, 0x30, 0x40, 0xfc, 0x00, 0x01, 0xf8, 0x30, 0x40, 0x00, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x30, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x60, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x60, 0x68, 0x00, 0x00, 0x00, 0x00, 0x60, 0x74, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x76, 0x00, 0x00, 0x00, 0x02, 0xe0, 0x76, 0x00, 0x00, 0x00, 0x06, 0xe0, 0x7b, 0x00, 0x00, 0x00, 0x0d, 0xe0, 0x7b, 0x00, 0x00, 0x00, 0x0d, 0xe0, 0x39, 0x80, 0x00, 0x00, 0x1b, 0xc0, 0x3d, 0x80, 0x00, 0x00, 0x1f, 0xc0, 0x3c, 0x80, 0x00, 0x00, 0x17, 0xc0, 0x3e, 0xc0, 0x00, 0x00, 0x2f, 0xc0, 0x3f, 0x40, 0x00, 0x00, 0x2f, 0xc0, 0x3f, 0x43, 0xff, 0xf8, 0x5f, 0xc0, 0x1f, 0xa4, 0xff, 0xe4, 0x5f, 0x80, 0x1f, 0x1c, 0x00, 0x06, 0x9f, 0x80, 0x1f, 0x08, 0x00, 0x03, 0x1f, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x0f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x07, 0x83, 0xff, 0xf0, 0x1f, 0x00, 0x03, 0xc7, 0xff, 0xf8, 0x3e, 0x00, 0x01, 0xff, 0xff, 0xfe, 0x7c, 0x00, 0x00, 0xff, 0xff, 0xfe, 0xf0, 0x00, 0x00, 0x6f, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x3c, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00 };

Notif notif(3,20); ancs_notification_t* current_notif = NULL; uint8_t message_char = 0;

// Pins in use

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

void ancs_connected() { connected = true; Serial.println("Connected"); } void ancs_disconnected() { connected = false; Serial.println("Disconnected"); }

void ancs_reset() { connected = false; Serial.println("Reset"); /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 eepromWrite(int address, uint8_t value) { eeprom_write_byte((unsigned char *) address, value); }

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.
//eepromWrite(0, 0xFF);

Serial.begin(9600);

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever

}

// Show initial display buffer contents on the screen -- // the library initializes this with an Adafruit splash screen. display.clearDisplay(); display.clearDisplay(); display.drawBitmap(0,0,logo_bmp,LOGO_WIDTH,LOGO_HEIGHT,1);

display.setCursor(48,31);
display.setTextColor(WHITE);
display.setTextSize(1);
display.println("Connecting...");
display.display();

Serial.println("Setting up BT");

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

Serial.println("Should be done setting up");
/*
lcd.clear();
lcd.setCursor(0,0);
lcd.print("    Apple iOS   ");
lcd.setCursor(0,1);
lcd.print(" Notifications  ");
*/

}

void update_lcd() { int messageLength = 0;

display.clearDisplay();

if (current_notif) {

    display.setCursor(0,0);
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.println(current_notif->title);

    messageLength = strlen(current_notif->message);
    for(int i=0;i<messageLength;i++){
      if((i%25) == 24){
        display.println(current_notif->message[i]);
      }
      else{
        display.print(current_notif->message[i]);
      }
    }

}
else{
  display.setCursor(0,0);
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.println("Connected");
}

screen_update_timer = millis();

}

void loop() { if((millis() - screen_update_timer) > 100) { update_lcd(); }

notif.ReadNotifications();

}