Shop OBEX P1 Docs P2 Docs Learn Events
Bluetooth serial bridge — Parallax Forums

Bluetooth serial bridge

Want to make a serial connection between two microcontrollers using bluetooth.
Started looking at stuff but seems need a Master and not clear how to do that...

But, maybe am starting to like AI because google tells me about HC-05.
Seems this thing can be master or slave.
Looks like very simple connections too.

<$10 on Amazon. Seems like easy way to go.

Appears code is mostly for Arduino, but that's easy to adapt for Propeller...

Comments

  • JonnyMacJonnyMac Posts: 9,460

    I've used the HC-0x modules as receivers on P1s many times, usually controlled through a terminal app on my phone. The attached picture shows a mini "Stranger Things" wall I made with WS2811 Christmas lights. I made a little BT app for my Android phone using MIT App Inventor that allowed me to control the lights with a P1. Mostly I'd ask a customer who was visiting the booth their name, type it in, and the P1 would spell out their name on the lights. It was a big hit.

    From a code standpoint, it was just a serial connection on the P1 side.

    I went through old parts boxes and found an HC-05 and cleaned up the attached terminal program which can be used to set-up your HC-05s. The only drag is that you have to push a button on them while applying power to get them into command mode.

  • MicksterMickster Posts: 2,883

    Although I don't do Arduino, I decided to use it to turn ESP32s into Bluetooth modules. It was a piece of cake, all I had to do was redirect the BT to the UART.

    I believe that Random Nerd Tutorials helped me figure it out. You could also use the ESP32 as an I/O expander.

  • JonnyMacJonnyMac Posts: 9,460
    edited 2025-09-19 15:18

    I am experimenting with a "bridge" using ESP-01 modules with ESP-NOW (very early stages), but this may be of interest to Ray as it can be used like the HC-05 BT, but unlike the HC-05, using ESP-NOW you can go 1-to-1, or 1-to-many.

    Random Nerd Tutorials

    I'm not an Arduino guy, either, but I have found useful information on that site.

  • MicksterMickster Posts: 2,883

    Yeah I have been following ESP-NOW and it's exciting stuff.
    Some of the round trip latencies that I have seen are ludicrously low.

    Great Scott has a neat YouTube video, comparing with other technologies.

    A great way to get a feel for the ESP32 capabilities is to load up Annex32. It's a BASIC interpreter but darn, there isn't much that they don't cover.

    They show examples of mixing ESP32 and ESP8266 on ESP-NOW.

    Only for non-commercial use though.

  • RaymanRayman Posts: 15,695
    edited 2025-09-19 20:23

    Haven't heard of ESP-NOW, have to check that out...

    HC-05 are $10 each on Amazon though.. Hard to beat that..
    Just noticed HC-06. Have to see if that's any better....

  • RaymanRayman Posts: 15,695

    Took a peek at ESP-Now... Looks like any ESP32 bluetooth module will work?

    Guess this is just software... These are 2 for $10, guess that is better.
    But, coding looks more difficult. Have to actually program the device...

  • JonnyMacJonnyMac Posts: 9,460
    edited 2025-09-19 21:50

    ESP-NOW is also part of the ESP8266 which is why I'm using the ESP-01S (latest with larger flash). You can get them for < $3 each:

    -- https://www.amazon.com/10Gtek-ESP8266-ESP-01S-WiFi-Module/dp/B09J2KPHTN

    Over lunch I loaded MicroPython into a couple of ESP-01S modules with this:

    -- https://www.amazon.com/Stemedu-ESP8266-Adapter-Programmer-Downloader/dp/B097SZMK2W

    I have tried a couple of other devices, but this is the only one that seemed to work without issues.

    I used esptool.exe from the command line to erase the flash and install MicroPython -- was a non-brainer, and was recognized by Thonny as soon as I opened the editor. Of course, you can also program the ESP-01S using the Arduino IDE if you prefer C. A good friend of mine has a network of ESPs around his home (out in the woods), and he was the one who suggested ESP-NOW when I told him what I want to do.

    Just noticed HC-06.

    The HC-06 is slave only, so it may not work in a bridge type app.

    Great Scott...

    I like his videos; they're always educational.

  • MicksterMickster Posts: 2,883

    Yup, HC-05 is master/slave, HC-06 is slave only.

    I have had a HC-05 bridge setup and it really is just like having a wire link between UARTs. IIRC, I didn't get auto-reconnect working but it was only a quick experiment.

    Bluetooth was actually designed for industrial use and has built-in error checking.

    My HMIs have been Android tablets since 2012 and they are rock solid. My environment is lots of metal and lots of EMR. I have literally never had a glitch.
    Because my tablet is only HMI, once the machine is running, it can be removed from the area. Pretty cool to bring the tablet back in to range and see the machine data suddenly start updating.
    Where I am atm, the client is connected to the tablet via factory WiFi which allows him to create a new program at his PC and send it over but he prefers to walk out to the machine and bring the device back to his office because the HMI touchscreen is more convenient than his mouse/keyboard.

    I posit that; all that anything needs anymore is not a dedicated HMI but something like a HC-05. Our phones and tablets are the most powerful HMIs ever created. The reason I get to replace perfectly good control systems is because the old dedicated HMI (the most abused element) has died and replacing it is no longer possible.

  • MicksterMickster Posts: 2,883

    @Rayman

    // This example code is in the Public Domain (or CC0 licensed, at your option.)
    // By Evandro Copercini - 2018
    //
    // This example creates a bridge between Serial and Classical Bluetooth (SPP)
    // and also demonstrate that SerialBT have the same functionalities of a normal Serial
    // Note: Pairing is authenticated automatically by this device
    
    #include "BluetoothSerial.h"
    
    String device_name = "ESP32-BT-Slave";
    
    // Check if Bluetooth is available
    #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
    #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
    #endif
    
    // Check Serial Port Profile
    #if !defined(CONFIG_BT_SPP_ENABLED)
    #error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip.
    #endif
    
    BluetoothSerial SerialBT;
    
    void setup() {
      Serial.begin(115200);
      Serial2.begin(115200, SERIAL_8N1, 16, 17);  // Initialize Serial2, TX on pin 17, RX on pin 16
      Serial2.setRxBufferSize(2048); // Set RX buffer size to 2048 bytes
    
      SerialBT.begin(device_name);  //Bluetooth device name
      //SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin
      Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());
    }
    
    void loop() {
      if (Serial.available()) {
        SerialBT.write(Serial.read());
      }
      if (SerialBT.available()) {
        char incomingChar = SerialBT.read();  // Read one byte from Bluetooth
        Serial.write(incomingChar);
        Serial2.write(incomingChar);
      }
      //delay(20);
    }
    

    Came to fire-up the Arduino IDE and it was gone :o No reason for me to uninstall...probably a senior moment :D

    Anyway, the above is at least similar to what I did.

Sign In or Register to comment.