This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Hello, I am using BLE shield from Redbear Lab v2.1, with nRF 8001 BLE chip on it, with Arduino UNO- how to find connection interval

I want to get sensor data from arduino, with atleast 200 samples per second, but at present I am only getting around 20 samples per second. I went through forums and got to know that nRF8001 can send only 1 data packet per connection event, and the RBL_nRF8001.cpp file tells, I can send upto 64 bytes of data each packet. Thus, I am able to send 64 bytes data in each connection event, so now I need to know what is the default connection interval for this nRF8001, so that I can calculate what no of bytes I can transfer in 1 second, ( I need 200 samples of 10 bit sensor value from Arduino). I installed nRF go studio to check connection interval, but I don’t know how can I find it. Can someone tell me where to look for some proper explanation to use nrf go studio, and find connection interval or how to create my own service so that i can set the parameters as i want. I am new to BLE and to Arduino, it would be helpful if anyone can help me and also suggest if I am going wrong. Thank you

  • Hey.
    Can you post you code, and also links to the Arduino library you are using?

  • Yeah. I am using Simple chat, from the BLE controller app of Red bear lab, to send character and see data, if I press 'a', the Arduino starts sending data, if I send b it stops. In the code I have used sprintf and pointers because I am separating the data as individual digits, and sending each digit as 1 byte

    #include <SPI.h>
    #include <EEPROM.h>
    #include <boards.h>
    #include <RBL_nRF8001.h>
    
    int analogPin = 3;
    int z;
    void setup()
    {  
        ble_begin();
        Serial.begin(57600);
    }
    void loop()
    {
      if ( ble_available() )
      {     z=ble_read();
            if(z==97)
            {
              bailout:
              while( ble_available()==0 )
              {
                int val= analogRead(analogPin);
                int b[1]={val};
                char msg[100]={0};
                char *p=msg;
                int j;
                if(val<1000) j=3;
                else if(val<100) j=2;
                else if(val<10) j=1;
                else j=4;
               for(int i=0;i<j;i++)
                    {
                       sprintf(p +=strlen(p),"%d",b[i]);
                       ble_write(msg[i]);
                    }
            ble_do_events();
            }
            z=ble_read();
            if( z==98 )
            {
              ble_do_events();
            }
            else goto bailout;   
        }
        else Serial.print("Failed\n");
        ble_do_events();
     }
    ble_do_events();
    }
    
  • Hello.

    It seems that the library has a 64 byte TX buffer. This does not mean that it can send 64 bytes in one packet over BLE. The limit for BLE is 20 bytes/packet (at the moment).

    I found the library you are using here. I recommend you to include relevant links in future posts to make is easier for others to help you.

    In RBL_services.h, we find the following:

    #define GAP_PPCP_MAX_CONN_INT 0x12 /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
    #define GAP_PPCP_MIN_CONN_INT  0x6 /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific maximum*/
    

    This means that we have worst case connection interval of 22.5 ms, a best case of 7.5 ms. This gives a theoretical throughput between ~21.3 kbps and ~7 kbps. You need 200*10bit = 2 kbps for you application, so this should work.

    Can you try to measure how often you use ble_write and ble_do_events, the arduino function micros() should help you with that.

Related