Problem with Teensy 3.2, Serial1 and HC-06

Status
Not open for further replies.
I will have to go and dig out a Pro Mini....

Rx2 and Tx2 shorted basically fires back:

Checking....Checking....AT+NAMEGAUGES13
Checking....AT+PIN123410
Checking....AT+BAUD48

That is really frustrating :( That shows that the code typed in for showMe() here in the WebBrowser actually works!

And that shows the expected. On power up the HC-06 is Silent/Mute, but that the commands are going out - and coming back in when the UART lines are jumpered.

And expect the same should happen on the T_3.2 if tried? And that the showMe() func as placed should show it those commands going OUT prompt and reponse output from the HC-06.

With a picture of the T_3.2 and the Pro Mini each wired to an HC-06 perhaps somebody would see the issue.

The only thing that could affect it noted above would be not having a common ground between the Arduino board and the HS-06, and well connected (soldered or jumpered) Rx/Tx wires.

Problem could be setting the HC-06 baud rate may have worked once to a new rate and it may store that statically?

T_3.2 baud rate - would need to be set to that current rate to get any data back when commands are issued.
 
Know I am late to the party but are you sure the baud rate of 9600 is the same baud rate that the HC-06 is expecting. Saw something where they were setting it up at 3840, Ref: https://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/

Also I found this at (keuwl.com/electronics/rduino/bluet/09-baud-rate/)

Code:
// Configuring HC-06 Via Bluetooth Demo
// By keuwlsoft:  www.keuwl.com  30th Sept 2015
// cc Attribution-ShareAlike

// Used with an Android device running keuwlsofts 'Bluetooth Electronics'
// app with the 'Configure HC-06 demo' panel.  Program baud rate, name and  
// pin on a second HC-06 module connected to the software serial. 

#include <SoftwareSerial.h> //library for software serial

//define software serial: RX on Pin 8, TX on Pin 9
SoftwareSerial softSerial(8, 9); 

long baud_rates[]={1200,2400,4800,9600,19200,38400,57600,115200};
int baud_index=3;
char BluetoothData; // the data received from bluetooth serial link
boolean found_baud=false; //Flag to indicate if baud rate has been detected

void setup() {
   
  Serial.begin(9600); //Initialise serial for communicating to android device 
}

void loop() {

 if (Serial.available()){
    BluetoothData=Serial.read(); //Get next character from bluetooth
    
  //Find Baud Rate
    if(BluetoothData=='F') find_baud_rate();
  
  //Set Baud Rate
    if(BluetoothData>48&&BluetoothData<57){ //chars '1' to '8'
      if (!found_baud) find_baud_rate();  
      softSerial.print("AT+BAUD"+String(BluetoothData-48));
      delay(1500);
      if (softSerial.available()) Serial.println("Response="+softSerial.readString());
      softSerial.end();
      baud_index=BluetoothData-49;
      softSerial.begin(baud_rates[baud_index]); //Initialise software serial at new rate
    }
    
  //Set New Name or Custom Command  
    if(BluetoothData=='N'||BluetoothData=='C'){
      String str=Serial.readString();
      if (BluetoothData=='N')str="AT+NAME"+str;
      if (!found_baud) find_baud_rate();  
      softSerial.print(str);
      delay(1500);
      if (softSerial.available()) Serial.println("Response="+softSerial.readString());
    }
  
  //Set New Pin  
    if(BluetoothData=='P'){
      int pin=Serial.parseInt();
      if (!found_baud) find_baud_rate();  
      softSerial.print("AT+PIN"+ String(pin));
      delay(1500);
      if (softSerial.available()) Serial.println("Response="+softSerial.readString());
    }

 }
}

//Function to loop through the baud rates until a response is obtained
void find_baud_rate(){
 
  found_baud=false;
  baud_index=-1;
  while(!found_baud&&baud_index<8){
    baud_index++;
    softSerial.begin(baud_rates[baud_index]); //Initialise software serial
    Serial.println("Testing "+String(baud_rates[baud_index])+" Baud ...");
    delay(100);
    softSerial.print("AT");
    delay(1500);
    if (softSerial.available()){
      found_baud=true;
      Serial.println(softSerial.readString()+" at "+String(baud_rates[baud_index])+" Baud");
    }
    if (!found_baud) softSerial.end();
  }
  if (!found_baud) softSerial.begin(9600); //If not found, try at 9600 anyway
}
 
Common grounds shared (that would be a newbie error!)
The new HC-06 should be 9600 baud, and I have never asked to change it to anything else.
I have tried talking to it today on basically all speeds... but nothing.

I did find something on the web about the newer HC-06 boards having a rogue diode added that was messing up any comms to the IC.
The fix was to pull the TX line high (either Pullup or with an actual resistor). But, they are not the HC-06's I have (different board layout - no Diode).

This HAS to be either a power supply issue, or I have dud HC-06's. To be honest, don't really want to waste any more time or cash on these things.

I have tried several PSU's (I do remember they make a lot of noise)... but that usually messed up the associated circuitry, not the Bluetooth module itself.

I think I will get one final new module, and try again. Too much time gone into this damn thing!

I may also stick these HC-06's in my other projects that use them and see if they fire up. That however, does require some dis-assembling :(
It's buried in the heart of a spaceship!
 

Attachments

  • Starship X-582.jpg
    Starship X-582.jpg
    89.5 KB · Views: 96
Cool ship!

Always a treat to reply to a post not knowing who is on the other end - NOOB or other - but assuming and not confirming the basics is the easiest way to getting lost without any hands on idea of what is there …

No fun buying the HC06's and having them fail to work - odd that some 'common' one has random diode and those don't - always have to wonder when buying things that are cloned/commodity items from who knows where.

Did you cross Tx<>Rx on Teensy to see the command echo back with showMe()? That should work with Serial1 or Serial2 with no issue if the pins are healthy - and then no GND required :)
 
I will second what @defragster said.

I also just ordered a HC-06. Won't get here until Tuesday though - I only have hc-05's laying around. Will give it another try then.
 
I will second what @defragster said.

I also just ordered a HC-06. Won't get here until Tuesday though - I only have hc-05's laying around. Will give it another try then.

Will be interesting to see what you see with HC-06 and the other HC-05 on your end.

I started to drop one in my cart - wasn't sure if HC-06 was better - but seems they don't all work :) Also wasn't sure what I'd do with it other than hook it up. I have an idea but not sure when I'll get there.
 
Will be interesting to see what you see with HC-06 and the other HC-05 on your end.

I started to drop one in my cart - wasn't sure if HC-06 was better - but seems they don't all work :) Also wasn't sure what I'd do with it other than hook it up. I have an idea but not sure when I'll get there.

I have been using them on and off to control my rovers in manual mode - either BT20 or one of the 3dr clone radios (https://www.amazon.com/FPVDrone-Tel...jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==). Used RC as well.
 
@SteveSFX

I just went into my repository of test sketches and it looks like I may had a HC-06 someplace - have to find it now. The one thing I noticed in the sketch I wasn't using serial1.write's but serial1.print's. So can you try this and see if it works for you (think it corresponds to same one you have):
Code:
/*
The posible baudrates are:
1-------1200
2-------2400
3------4800
4------9600
5------19200
6-------38400
7------57600
8-----115200
9------230400
A-----460800
B-----921600
C-----1382400


*** Important. If you re-set the BT baud rate, you must change the myserial baud to match what was just set. Steps:

Assuming the BT module baud default is 9600 Baud set mySerial to 9600 and you want to change it to 57600.
1) leave the line:  //mySerial.begin(9600); as you have to been at the current baud setting to be able to send the command to the BT module.
2) uncomment the line:  //mySerial.print("AT+BAUD7"); // Set baudrate to 57600
3) run the sketch.  This will set the baud to 57600.  However, you may not see the response OK. 
4) uncomment the line //mySerial.begin(57600); and download the sketch again - this sets myserial to the new setting.
5) now that myserial is set to 57600 open the serial monitor - this will restart the sketch.  You should see a secomd line after "Goodnight Moon"
that will show the BT module responding to the change.
6) be sure to re-comment the line //mySerial.print("AT+BAUD7"); when done

*/
#define mySerial Serial3

void setup()
{
//Serial.begin(9600);
//Serial.begin(57600);
Serial.begin(57600);
Serial.println("Goodnight moon!");
mySerial.begin(57600);
//mySerial.begin(57600);
//mySerial.begin(115200);    //if you change the baud and want to re-run this sketch, make sure this baud rate matches the new rate.


mySerial.print("AT");

mySerial.print("AT+VERSION");

//mySerial.print("AT+PIN1234"); // Set pin to 1234  was 1342
//delay(1000);
//mySerial.print("AT+NAMEJY-MCU-HC06"); // Set the name to JY-MCU-HC06
//delay(1000);
//mySerial.print("AT+BAUD4"); // Set baudrate to 9600
//mySerial.print("AT+BAUD7"); // Set baudrate to 57600
//mySerial.print("AT+BAUD7"); // Set baudrate to 115200

}

void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
 
Thanks for all the assistance guys.

Yes- tried serial.prints and serial.writes... no difference

I did cross Tx and Rx on the Teensy and the command did echo back.

I thought the HC-06 was easier to use because it is always in AT mode.

The Bluetooth modules with the rogue diodes are JY-MCU BT_BOARD V1.06. Link below to the fix.

https://mcuoneclipse.com/2014/03/30/getting-bluetooth-working-with-jy-mcu-bt_board-v1-06/

Got to put an RS order in this afternoon for work. No idea if they sell BT modules. but the random sub-par crap I get these days from Ebay (even if purchased in the UK) has made me all but abandon Ebay as a source of modules.
Not.... that I think this is a module issue.
 
Just fired it up again.... I just noticed you said to reverse the RX/TX pins - not short them
Changed write to print just to check (although done that many times already)

Code:
void setup() {
  // put your setup code here, to run once:

  Serial1.begin(9600);
  showMe();
  delay(5000);

      Serial1.print("AT+NAMEGAUGES");                                             // Set up the Bluetooth comms
      showMe();
      delay(5000);
      
      Serial1.print("AT+PIN1234");
      showMe();
      delay(5000);
 
      Serial1.print("AT+BAUD4");
      showMe();
      delay(5000);
     
    
}

void loop() {
  // put your main code here, to run repeatedly:

}

void showMe() {
  int foo;
  delay(20); // optional to wait for incoming chars
  foo=Serial1.available();
  while ( Serial1.available() ) {
    Serial.print( (char)Serial1.read() );
  }
  if (foo) Serial.println(foo);
}

This produces nothing unless you short the RX/TX pins, then you get the reflected answer. Swapping them doesn't do anything. I wish I had a clearer understanding of serial comms.... Google reading tonight.

The HC-06 'should' make the rapid blinking LED stutter as it receives the command. That has never happened.
I also remember that the HC-06 usually needs to be rebooted for the new commands to take effect. I believe on my Starship (Every Starship should have it's own App!)... the Bluetooth module has its own power toggle and it is automatically rebooted after you change any details.

I usually change the pin, as this is something that appears to be instant... when 1234 won't let you connect, you know you are changing the details.
I have noticed before the name stay as HC-06 in the devices list, and change to your name once you connect.

Have to go to work now guys... so, catch up later. Thank you for the suggestions.
 
Serial is a good simple protocol - the hardware does the timing and byte assembly. Keys off STOP value then switches to START for a baud pulse and sends the next bits at baud. So GND and a Tx going to an RX and it works - with working baud.

If you have a second Teensy you can set up a simple test - or even send one Teensy's Serial1 to Serial2 and play with it. I have a board here running out each of 5 Serial Uart ports and IN on the next in line with the last looped to the first. T4 has 7 ports and during Beta to test KurtE's work I wired each of the 7 ports similalrly back and forth between the two Teensy 4's and it runs for days at 5M baud.

I see I was cheap on the end of function showMe() should have ended like this to give none confusin output it is ever start working:
Code:
void showMe() {
  int foo;
  delay(20); // optional to wait for incoming chars
  foo=Serial1.available();
  while ( Serial1.available() ) {
    Serial.print( (char)Serial1.read() );
  }
  if (foo) {
    Serial.print("\t cnt="); // assuming no chars arrive during reading and get transferred
    Serial.println(foo);
  }
}

Hopefully @mjs513 will get working units online and be of more help.
 
@SteveSFX @defragster

Got my HC-06 from Amazon today. Been playing with it. It has the additional marking on the back of ZS-040 - hope yours is the same. The following works by sending commands through the Serial Monitor BUT you have to use "NO LINE ENDINGS" to get it to work.

Code:
// Basic Bluetooth sketch HC-06_01
// Connect the Hc-06 module and communicate using the serial monitor
//    http://www.martyncurrey.com/arduino-and-hc-06-zs-040/
// The HC-06 defaults to AT mode when first powered on.
// The default baud rate is 9600
// The Hc-06 requires all AT commands to be in uppercase. [COLOR="#FF0000"]NL+CR should not be added to the command string[/COLOR]
//
 
 
#define BTserial Serial1
 
void setup() 
{
    Serial.begin(9600);
    Serial.println("Enter AT commands:");
 
    // HC-06 default serial speed is 9600
    BTserial.begin(9600);  
}
 
void loop()
{
 
    // Keep reading from HC-06 and send to Arduino Serial Monitor
    showMe();
 
    // Keep reading from Arduino Serial Monitor and send to HC-06
      if (Serial.available())
      {
          BTserial.write(Serial.read());
      }
}

void showMe() {
  int foo;
  foo=BTserial.available();
  while ( Serial1.available() ) {
    Serial.print( (char)BTserial.read() );
  }
  if (foo) Serial.println(foo);
}
 
Hi. No, my modules don't have that written on them. I do have 2 different 'types', but neither work.

I have ordered a new HC-06 and also a HM-10 bluetooth module (that I also have a library for).

I don't use line endings anyway... I will try your code, but I am starting to suspect my modules. Maybe I have been unlucky and just got duds from two different places (although unlikely!)

I am assuming correctly that the CPU speed doesn't affect the baud rate.... I mean, it shouldn't, but at this point... try anything. Saying that, I have tried at all CPU speeds and no change anyway.

It's mad, I am sitting here designing a PCB for a project. Heart of it is a Teensy 3.2, with a Nextion screen, multiple inputs/outputs, DMX opto-isolated receiver and loads of other functions.....

.... and I can't get a 4 pin BT receiver to work :confused:

Will try and report back. Thank you for your time on this
 
There is a table of usable baud rates on T_3.2 here :: pjrc.com/teensy/td_uart.html

Certainly at 96 MHz there is 0% error in the baud rate clocking, that should not be an issue. T_3.2 was used to program ESP8266's - faster rates than 9600 - but it was never an issue to pump out the 300-500KB of code they take.

Something about the design/build/function of units on hand.

On the linked p#27 instructible page above it notes the HC05 takes setup to get to AT Slave mode - perhaps try that - may the units really are not HC-06's? It also shows units with a range of VIN - but does show that Rx/Tx are 3.3V.
 
Common grounds shared (that would be a newbie error!)
The new HC-06 should be 9600 baud, and I have never asked to change it to anything else.
I have tried talking to it today on basically all speeds... but nothing.

Did you try the baud-rate scanning sketch in post #27?
If you have a scope or logic analyzer, you could observe Tx pin of HC-06. You could see if there is activity on the Tx pin when testing with various baud rates, and maybe deduce the baud rate from bit speeds on scope/LA. Lacking scope or LA, you could use pulseIn() to measure the pulse width from HC-06 Tx pin -- @9600 baud would yield 104 us width-ish
 
Last edited:
@SteveSFX
Can you post a link to the HC06 module that you have or photo of the front and back? Are you sure you initial baud is 9600 and not something else? Also from what I read is if your module is already paired the initialization wont work? Just guessing here. EDIT: Did you try connecting it up via a USB-ttl converter to your computer?
 
Hello

OK, let me run through your questions....

Yes, I did run the baud scanner... no result
That last piece of code to connect via Serial port.... no result

I have 3x HC-06's here. One I tried directly RX-TX connections without level shifting, basically to see if it worked. Never needed to level shift them before, but hey... they do say 3.3v on the boards.
The other 2x modules were always tried through a level shifter.

Am I correct in thinking that a Teensy 3.2 is 3.3v output, and 5v tolerant input?

The link:
https://www.ebay.co.uk/itm/JY-MCU-HC-06-Arduino-Android-Wireless-Bluetooth-RF-Serial-5v-Transceiver-Module/312497877145?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

If you connect to the Bluetooth modules with my phone, they come up listed as HC-06.

Dud modules.... have to be

I have just received this HM-10 Bluetooth module. Going to try that.
I still want to crack these HC-06's however
 

Attachments

  • 20190925_161505.jpg
    20190925_161505.jpg
    75.5 KB · Views: 48
  • 20190925_161440.jpg
    20190925_161440.jpg
    91.2 KB · Views: 52
Just tried the HM-10 module.

Worked straight off the bat... :rolleyes:

Dud HC-06 modules I would think.

The HM-10 is a low energy thing, so I needed a BLE app to find it, but it renamed and accepted a new pin straight away.

Still determined to get these damn HC-06's working (well, replacement ones)
 
Just tried the HM-10 module.

Worked straight off the bat... :rolleyes:

Dud HC-06 modules I would think.

The HM-10 is a low energy thing, so I needed a BLE app to find it, but it renamed and accepted a new pin straight away.

Still determined to get these damn HC-06's working (well, replacement ones)

Strange. You sure you not connected to phone app when you are trying to program? Also on mine I just went from TX-RX and RX-TX. The last code I posted should have worked with that module.
 
No. Bluetooth is off on the phone. Anyway, the led on the HC-06 is flashing, meaning unpaired.
You should be able to go RX-TX and TX-RX. Teensy is 3.3v and so are the comms on the HC-06.

From past experience with these modules (but they are all different it seems), I could always tell when it received the re-programming commands, because the flashing 'unpaired' led would stutter as it received the new instruction.
 
Looking at the ebay link you posted it shows the module as a ZZS-040. Also the top and bottom sides look a lot different than what you posted. Really strange those boards. To be honest really out of ideas on getting you HC-06's to work.

The only other possibility is the 3.3v signals on tx/rx are too low for the T3.2 to read. Do you have a scope or something you can measure the signals with to see if you are getting anything and the voltage level - believe @manitou suggest this as well.
 
I thought that the signals may be too low..... but I tried firing tx through a level shifter to the Teensy, but no difference.

It shows ya... both these BT modules came from that guy, but they are not the same.

Think I may buy 5x of the ones I have used before from the guy I used in China. Usually avoid Chinese knock-off stuff, but his modules seem to work fine.
Used those in my Spaceship, and also got one in my pickup truck (controls the LED lights from an App).

My scope is dead, and no pennies for a new one at the moment.
Might start looking for a replacement I think.... I miss that handy bit of kit
 
Bit of both. Someone asked me to make a themed bed for their son. After I had started, they changed their minds... but I carried on anyway and got a bit carried away.
I need to get shot of it now.... not exactly sure where to sell it!

https://www.youtube.com/watch?v=bepTv2w4InI&t=247s

It's had some extra stuff added since this video, but you get the idea!
 
wow that is very detailed !

you need to turn it into a motion simulator !

what types of screens did you use ?
 
Status
Not open for further replies.
Back
Top