Bluno Beetle Continues Data Receivement?

53 Views Asked by At

So i am sending data from my flutter app over ble to my bluno beelte v1.1 (firmware update v1.97) and i see the rx LED light up the instant i send the data over, but it gets posted in the serial port only after all the data has been sent. It groups the last couple seconds of data together and prints it in one go. However i need it to send it to the serial port the instant it gets it.

How can i accomplish this?

here the code on the arduino:

#include <Adafruit_NeoPixel.h>
#include <Servo.h>

int estPin = 5;
int servoPin = 2;
int pixelPin = 3;

int pixelNum = 1;

int data;

Servo servo;
Servo esc;

String command;
String r;
String g;
String b;

int color[3] = {150, 0, 0};

Adafruit_NeoPixel pixels(pixelNum, pixelPin, NEO_GRB + NEO_KHZ800);

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

  servo.attach(servoPin);
  esc.attach(estPin);

  delay(7000);
}

void loop() {
  if(Serial.available()) {
    data = Serial.read();
    command = Serial.readStringUntil('\n');

    Serial.print("command: ");
    Serial.println(command);

    String code = command.substring(0,3);
    if(code == "rgb")
    {
      String rgb = command.substring(3,command.length());
      String c[3];
      int index = 0;
      for (int i=0;i<3;i++){
        index = rgb.indexOf(' ');
        c[i] = rgb.substring(0, index);
        rgb = rgb.substring(index+1);

        color[i] = c[i].toInt();
      }

      pixels.clear();
      for(int i=0; i<pixelNum; i++) {

        pixels.setPixelColor(i, pixels.Color(color[0], color[1], color[2]));
        pixels.show();
      }
    }
    else if(code == "srv")
    {
      String value = command.substring(3,6);
      servo.write(value.toInt());
      Serial.println(value);
    }
    else if(code == "mtr")
    {
      String Svalue = command.substring(3,6);
      int value = Svalue.toInt();
      value = map(value, 0, 100, 1100, 1900);
      esc.writeMicroseconds(value);
      Serial.println(value);
    }
  }  
}
1

There are 1 best solutions below

0
On

i found that if you use software serial to open a serialport on the rx tx pins of the bluno beetle, and then attach an interupt you can get the data emediatly after it gets received by the beetle.

here is my code snippet:

SoftwareSerial bleSerial(0,1);

void setup()
{
  bleSerial.begin(115200);
  attachInterrupt(0, handleBLEInterrupt, FALLING);
}

void handleBLEInterrupt()
{
 char data = bleSerial.read();  
 //do your thing here
}