Blue Tooth Bee + Shield not supposed to send Ascii

Kyle:

Thanks for including your sample code. Although I don’t have a bluetooth pair to test this out, I believe the issue may be with the lines like this one:

blueToothSerial.print(newSensorVal);

In this case, blueToothSerial is an instance of SofwareSerial, so it inherits the methods associated with SoftwareSerial. I went to the reference for SoftwareSerial on the Arduino site ( arduino.cc/en/Reference/SoftwareSerialPrint ) and found the following example code, which I think may explain the problem you’re seeing:

// read the analog input on pin 0:
analogValue = analogRead(A0);

// print it out in many formats:
serial.print(analogValue); // print as an ASCII-encoded decimal
serial.print("\t"); // print a tab character

serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the
// value by 4 because analogRead() returns numbers
// from 0 to 1023, but a byte can only hold values
// up to 255)

As you can see, the default serial.print() function prints characters in ASCII-encoded values. So, integer 0 becomes 0x30, integer 1 becomes 0x31, and so forth, just as you are seeing.

You have at least a few options:

  • break your sensor values into two BYTE values and recombine them on the receiving end
  • continue to send ASCII encoded values, and reinterpret them on the receiving end
  • Use the example code above, divide the analog value by 4, and send a single raw byte value

I suspect the easiest is to continue sending the sensor values in ASCII encoded form, and use the atoi or atol (ASCII to INT, ASCII to LONG) conversion functions on the receiving end. You can find some sample code on how to do that here:
inkling.com/read/arduino-co … recipe-2-9

You might also use the toInt method available from the String library. An example is shown in the article I mentioned above. Here’s a quick code snippet:

String aNumber = “1234”;
int value = aNumber.toInt();

And lastly, there is the parseInt() and parsefloat(). Those are documented here: arduino.cc/en/Reference/Stream

I hope this helps.

Best wishes.