2017년 8월 1일 화요일

Problem of data mismatch between arduino and android app


I have developed an android app which can show raw data of strain gauge and can calculate the force applied to it via Bluetooth through Arduino Uno. Usually, at the very beginning, it can work well, but a few seconds later the app cannot get along with the data transmitted from the arduino and there is mismatch of data (for example, if a sequence of numbers "8148888 8148070" is transmitted, it will get "148888", or even "148888 8148070" at one time. How to solve the problem? The best way is to provide an solution that can make the app auto-match the data. The worst way is to tell me the way to automatically ignore warning windows (the app can still work if I just ignore emerging warning notification by tapping blank areas). Thanks.

PS: the Android code:

#include <HX711.h>

#include <SoftwareSerial.h>
SoftwareSerial BT (2, 3); // RX, TX
#define DOUT  5
#define CLK  4

HX711 scale(DOUT, CLK);

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  scale.set_scale(1);
  BT.begin (9600);
}
void loop() {

  // put your main code here, to run repeatedly:
   long rawdata = (long)scale.get_units();
   delay(20);
   BT.println(rawdata);
  Serial.println(rawdata);
}
The App inventor blocks:



--
Your data stream is sliding around, making it hard to parse on the receiving end.

Set the AI2 BlueTooth Client Delimiter attribute in the Designer to 10.
(10 is the decimal equivalent of LF)
Also, in the Blocks Editor, set the BlueToothClient.ReceiveText to ask for -1 bytes.
This will feed you exactly one println() worth of data at a time.

Display the incoming data, so you can see how to process it more.

--

댓글 1개:

  1. QUANTUM BINARY SIGNALS

    Professional trading signals sent to your cell phone daily.

    Start following our signals today & profit up to 270% daily.

    답글삭제