Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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("Bluetooth Ready.");
  softwareSerial.println("Waiting...");

 delay(1000);
}

void loop() {
  int readByte;

  int bytes[10];

  int i = 0;
  boolean readSomething = false;

  softwareSerial.listen();

  long l = millis();
  while (millis() - l < 1000) {
    while (softwareSerial.available() > 0) {
      readByte = softwareSerial.read();
      bytes[i] = readByte;
      i++;

      readSomething = true;
    }
  }

  if (readSomething == true) {
    delay(20);
    readSomething = false;
    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!

share|improve this question
1  
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
show 10 more comments

1 Answer

if your problem is only in characters you receive back just use char[] array instead of int e.g.

char bytes[10];

Now you'll receive the same data back.

Hopefully it solve your problem

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.