Hello !
I'm running this little snippet of code to test my new Bluetooth module (BlueSMiRF Silver (RN-42)) :
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
int bluetoothTx = 9 ;
int bluetoothRx = 8 ;
String inData;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
LiquidCrystal lcd(2,3,4,5,6,7);
void setup()
{
Serial.begin(9600);
delay(100);
bluetooth.begin(115200);
bluetooth.print("$$");
delay(100);
bluetooth.println("U,9600,N");
bluetooth.begin(9600);
delay(100);
lcd.begin(16,2);
lcd.clear();
}
void loop()
{
while (bluetooth.available() > 0) {
char recu = bluetooth.read() ;
inData += recu ;
if (recu == '
See the for-loop commented at the end ? When it's activated, I can only receive data up to 63 bytes at a time. What I do to test it : I open minicom on the serial port. Everything works fine for short strings (I use my Android smartphone to send them), such as "aaaa$". It displays :
Data received : aaaa$
But when I send a string that is longer than 63 characters, only the 63 first characters are sent, the next ones are lost. Since the "$" is after the 63 first characters, nothing is displayed. The 63 characters are added to inData nonetheless. So when I then send a short string such as "aaaa$", it gets added to InData itself and the "$" triggers the displaying of everything and the emptying of inData :
Data received: longstring_longstring_longstring_longstring_[imagine a lot of characters here]_longstring_end_of_longstringaaaa$
When the last lines of the code are commented, such as what I've pasted here, everything is passed right away, even veeery long strings.
Anyone know why it behaves like that, and what I could do in the eventuality where the loop() function has to perform a lot of operations AND I have to transmit long strings in one shot ?
Thank you !) {
Serial.print("Data received :");
Serial.println(inData);
inData = "";
}
}
/for(int i=0 ; i<1000 ; i++) {
int victim = random(1,1000);
}/
}
See the for-loop commented at the end ? When it's activated, I can only receive data up to 63 bytes at a time. What I do to test it : I open minicom on the serial port. Everything works fine for short strings (I use my Android smartphone to send them), such as "aaaa$". It displays :
> Data received : aaaa$
But when I send a string that is longer than 63 characters, only the 63 first characters are sent, the next ones are lost. Since the "$" is after the 63 first characters, nothing is displayed. The 63 characters are added to inData nonetheless. So when I then send a short string such as "aaaa$", it gets added to InData itself and the "$" triggers the displaying of everything and the emptying of inData :
> Data received: longstring_longstring_longstring_longstring_**[imagine a lot of characters here]**_longstring_end_of_longstringaaaa$
When the last lines of the code are commented, such as what I've pasted here, everything is passed right away, even veeery long strings.
Anyone know why it behaves like that, and what I could do in the eventuality where the loop() function has to perform a lot of operations AND I have to transmit long strings in one shot ?
Thank you !