Sample code for BLE ADC Continuous Data Send

ANy Sample code for BLE   ADC Continuous Data Send 

  • No exaple is there so far, but the below sample helps you ?
    gadget.renesas.com/.../5.html
  • I have a working code that will use esp32 ble to transfer data as notification.Im not an expert in coding but the code will work sure.You need to install renesas gatt browser from playstore.Then run the code , scan for ble devices in renesas gatt browser,Then connect to the device ,After connecting you will see some characteristics, among them select notify characteristics, then turn on notification and stay on that window.Now press the ub0 button on the GR lychee board inorder to start recieving the analog values from A0 pin in every 1seconds.Code is posting below

  • int sent_flag=0;
    void ub0_interrupt()
    {
    sent_flag=1;
    }
    void setup()
    {
    Serial2.begin(115200);
    pinMode(PIN_ESP_IO0, OUTPUT);
    pinMode(PIN_ESP_EN, OUTPUT);
    digitalWrite(PIN_ESP_IO0, HIGH);
    digitalWrite(PIN_ESP_EN, LOW);
    delay(10);
    digitalWrite(PIN_ESP_EN, HIGH);
    pinMode(PIN_SW0, INPUT);
    attachInterrupt(4, ub0_interrupt, FALLING);
    delay(6000);
    Serial.begin(9600);
    while(Serial.available()>0)
    {
    Serial.write(Serial2.read());
    }
    setup_ble();
    Serial.println("bluetooth initialised");
    delay(1000);
    }
    void loop()
    {
    int analog_value=0;
    while(1)
    {
    analog_value=analogRead(A0);
    delay(1000);
    if(sent_flag)
    {
    sent_value(analog_value);
    }
    }
    }

    void sent_value(int value)
    {
    int l=len(value);
    Serial2.print("AT+BLEGATTSNTFY=0,1,6,");Serial2.print(l);
    send_with_response("",">",500);
    Serial2.println(value);

    }
    int len(int value)
    {
    if(value!=0)
    {
    int nDigits=floor(log10(abs(value)))+1;
    return nDigits;
    }
    return 0;
    }

    void setup_ble()
    {

    if(send_with_response("AT+BLEINIT=2","OK",1000))
    {
    Serial.println("bleinit");
    }
    if(send_with_response("AT+BLEGATTSSRVCRE","OK",1000))
    {
    Serial.println("gattcre");
    }
    if(send_with_response("AT+BLEGATTSSRVSTART","OK",1000))
    {
    Serial.println("gattstart");
    }
    if(send_with_response("AT+BLEADVSTART","OK",1000))
    {
    Serial.println("advstart");
    }
    }

    int send_with_response(char* data_to_send,char* expected_data,int wait_time)
    {
    char recieved_data[200];
    long cur,prev;
    int x=0;
    Serial2.println(data_to_send);
    cur=millis();
    prev=millis();
    while((cur-prev)<wait_time)
    {
    cur=millis();
    if(Serial2.available()>0)
    {
    recieved_data[x]=Serial2.read();
    Serial.print(recieved_data[x]);
    x++;
    }
    }
    recieved_data[x]='\0';
    Serial.print(recieved_data);
    if(strstr(recieved_data,expected_data)!=NULL)
    {
    return 1;
    }
    return 0;
    }

  • In reply to jihas:

    I tried this code but not worked..
  • In reply to guru:

    what is the error?
  • In reply to guru:

    I tried and now it works ! Device gets recognised.