Go Down

Topic: Help with serial port Bluetooth module (Read 1 time) previous topic - next topic

emoretto

Hi folks,

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

But the messages are intermittent splitted.

Arduino:
Code: [Select]

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


Android log:
Code: [Select]

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!
Emerson Moretto

al1fch

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.

PaulS

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.

emoretto

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.  :smiley-red:

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

Emerson Moretto

PaulS

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.

AWOL

Code: [Select]
Serial1.write("123456");
I'm really surprised that works at all - I thought "write" took a single "byte" argument.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

From Print.h:
Code: [Select]
    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.

Go Up