system
December 28, 2012, 10:08pm
#1
Hi Arduino fans,
I have this weird thing going with my program. Basically I am transmitting a char buffer over Serial (bluetooth) but some parts get lost somewhere.
Example:
Serial bluetooth;
char buff[5];
buff[0] = 15;
buff[1] = 0;
buff[2] = 0;
buff[3] = 3;
buff[4] = 0;
bluetooth.write(buff);
bluetooth.write(13); <--- new line character
What happens is that I do receive the 15, but the rest is gone until the 13 (new line character)
However, if the buffer contains:
buff[0] = 15;
buff[1] = 1;
buff[2] = 1;
buff[3] = 3;
buff[4] = 0;
Then its ok.
My Android app logic is:
byte b = inputstream.read();
if(b==13) // the delimeter{
process the whole buffer;
}else{
add b to buffer;
}
What am I missing?
Thanks guys.
bluetooth.write( buff, sizeof(buff) );
system
December 28, 2012, 10:36pm
#3
I am using SoftwareSerial for the bluetooth but it seems that it does not like it:
v2.cpp: In function 'void sendBluetooth(message_t)':
v2:180: error: invalid conversion from 'char*' to 'const uint8_t*'
v2:180: error: initializing argument 1 of 'virtual size_t Print::write(const uint8_t*, size_t)'
Should I need some different serial library?
system
December 28, 2012, 10:44pm
#4
Should I need some different serial library?
No. The function expects one type of data. You have another. Lie to it; tell it you have what it expects:
bluetooth.write( (const uint8_t*) buff, sizeof(buff) );
Or change the data-type of buff …
uint8_t buff[5];
bluetooth.write(13); <--- new line character
13 is carriage-return.
If you want a newline:
bluetooth.write('\n');
If you really want a carriage-return:
bluetooth.write('\r');
system
December 28, 2012, 11:43pm
#7
Thank you gentlemen, I have sorted it out by changing the buff type to uint8_t.
Thanks again.