Bluefruit function reference

Is there any documentation, like a function reference that describes the function calls and returns in the libraries (e.g. bluefruit) ?
Thanks,
Emmett

not sure what you mean with "function reference."
and what you mean with

How should a function-call return a library???
And how is this related to a certain board?
If the core for the board exists you can use almost any library for this board.

If this does not help
you have to describe with more words what you mean.
A good way to descfibe it is to make an example which describes one partical case

best regards Stefan

Hi Stefan,

Thanks for your reply.
By reference, I meant a document that describe a library's function, parameters and return variables.
The arduino reference link seems to be what I need, but I'm not sure what library I am dealing with.
I see an #include bluefruit.h
I am using nRF52832.
I want to know how to query if it is ready for bleuart.write because sometimes strings ar lost.

Thanks,
Emmett

I usually Google the name of the include file, which generally takes me to github. There you may find documentation, but usually at least some examples.

As that is an Adafruit library, you might also check their site for a tutorial.

This is a waaaaayyy to short description of the error you are encountering.

I want to know how to query if it is ready for bleuart.write because sometimes strings are lost.

what exactly is "it" ???

.write commands are mostly used for single bytes but not for strings (strings = a sequence of multiple bytes)

"some strings are lost".

possible reasons out of boundary reading? heapoverflow?

No idea without seeing the complete sketch that you are using.
best regards Stefan

Stefan,
I attached my sketch.
I started out this thread just looking for the documentation that describes the bluefruit library.
But I would like help about this particular issue.

I am sending 20 character strings via bleuart.write to the BLE Connect app, 15 of them as fast as possible.
I have been playing with delays as has been discussed in some forum posts.
More delay helps but never completely eliminates the missing strings.

My suspicion is that there is a FIFO or other mechanism that is not ready for another bleuart.write.

If there was a way to check if "it" (the FIFO, or interrupt or whatever) is ready for another bleuart.write, that would be a more robust way to avoid missing strings.

I hope that's a better explanation.

Thanks,
Emmett

BLE_Target2.ino (10.6 KB)

You should post code as a code-section

/*********************************************************************
 This is an example for our nRF52 based Bluefruit LE modules

 Pick one up today in the adafruit shop!

 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!

 MIT license, check LICENSE for more information
 All text above, and the splash screen below must be included in
 any redistribution
*********************************************************************/
#include <bluefruit.h>
#include <Adafruit_LittleFS.h>
#include <InternalFileSystem.h>

// BLE Service
BLEDfu  bledfu;  // OTA DFU service
BLEDis  bledis;  // device information
BLEUart bleuart; // uart over ble
BLEBas  blebas;  // battery

#define STATUS_LED (17)

int trigger=1;  
int triggerlast=0;
int StringWriteDelayVal=5;

void setup()
{
  Serial.begin(115200);

#if CFG_DEBUG
  // Blocking wait for connection when debug mode is enabled via IDE
  while ( !Serial ) yield();
#endif
  
  Serial.println("Bluefruit52 BLEUART Example");
  Serial.println("---------------------------\n");

  // Setup the BLE LED to be enabled on CONNECT
  // Note: This is actually the default behavior, but provided
  // here in case you want to control this LED manually via PIN 19
  Bluefruit.autoConnLed(true);

  // Config the peripheral connection with maximum bandwidth 
  // more SRAM required by SoftDevice
  // Note: All config***() function must be called before begin()
  Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);

  Bluefruit.begin();
  Bluefruit.setTxPower(4);    // Check bluefruit.h for supported values
  //Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections
  Bluefruit.Periph.setConnectCallback(connect_callback);
  Bluefruit.Periph.setDisconnectCallback(disconnect_callback);

  // To be consistent OTA DFU should be added first if it exists
  bledfu.begin();

  // Configure and Start Device Information Service
  bledis.setManufacturer("Adafruit Industries");
  bledis.setModel("Bluefruit Feather52");
  bledis.begin();

  // Configure and Start BLE Uart Service
  bleuart.begin();

  // Start BLE Battery Service
  blebas.begin();
  blebas.write(100);

  // Set up and start advertising
  startAdv();

  Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
  Serial.println("Once connected, enter character(s) that you wish to send");
}

void startAdv(void)
{
  // Advertising packet
  Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
  Bluefruit.Advertising.addTxPower();

  // Include bleuart 128-bit uuid
  Bluefruit.Advertising.addService(bleuart);

  // Secondary Scan Response packet (optional)
  // Since there is no room for 'Name' in Advertising packet
  Bluefruit.ScanResponse.addName();
  
  /* Start Advertising
   * - Enable auto advertising if disconnected
   * - Interval:  fast mode = 20 ms, slow mode = 152.5 ms
   * - Timeout for fast mode is 30 seconds
   * - Start(timeout) with timeout = 0 will advertise forever (until connected)
   * 
   * For recommended advertising interval
   * https://developer.apple.com/library/content/qa/qa1931/_index.html   
   */
  Bluefruit.Advertising.restartOnDisconnect(true);
  Bluefruit.Advertising.setInterval(32, 244);    // in unit of 0.625 ms
  Bluefruit.Advertising.setFastTimeout(30);      // number of seconds in fast mode
  Bluefruit.Advertising.start(0);                // 0 = Don't stop advertising after n seconds  
}

void loop()
{
  uint8_t counter=0;
  char buffer[64];
  int count;

  if(trigger != triggerlast)
  {
    triggerlast = trigger;
    WriteClearScreen();
    
    switch (trigger)
    {
      case 1:
        WriteLeftCol();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        break;
      
      case 2:        
        WriteCenterCol();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        break;

      case 3:
        WriteRightCol();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        break;

      case 4:
        WriteEmptyRow();
        WriteLeftCol();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        break;
      
      case 5:        
        WriteEmptyRow();
        WriteCenterCol();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        break;

      case 6:
        WriteEmptyRow();
        WriteRightCol();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        break;

      case 7:
        WriteEmptyRow();
        WriteEmptyRow();
        WriteLeftCol();
        WriteEmptyRow();
        WriteEmptyRow();
        break;
      
      case 8:        
        WriteEmptyRow();
        WriteEmptyRow();
        WriteCenterCol();
        WriteEmptyRow();
        WriteEmptyRow();
        break;

      case 9:
        WriteEmptyRow();
        WriteEmptyRow();
        WriteRightCol();
        WriteEmptyRow();
        WriteEmptyRow();
        break;

      case 10:
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteLeftCol();
        WriteEmptyRow();
        break;
      
      case 11:        
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteCenterCol();
        WriteEmptyRow();
        break;

      case 12:
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteRightCol();
        WriteEmptyRow();
        break;

      case 13:
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteLeftCol();
        break;
      
      case 14:        
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteCenterCol();
        break;

      case 15:
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteEmptyRow();
        WriteRightCol();
        break;

      default: // code to be executed if n doesn't match any cases
        WriteClearScreen();
        break;
    }


digitalToggle(STATUS_LED);
if(++trigger>15) trigger=1;
delay(3000);
}

//169,170,179,191,192,217,218
//bleuart.write( "⌐¬│┐└┘┌\n" );

//182,187,188,199,200,201,205,
//bleuart.write( "╢╗╝╟╚╔═\n" );

//bleuart.write( "    ╔════╗╔════╗╔════╗\n" );
//bleuart.write( "    ╟────╢╟────╢╟────╢\n" );
//bleuart.write( "    ╟────╢╟────╢╟────╢\n" );
//bleuart.write( "    ╚════╝╚════╝╚════╝\n" );

//176,177,178,219,220,221,222
//bleuart.write( "░▒▓█▄▌▐▀\n" );


//    sprintf(buffer,"Emmett Loves Lori\n");
//    sprintf(buffer,"%02d\n",counter++);
//    bleuart.write( buffer );

//digitalToggle(STATUS_LED);
//delay(1000);
//      bleuart.write( Clear_Screen );
//      bleuart.write( 0x0c );
//digitalToggle(STATUS_LED);
//delay(1000);
    

  
  // Forward data from HW Serial to BLEUART
  while (Serial.available())
  {
Serial.println("Serial.available");
    // Delay to wait for enough input, since we have a limited transmission buffer
    delay(2);
    uint8_t buf[64];
    int count = Serial.readBytes(buf, sizeof(buf));
    bleuart.write( buf, count );
  }

  // Forward from BLEUART to HW Serial
  while ( bleuart.available() )
  {
Serial.println("bleuart.available");
digitalToggle(STATUS_LED);
    uint8_t ch;
    ch = (uint8_t) bleuart.read();
    Serial.write(ch);
  }
  
}

void WriteEmptyRow (void)
{
  delay(StringWriteDelayVal);
  bleuart.write( "╔════╗╔════╗╔════╗\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╟────╢╟────╢╟────╢\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╟────╢╟────╢╟────╢\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╚════╝╚════╝╚════╝\n" );
  delay(StringWriteDelayVal);
}

void WriteLeftCol (void)
{
  bleuart.write( "██████╔════╗╔════╗\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "██████╟────╢╟────╢\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "██████╟────╢╟────╢\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "██████╚════╝╚════╝\n" );
  delay(StringWriteDelayVal);
}

void WriteCenterCol (void)
{
  bleuart.write( "╔════╗██████╔════╗\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╟────╢██████╟────╢\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╟────╢██████╟────╢\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╚════╝██████╚════╝\n" );
  delay(StringWriteDelayVal);
}

void WriteRightCol (void)
{
  bleuart.write( "╔════╗╔════╗██████\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╟────╢╟────╢██████\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╟────╢╟────╢██████\n" );
  delay(StringWriteDelayVal);
  bleuart.write( "╚════╝╚════╝██████\n" );
  delay(StringWriteDelayVal);
}

void WriteClearScreen (void)
{
  bleuart.write( "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" );
  delay(StringWriteDelayVal);
}

// callback invoked when central connects
void connect_callback(uint16_t conn_handle)
{
  // Get the reference to current connection
  BLEConnection* connection = Bluefruit.Connection(conn_handle);

  char central_name[32] = { 0 };
  connection->getPeerName(central_name, sizeof(central_name));

  Serial.print("Connected to ");
  Serial.println(central_name);
}

/**
 * Callback invoked when a connection is dropped
 * @param conn_handle connection where this event happens
 * @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
 */
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
  (void) conn_handle;
  (void) reason;

  Serial.println();
  Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}

a code-section has a limited height and enables with a single mouse-click in the top right corner to copy the whole sketch into the clipboard and then paste it into the editor

additionally you should describe in detail what you observe when running the code
your board bluefruit is not so popular. Your description will shorten the analysing time what is the bug a lot.

This description should include what string you expect and what string you get instead.

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.