Issue with not finding device until reset

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
natebc
 
Posts: 8
Joined: Wed May 12, 2021 2:21 pm

Issue with not finding device until reset

Post by natebc »

So I have an odd issue, I don't know if it's the central (Itsy Bitsy) or my peripheral.
When I boot up the Itsy it is programmed to find the peripheral device by its local name. Most of the time it works fine, but sometimes it cannot find the device at all while being able to find other devices. It's as if my peripheral is gone. I have found 3 ways to fix this.

1. If the device is not found within a fixed period of time upon powering on, I ground the Reset pin from one of the digital pins. Eventually (usually after 2 or 3 resets) the device is found or run the setupBT function again which does the same thing.
2. If I connect to the peripheral from my phone then disconnect, the Itsy finds the device.
3. There is a button for "pairing" on the peripheral that increases the advertising packet broadcast frequency.

All these solutions result in the device being found continually about every 4 seconds. I have had the same issue with another peripheral which leads me to believe it has something to do with the Itsy.

Code: Select all

#include <bluefruit.h>

uint8_t SENSORTAG_ADV_COMPLETE_LOCAL_NAME[] =            {0x53,0x45,0x45,0x4B,0x2D,0x30,0x31};  // SEEK-01

unsigned long int WDT = 0;
bool triggerWDT = true;

void setup() 
{
  Serial.begin(115200);
  //while (!Serial);
  delay(10);

  strip.begin(); // Initialize pins for output
  strip.setBrightness(80);
  strip.show();  // Turn all LEDs off ASAP

  pinMode(7,OUTPUT); // Unlock
  digitalWrite(7,LOW);
  pinMode(9,OUTPUT); // Lock
  digitalWrite(9,LOW);
  pinMode(10,OUTPUT); // WDT pin

  setupBT();
}

void setupBT(){
  // Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1
  // SRAM usage required by SoftDevice will increase dramatically with number of connections
  Bluefruit.begin(0, 1);
  Bluefruit.setTxPower(4);    // Check bluefruit.h for supported values
  Bluefruit.setName("Bluefruit52");

  // Start Central Scan
  Bluefruit.setConnLedInterval(1000);
  Bluefruit.Scanner.setRxCallback(scan_callback);
  Bluefruit.Scanner.start(0);
}

uint8_t buffer[BLE_GAP_ADV_SET_DATA_SIZE_MAX] = { 0 };
void scan_callback(ble_gap_evt_adv_report_t* report)
{

  // Reset controller if device cant be found in first 8 seconds
  
  if (triggerWDT == true){
    if (millis() - WDT > 6000){
      Serial.println("RESET");
      setupBT();
      WDT = millis();
    }
  }

  if(Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, buffer, sizeof(buffer)))
  {
    triggerWDT = false;
    Serial.println("Found");
    buffer[BLE_GAP_ADV_SET_DATA_SIZE_MAX] = { 0 };
    int rssi = report->rssi;
    Serial.println(rssi);
  }
  Bluefruit.Scanner.resume();
}

void loop() 
{
  // nothing to do
}

This is not an ideal fix, but this is the code I have to run to ensure my device can be found initially. Any ideas on what is going on here?

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”