Why am I seeing unexpected data at the start of an Android app when sending data to Arduino over bluetooth?

I am working on a group project where we send serial data over bluetooth from Arduino to Android. We're all pretty new on both Arduino and Android.

The hardware used includes the Arduino Uno R3 and HC-05 Bluetooth module.

I am sending dummy data for 3 axis accelerometer and am successfully viewing packet data from Android.

However, we have this block of data (roughly 50+ bytes and up to 512 bytes) that are always sent to the application at the beginning. Its a random byte size that we cannot interpret because it doesn't seem to match the packet format we configured for our data. We managed not to look at this byte, checking if the packet size is sufficient. But this adds a lot of overhead (4-5 seconds), so we would like to find out what this drop of data is. So, is the HC-05 sending some proprietary Bluetooth related data, or is there something wrong with my script, which results in unexpected data being sent?

This is the Arduino code.

#include <SoftwareSerial.h>
SoftwareSerial bluetooth(10,11);

void setup(){
  bluetooth.begin(9600);
}

void loop() {
  int x = random(360);
  int y = random(360);
  int z = random(360);
  formAccelerometerPacket(x, y, z); 
  delay(5000); // wait 5 sec
}

void formAccelerometerPacket(int xVal, int yVal, int zVal) {
  printSensorVal('A', xVal); 
  printSensorVal(':', yVal); 
  printSensorVal(':', zVal); 
}

void printSensorVal(char flag, int sensorVal) {
  bluetooth.print(flag);
  bluetooth.print(sensorVal);
}

      

I looked at it with a bluetooth connect app, but nothing works there. Its a LogCat from the application that shows this content received from the application, but I cannot interpret it as I said earlier and this is what I need to solve.

I tried to look at other questions but no one else could help me.

I don't have the code for an Android app like the other teammate, but I know they followed the BluetoothChat example closely.

The only thing I had was that since the Arduino is processing data, if the application starts after the Arduino starts up, it may start reading some of the data, in part from what was happening on the serial port before. But that doesn't explain the difference in byte size bytes.


Edit on 08.21.2014 at 10:33 AM PST

Here is a screenshot of the LogCat. We ran the Android app first and then I started Arduino to make sure the board has no old data. Looking at this, I think it might be a mating issue as some have suggested. I am working on trying to fix it.

logCat Output

+3


source to share


2 answers


Try Bluetooth SPP on Google Play, then connect to HC-05. Check the output and then once you get the clean data reset arduino and see what happens. This is, as usual, I am checking the output from my HC-05. And there is nothing to send the HC-05 when it starts up. I couldn't comment, so I had to post an answer, sorry.



+1


source


I'm not sure if this is your case, but it might be helpful. When you send data from HC-05 (FC-114) to slave (HC-06), the first byte (or the first three / four) is sent immediately and the rest is sent with a 5/10 ms delay. I don't know why, but I can see it with an oscilloscope. If you manage well, you can fix the problem when you receive a byte packet by waiting a while, otherwise you might go crazy to figure out what is going on.



0


source







All Articles