(Help) Bluetooth and Teensy 3.2

Status
Not open for further replies.
Hello, I am trying to configure this Bluetooth device (https://www.sparkfun.com/products/12576) on teensy 3.2. To enter the command mode and set your preferences I just have type $$$ and then CMD on the serial monitor. I don't know why but the bluetooth module is not sending any data back to me.
Below is the sketch I am using, thanks!

Commands references: http://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf


Code:
String receivedText = "";

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600); //rx1 and tx1 = pins 0 and 1 on Teensy
  delay(200);
}

void loop() {
   if (Serial.available()) Serial1.write(Serial.read());
  while(Serial1.available() > 0) { // While there is more to be read, keep reading.
    receivedText += (char)Serial1.read();
    delay(10);
    Serial.println("Working!");
  }

  if(receivedText != "") Serial.println(receivedText);
  receivedText = "";
}
 
Last edited:
What is the intent of the 'serial1.println("working"); line? That will inject extra characters you don't want there.

Not really excited about the delay(10) bit inside the Serial.availible loop. Can see what it's doing and think it'll work though.

Also, what happens if you remove the bluetooth module and just jumper pin 1 and 0 together to loop the traffic?
 
The delay is there for a reason, to gather up all the serial data for a single send instance and print it as a single line instead of parsing the end of line character, so removing it probably won't fix anything. A test is to swap
(char)Serial1.read(); with a Serial.print(Serial1.read);
might be worth a look. Will look ugly since it it probably will not swap lines but will confirm if you are in fact reading data.
 
Nothing with the Serial.print(Serial1.read());

Code:
String receivedText = "";

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600); //rx1 and tx1 = pins 0 and 1 on Teensy
  delay(200);
}

void loop() {
   if (Serial.available()) Serial1.write(Serial.read());
  while(Serial1.available() > 0) { // While there is more to be read, keep reading.
    Serial.print(Serial1.read());
    delay(10);
  }

  if(receivedText != "") Serial.println(receivedText);
  receivedText = "";
}
 
You need to try looping the teensy to itself, prove if the Teensy serial1 is working, or if the bluetooth module isn't responding. May also be useful to add led+300 ohm resistor to those pins so you can see traffic, disregard this if you have access to a osciliscope since that's a batter hammer for this job.
 
I get this when I send the command $$$

631310



Code:
void setup() {
  Serial.begin(9600);
  Serial1.begin(115200); //rx1 and tx1 = pins 0 and 1 on Teensy
  delay(200);
}

void loop() {
   if (Serial.available()) Serial1.write(Serial.read());
  while(Serial1.available() > 0) { // While there is more to be read, keep reading.
    Serial.print(Serial1.read());
  }
}
 
[...] open up the Serial Monitor. Throughout this process you’ll have to fudge around with the dropdown menu to the left of the baud rate selection. It should initially be set to “No line ending”.

First, let’s enter command mode by typing $$$, and click “Send”. You should see the Bluetooth modem respond with CMD, and you’ll notice the red Stat LED blinking much faster, this all indicates that the device is in command mode.

Once you’re in command mode, you’ll need to change the line ending dropdown to “Newline”. The basis of all this is that the RN-42 module expects a newline character after every command except for the command mode string. Annoying, but we’ll deal.
https://learn.sparkfun.com/tutorials/using-the-bluesmirf
 
And the code that is working now :)


Code:
String rcve = "";

void setup() {
  Serial.begin(9600);
  Serial1.begin(115200); //rx1 and tx1 = pins 0 and 1 on Teensy
  delay(200);
}

void loop() {
   if (Serial.available()) Serial1.write((char)Serial.read());
  while(Serial1.available() > 0) { // While there is more to be read, keep reading.
    rcve += ((char)Serial1.read());
  }
  if(rcve != "") Serial.print(rcve);
  rcve = "";
}
 
Status
Not open for further replies.
Back
Top