Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 18 of 18

Thread: Teensy 4.1 master and ESP32 in Slave, possible ?

  1. #1
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31

    Teensy 4.1 master and ESP32 in Slave, possible ?

    Hello. I am working on my Hanpan project with FSR Pads and everything is working fine. I can connect it to a PC or a phone via USB. But I would like to add a bluetooth connection and I have an ESP32 card. Is it possible to place the ESP32 card as a slave? What solution to send a midi signal in BLE with a Teensy 4.1 ?
    Thanks

  2. #2
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    Hello, I swim a little ... More simply, how to send a MIDI note from a Bluetooth from a Teensy, regardless of the use module HC-06 Adafruit BLE ESP32 ...
    Thank you so much

  3. #3
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    Hello, because you have to start somewhere, the famous Hello World
    But it doesn't work
    I am connected on the Teensy 4 to RX1 (pin 0) and TX1 (pin 1), on ESP32 to RX2 (GIOP16) and TX2 (GIOP17)
    I guess it's not so simple.

    Thanks, and best regards


    Teensy master
    Code:
    void setup()
    {
      Serial.begin(9600); // USB is always 12 Mbit/sec
    }
    
    void loop()
    {
      Serial.println("Hello World...");
      delay(1000);  // do not print too fast!
    }

    ESP32 slave
    Code:
    #define RXD2 16
    #define TXD2 17
    
    void setup() {
      Serial.begin(115200);
      Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
    
    }
    
    void loop() {
     Serial.print("Receided :");
     Serial.println(Serial2.readString());
     delay(200);
    
    }

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    You also need to connect the ground of both together.
    ...and you need to setup and user Serial1 on Teensy.
    Your code is using Serial which is usb serial to the PC.

    I have been using Serial1 at 2000000 baud. That's 200,000 characters per second, ridiculous!!
    I'm not saying that the ESP32 can go that fast.

  5. #5
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    Yes, I did not specify but I connected the ground of both together

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    Your code is wrong on the Teensy as I explained in my previous post.

  7. #7
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    I know, this is only an example I found on Youtube for an Arduino UNO and I understood that it is not the same. I start and I learn. What do i need to change ? Thanks
    https://youtu.be/YVPumD16Y_Y
    Last edited by SPIRIT; 06-09-2021 at 05:45 PM.

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    If I tell you you will not learn anything.
    First of all Serial on Teensy is the USB port talking to your PC.
    I suggest you read this. That way you will learn more about your teensy and how to use it and also how to solve your problem.
    The solution is quite simple actually.

  9. #9
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    Thanks for your helps. I try this but don't work

    Code:
    void setup()
    {
      Serial.begin(115200);
    }
    
    void loop()
    {
      Serial1.println("Hello World...");
      delay(1000);  // do not print too fast!
    }

  10. #10
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    I looked at the "Using the Hardware Serial Ports" page and I understood for Serial1 Serial2...

  11. #11
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    Quote Originally Posted by SPIRIT View Post
    Thanks for your helps. I try this but don't work

    Code:
    void setup()
    {
      Serial.begin(115200);
    }
    
    void loop()
    {
      Serial1.println("Hello World...");
      delay(1000);  // do not print too fast!
    }
    Did you initialise/start Serial1?

    EDIT:
    The baud rate MUST be the same on Teensy and ESP32, as well as parity and stop bit settings.
    Last edited by BriComp; 06-09-2021 at 07:20 PM.

  12. #12
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    Quote Originally Posted by SPIRIT View Post
    I looked at the "Using the Hardware Serial Ports" page and I understood for Serial1 Serial2...
    Teensy 4 and 4.1 are mentioned on that page.

  13. #13
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    Better ?

    Code:
    // set this to the hardware serial port you wish to use
    #define HWSERIAL Serial1
    
    void setup()
    {
      Serial.begin(115200);
      HWSERIAL.begin(9600);
    }
    
    void loop()
    {
      HWSERIAL.print("Hello World...");  
      delay(1000);  // do not print too fast!
    }

  14. #14
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    Yep, did it work talking to ESP32?

  15. #15
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    Well, I do get a response when I start teensy, but then the reception freezes. But it's starting to be interesting

    Receided :Hello World...Hello World...Hello World...Hello World...Hello World...Hello World...Hello World...Hello World...Hello World...
    Receided :
    Receided :
    Last edited by SPIRIT; 06-09-2021 at 08:44 PM.

  16. #16
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    That's because loop keeps on going round and round that's why it's called loop.

  17. #17
    Member
    Join Date
    Apr 2020
    Location
    France
    Posts
    31
    Hi ! A small adjustment with BAUD at 921600 and delay, now it works perfectly.
    Thank you very much for your patient and for taking the time to explain to me

    Code:
    //Teensy 4 Master
    #define HWSERIAL Serial5
    
    void setup()
    {
      Serial.begin(115200);
      HWSERIAL.begin(921600);
    }
    
    void loop()
    {
      HWSERIAL.println("Hello World...");  
      delay(1200);  // do not print too fast!
    }
    Code:
    // ESP32 Slave
    #define RXD2 16
    #define TXD2 17
    
    void setup() {
      Serial.begin(115200);
      Serial2.begin(921600, SERIAL_8N2, RXD2, TXD2);
    
    }
    
    void loop() {
    
    Serial.print("Receided :");  
    Serial.println(Serial2.readString());
    delay(200); 
    }

  18. #18
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    No problem, and you learnt something which is good.

Posting Permissions

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