# Making an echo sketch using SoftwareSerial and Bluetooth

In order to test my Arduino UNO + Sparkfun Bluetooth Mate Gold I've written this little sketch;

#include <SoftwareSerial.h>

SoftwareSerial softwareSerial(8, 9);

void setup() {
softwareSerial.begin(115200);
softwareSerial.println("Waiting...");

delay(1000);
}

void loop() {

int bytes[10];

int i = 0;

softwareSerial.listen();

long l = millis();
while (millis() - l < 1000) {
while (softwareSerial.available() > 0) {
i++;

}
}

delay(20);
for (int c = 0; c < i; c++) {
softwareSerial.print(bytes[c]);
softwareSerial.println(" ");
bytes[c] = 0;
}

i = 0;
}
}


Now I'll connect through bluetooth via a terminal and send a string to Arduino, which will be written back.

If I send a string of '11111' for example, I would like something consistent back - the problem is that I get something that is not consistent!

-
I don't know a lot about Arduino, but are you sure that "SoftwareSerial" actually supports data rates as high as 115200? That would be awfully high for a bit-banged implementation. –  Dave Tweed Sep 15 '12 at 11:16
Yes - i am sure. However, the problem persists with all the baud rates that I've tried. So I don't think that that is the problem. –  Mr Danois Sep 15 '12 at 11:24
OK, fair enough. Do you want to give us a clue about what's wrong with the data you get back, or do you want us to keep guessing? If you take the Arduino out of the circuit and just loop the data back at the Bluetooth module, does it work? –  Dave Tweed Sep 15 '12 at 13:40
For example, if i send five 1s (11111) I get this back; 49, 152, 76, 166, 230 first time. Second transmit of the same string I get this; 49, 166, 166, 70, 243. I find it a bit strange that I get different numbers. Maybe there is a system to this, but it eludes me. –  Mr Danois Sep 15 '12 at 19:04
That's very interesting, because almost all of those numbers are bit-shifted versions of the correct value (49). The 70 is the only one that doesn't fit this pattern. This implies that one end or the other of the serial link between the Bluetooth module and the Arduino is losing track of the start/stop bits. Can you answer my second question above? –  Dave Tweed Sep 15 '12 at 19:52