Forum Rule: Always post complete source code & details to reproduce any issue!
Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 51 to 75 of 87

Thread: Problem with Teensy 3.2, Serial1 and HC-06

  1. #51
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,282
    Quote Originally Posted by SteveSFX View Post
    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 really cool.

  2. #52
    It's built from crap!

    The screen is a small 2.4" touchscreen I had spare. Also 4x LCDS that I had left over from some other project.

    It is mostly MDF. Arduino Mega controls the cockpit (Didn't know of Teensy's when I started 18 month back). Also a Mega in the console, and a Pro Mini in the PSU.

    Dustbins make the side engines, plant pot is the main engine, cutlery holders make the thrusters, bicycle pumps make the hydraulic rams... you get the idea

    Found a great guy on Ebay who did all the graphics for the button arrays (Max7219's control the leds) and the main Starship graphics.

    4x MCP23016 read all the buttons.

    Sparkfun MP3 module controls the sound - allows you to play multiple MP3 files at the same time. Therefore, I can keep the engines running by overlaying the sound effect, or use startup/shutdown SFX.
    Free online text to speech facility created the voices, which are then played from their own separate MP3 module. This MP3 module also stores the music files.

    Been tinkering with it for about 18 months in my spare time (which isn't much). Cost about 900 to build.

  3. #53
    madness.....

    Got 2x new HC-06's, and I can't get anything out of them

    The code you have in post #27 results in the HC-06's led going on constantly, and the module freezing. I have to unplug it to get it back. Serial monitor shows nothing. But sending an AT command clearly does something to the module (although not what it is supposed to do).

    All I have is a Teensy3.2, with the HC-06 directly connected to Serial1.... nothing else.

    I ... Just ... Don't... Get it. What has changed? Why don't they work like all the others I have ever used. This is something SO stupidly simple.

    Tired of this Teensy at the moment. It's making me want to give this hobby up... hours of staring at a flashing led is taking it's toll

  4. #54
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,066
    That is bothersome. Are they any better with a USB<>UART adapter from PC Terminal program? Or another Arduino?

    To make sure the Teensy UART is good that prior code could be run - then wire Serial1 RX>TX and TX>RX to same Teensy Serial2 pins.

    Add code like this with Serial2.begin(9600) in setup() - this will do a bit more than just crossing Serial1 Rx and Tx.

    Suppose this is typed right?::
    Code:
    void showMe() {
      delay(20); // optional to wait for incoming chars
      while ( Serial2.available() ) {
        Serial2.print( (char)Serial2.read() );
        delay(2); // optional to wait for incoming chars
      }
      delay(20); // optional to wait for incoming chars
    
      int foo;
      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);
      }
    }

  5. #55
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,543
    And if it was (for whatever reason) that specific Teensy? Did you try to take a fresh one out of your dev drawer for a differential diagnose? How do the serial signals look on an oscilloscope? Post osc screenshots if you need help in deciphering.

  6. #56
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,235
    here is a variation on baud scanner of post #27, give it a try (i've tested it between Teensy 3.2's)
    Code:
    // baud scan keuwl.com/electronics/rduino/bluet/09-baud-rate/
    
    long baud_rates[] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200};
    int baud_index = 3;
    boolean found_baud = false; //Flag to indicate if baud rate has been detected
    
    //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++;
        Serial1.begin(baud_rates[baud_index]); //Initialise software serial
        Serial1.flush();
        Serial.println("Testing " + String(baud_rates[baud_index]) + " Baud ...");
        delay(100);
        Serial1.print("ATATAT");
        delay(1500);
        while (Serial1.available()) {
          char c = Serial1.read();
          if (c == 'O' || c == 'K') {
            found_baud = true;
            Serial.print("recvd "); Serial.println(c);
          }
    
        }
        if (!found_baud) {
          Serial1.flush();
          Serial1.end();
          delay(200);
        }
      }
      if (!found_baud) Serial1.begin(9600); //If not found, try at 9600 anyway
    }
    
    void setup() {
      Serial.begin(9600);
      while (!Serial);
      find_baud_rate();
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    and/or try sketch in post #37

    maybe attach a photo of your T3.2 hooked up to HC-06.

    bad jumpers/wires?
    Last edited by manitou; 09-27-2019 at 09:18 PM. Reason: ooops original was for echo back, change to OK

  7. #57
    Attached is the circuit. It doesn't get any simpler. There are no wires apart from the supplies.

    That code in the reply above - runs through the bauds and prints them to the serial monitor... never finds one. Led just stays flashing (no stutter - which it usually does)

    Tried running it off a battery, just in case the supply was rubbish. Nope.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	BT circuit.jpg 
Views:	9 
Size:	62.0 KB 
ID:	17739  

  8. #58
    Well I have sat here for the last 2-3 hours and tried everything within (my clearly lacking) knowledge. It's broke me this damn Bluetooth module. Must have spend 20 hours on this.

    Tried everything I can possibly think of. Only thing now is to try a different Teensy (I don't have any another one). But... this has disheartened me so much, I am not going to bother.

    How do you test a serial port? I thought you could short them, and anything you typed into the serial monitor would reflect back.... sure that is what I have done before.
    But how do you do that for Serial1 or Serial2? You can't set the serial monitor to those ports?

    Went and check my Bluetooth wiring and code on my Starship ... it is exactly as above, using write statements spaced with a delay(1000). That has never failed.

    Defeated

  9. #59
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,066
    Something very odd. Post #54 had an updated showME() and notes to wire Serial1 to Serial2 and that code should receive on Serial2 and push it back in Serial1 to read.

    That should work with the same wires if you can get them connected to 10,9 from 0,1?

  10. #60
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,282
    You all are right this is really strange. Have you tried changing from Serial1 to Serial2 and do the AT commands?

    Think you asked about the USB-TTL adapter - it comes in handy to check connections and make sure everything is working correctly with the chip. Its a double check for me.

    EDIT: know this is going to sound dumb but have you tried it without the caps between ground and 5v? When I tested I just connected 5v-5v and gnd-gnd

  11. #61
    Caps make no difference. I know these HC-06 modules are noisy on the power lines. I have it running off a battery, separately from the Teensy (combined ground!)... but that hasn't helped.

    Just tried sending out data on various TX pins (Serial1,2 and 3) and reading it back on on different RX pins (Serial1,2, and 3) and printing the result to the serial port. All appear to work.

    That was my last idea. I thought maybe the Teensy had dud serial ports... but doesn't look like it.

    Packing this up for a while now. I will go back to an Arduino Mega at a later date and see if I can get that to work.

    Thank you for all your suggestions.

  12. #62
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,066
    Nice the Teensy likes itself. Hard to believe all of those are bad in such a way - and @mjs513 orders one from Amazon and it works.

    Did you cut thee Teensy underside VIN<>VUSB trace to have USB and external power applied at the same time? Or is the Teensy really not powered from that pin as p#57 shows while connected to USB? Or is USB power line cut?

    If not cut then feed the HC-06 from the 5V VIN pin and skip the battery? It shouldn't take too much power and the Teensy has 'stuff' for decent power minimizing noise to a decent 3.3V.

  13. #63
    I wrote a short routine that is running at the moment.

    Steps through every possible baud, trying Print, Println and Write, with steadily increasing delays between the commands of delay(100) increments. Then asks your ShowMe routine for results.

    So far, it has only responded to 9600 baud, using println, but the ShowMe routine throws back:

    Code:
    ERROR:(0)
    	 cnt=11
    ERROR:(0)
    	 cnt=11
    ERROR:(0)
    	 cnt=11
    This says to me (correctly or incorrectly) that the command is incorrect? e.g Serial1.println("AT+NAMETest");

  14. #64
    9600 Baud. Send: Serial1.println("AT+VERSION"); and then read with showMe();

    Timing is everything. Seems to need exactly delay(900); between commands

    Responds with OK VERSION: 3.0-20170609

    Send "AT". Responds with OK

    Send "ADDR". Responds with ADDR:FCA8:9A:2FF7

    Send "AT+NAME". Responds with Name: HC-06

    Send "AT+UART". Responds with UART: 9600,0,0


    Why is it not accepting any other commands such as "AT+NAMEtest" ?
    Last edited by SteveSFX; 09-28-2019 at 04:32 PM.

  15. #65
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,282
    Try just "AT+NAME". Should print just current name

  16. #66
    It does (written in #64). AT+NAME returns Name:HC-06 which is correct

    It is responding to requests for information. Tried "AT+ORGL" which should reset it. That failed.

    3 of my 5 HC-06's respond with all information, but none of them will accept the standard commands to change the pin, name etc.
    They all fire back 'ERROR'.

    Hmmm ....

  17. #67
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,066
    That is not cool { the slow timing and ERROR return } - but now way less Not Cool than nothing coming back at all.

  18. #68
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,282
    Quote Originally Posted by SteveSFX View Post
    It does (written in #64). AT+NAME returns Name:HC-06 which is correct

    It is responding to requests for information. Tried "AT+ORGL" which should reset it. That failed.

    3 of my 5 HC-06's respond with all information, but none of them will accept the standard commands to change the pin, name etc.
    They all fire back 'ERROR'.

    Hmmm ....
    Sorry didn't register. What command are u using for PIN change and name change? For name change it should be something like this:
    Code:
    AT+NAMExxxx
    where xxxx is the new name. Sorry but have to ask.

    Don't think AT+NAMEtest is valid for the HC06 anymore from what I see. Just like AT+VERSION? is not valid

  19. #69
    That is what I tried (and have always used) Serial.println("AT+NAMEhello");

    Tried gaps, capitals, plus signs, long words, short words, swear words....

    What is really odd (to me) is that Serial.write doesn't work. All the other times I have written to these modules, I have used that.

    My Spaceship has this:

    Code:
      digitalWrite(BT_relay, HIGH);
      delay(1000);
      Serial1.begin(9600);
      delay(1000);
      Serial1.write("AT+NAMEStarship_X-582");
      delay(1000);
      Serial1.write("AT+PIN1999");
      delay(1000);
      Serial1.write("AT+BAUD4");
    The BT_relay gives me the ability to turn off the blueooth. Yes... I have tried programming these HC-06's immediately after power up - just in case

  20. #70
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,282
    Interesting - I am having exactly the same problem with my HC06 that I just got. The only thing I seem to able to change baudrate. For name I get back "OKsetName". Cant seem to break the code

  21. #71
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,282
    @SteveSFX
    Well I figured out whats going, at least with my module.

    Steps to change name or pin:
    1. Send "AT"
    2. Will get "OK response"
    3. Send "AT+NAMEStarship1"
    4. Will get a "OKsetName" response. At this point the name is changed.
    5. Open you Android Bluetooth App (that's what I did), do a scan and you will see the device name that you get set.


    Baud seems to be the only command that gives you an immediate response.

  22. #72
    I get a reply to "AT" of OK.

    Everything else fires back error. Name has never changed since I got it. I have Bluetooth terminal on my phone that I use (plus the name in the Bluetooth list never changed either).

    Sucks. Totally.
    This may well be a Teensy thing. I did read people were having issues with the serial cable preventing the AT commands reaching the module. However.... I get a response from the module, so that can't be it (plus I have tried it with the USB unplugged).

    How can you get a response to all the questions, yet it won't respond to change requests. This bluetooth module and Teensy will be in the bin soon

  23. #73
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,282
    Just attached a very old HC-06 to a T3.2. Wired as:
    Code:
    Tx(BT)-RX(T3.2)
    Rx(BT)-Tx(T3.2)
    Gnd-Gnd
    Vcc(BT)-5v
    Yes I know this is obvious but had to put it down.

    Since my old HC-06 was set at 57600 I used the following sketch that you have seen before:
    Code:
    #define BTserial Serial1
     
    void setup() 
    {
        Serial.begin(9600);
        Serial.println("Enter AT commands:");
     
        // HC-06 default serial speed is 9600
        BTserial.begin(57600); 
    
    }
     
    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=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);
      }
    }
    Then went to the SerMon and sent commands as in previous post:
    Steps to change name or pin:
    1. Send "AT"
    2. Will get "OK response"
    3. Send "AT+NAMEStarship1"
    4. Will get a "OKsetName" response. At this point the name is changed. You will not get any other response. This is the response to the change request. I think depending on firmware not everything is available. I know PIN and NAME will work on mine but AT+UART wont get any response nor will AT+ADDR

    Then I went over to my phone and hit the BT button to turn on BT and did a scan and it came up with the new name.

  24. #74
    I have never had any response to a change command except Error (0).
    I can get the baud rate, the old name, the version, the pin, the address........ but I can't change anything

    Sending AT first doesn't make any difference

  25. #75
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,282
    I am stumped now sick I can not duplicate. Can u send me ebay link where u bought them from. Did you try on the mega yrt?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •