Help with serial port Bluetooth module

Hi folks,

I have bluetooth module attached to arduino and connected (via bluetooth) to my android phone.

But the messages are intermittent splitted.

Arduino:

void loop(){
   Serial1.write("123456");
   delay(300);
}

Android log:

Received (6 bytes): 123456
Received (1 bytes): 1
Received (5 bytes): 23456
Received (1 bytes): 1
Received (5 bytes): 23456
and so on...

It's normal?
I should do a packaging method or something else? Maybe set messages with start and end mark..?

Maybe is a dumb question.. sorry, I'm a beginner.

thanks in advance!

Hi
On Android side did you test it with some proven terminal like BlueTerm ot SenaBterm ?
Is your Android version known for good serial port profile handling ?
If you stay under 57600 bauds no reason loose bytes in such short messages if Android appication is good.

Serial.write() is meant for sending individual bytes, not strings of characters. With nothing to indicate what constitutes a packet within a stream of data, the receiver is just guessing.

In this case, the Android application guessed wrong.

Thanks PaulS and al1fch.
After a 1 minute thinking.. I've found a solution.

I have a thread to listen bluetooth stream... but this thread don't have sleep time. It's so fast to listen arduino. :blush:

Maybe isn't a perfect solution, because still data are broken, however much less (~10%)

I'm using 9600 baud rate. My Android 2.2.
I've tested with BlueTerm too with same results.

Soon I will post here the source code.

thanks

Adding a sleep to the listener is a bandaid, and a poor one at that. Notice that when we communicate we use punctuation to tell when a sentence (a packet) ends and spaces to tell when a word ends (another kind of packet.

WhatissohardaboutdoingthesamethinginyourserialcommunicationItcompletelyeliminatestheconfusionorambiguityaboutwhatconstitutesapacket.

Serial1.write("123456");

I'm really surprised that works at all - I thought "write" took a single "byte" argument.

From Print.h:

    virtual void write(uint8_t) = 0;
    virtual void write(const char *str);
    virtual void write(const uint8_t *buffer, size_t size);

So, yes, there is an overload that takes a string.