Bluetooth Bluetooth serial bridge

Hi
I would like to connect a device with a serial output to a Standalone Arduino which then connects via Bluetooth to an arduino attached to the PC at 57600 Baud. In order to tackle this one by one I am starting with the following Setup:
-2 x Arduino Mega2560
-2 x Grove Serial Bluetooth 3.0 Grove - Serial Bluetooth v3.0 | Seeed Studio Wiki

So currently the basich schematic is the following:

PC - Arduino - Bluetooth Module Bluetooth Module - Arduino - PC

On the Arduino I am trying to get the Serial passthrough from Serial to Serial 1 working where I attached the Bluetooth Modules.

The following is the code running on the Central Arduino:

////Central
void setup() {
  Serial.begin(9600);
  Serial.println("CENTRAL");

//  Serial1.begin(57600);
  Serial1.begin(9600);
  setupBlueToothConnection();
  Serial.flush();
  Serial1.flush();
  // Serial1.begin(57600);
  // Serial.flush();
  // Serial1.flush();
  Serial.println();
  Serial.println("Ready");
  Serial1.println("Central Ready");
}

void loop() {
  if (Serial.available()) {        // If anything comes in Serial (USB),
    Serial1.write(Serial.read());  // read it and send it out Serial1 (pins 0 & 1)
  }

  if (Serial1.available()) {       // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial1.read());  // read it and send it out Serial (USB)
  }
}

void setupBlueToothConnection() {


  //    Serial1.begin(9600);

  Serial1.print("AT");
  delay(400);

  Serial1.print("AT+DEFAULT");  // Restore all setup value to factory setup
  delay(2000);

  Serial1.print("AT+NAMESeeedMaster");  // set the bluetooth name as "SeeedMaster" ,the length of bluetooth name must less than 12 characters.
  delay(400);

  Serial1.print("AT+ROLEM");  // set the bluetooth work in slave mode
  delay(400);

//Serial1.print("AT+BAUD7");
//delay(400);

  Serial1.print("AT+AUTH1");
  delay(400);

  Serial1.print("AT+CLEAR");  // Clear connected device mac address
  delay(400);

  Serial1.flush();
}

And on the peripheral Arduino:

/*Peripheral*/

void setup() {
  Serial.begin(9600);
  Serial.println("PERIPHERAL");
//  Serial1.begin(57600);
  Serial1.begin(9600);
  setupBlueToothConnection();
  Serial.flush();
  Serial1.flush();
  // Serial1.begin(57600);
  // Serial.flush();
  // Serial1.flush();
  Serial.println();
  Serial.println("Ready");
  Serial1.println("Peripheral Ready");
}

void loop() {
  if (Serial.available()) {        // If anything comes in Serial (USB),
    Serial1.write(Serial.read());  // read it and send it out Serial1 (pins 0 & 1)
  }

  if (Serial1.available()) {       // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial1.read());  // read it and send it out Serial (USB)
  }
}


void setupBlueToothConnection() {



  // Serial1.begin(9600);

  Serial1.print("AT");
  delay(400);

  Serial1.print("AT+DEFAULT");  // Restore all setup value to factory setup
  delay(2000);

  Serial1.print("AT+NAMESeeedBTSlave");  // set the bluetooth name as "SeeedBTSlave" ,the length of bluetooth name must less than 12 characters.
  delay(400);

 // Serial1.print("AT+BAUD7");
 // delay(400);

  Serial1.print("AT+PIN0000");  // set the pair code to connect
  delay(400);

  Serial1.print("AT+AUTH1");  //
  delay(400);

  Serial1.flush();
  
}

The code is modified from the SEEED button/LED example as I have hardware serial ports at my disposal, I don't need to use softwareserial. The LED example works.

At standard 9600 I can connect and the two seem to communicate:
Central side:

CENTRAL

Ready
AT+DEFAULTAT+NAMESeeedBTSlaveAT+PIN0000AT+AUTH1Peripheral ReadySent from peripheral

Peripheral side:

PERIPHERAL

Ready
ATAT+DEFAULTAT+NAMESeeedMasterAT+ROLEMAT+AUTH1AT+CLEARCentral Ready
Test

But I seem to be unable to change the Bluetooth (and the computer-Arduino) baudrate to my desired 57600, no matter what I try, the two won't connect anymore.
AT+BAUD7 does not seem to do anything, in the worst case the two bluetooth modules don't seem to connect anymore and I am getting garbage in the Serial monitor.

I tried with init Serial1 at 9600, send the AT+BAUD7, then serial1.flush, then serial1.begin(57600) but nothing seems to work. I would be grateful if anyone has an idea to get the bidirectional communication working at higher baudrates! After that I will tackle attaching my device to serial2 and have it talk via bluetooth :slight_smile:

then a verbal recounting follows.

Amazing.

I am sorry, English is not my first language. High level overview would be better?
And I would have hoped that for the purpose of the question it's a good enough description?
As the basic connection is working but I am unable to change the Baudrates.

Several things could be wrong. First check your wiring against the Wiki - twice. Note that, while the AT commands in the Wiki suggest it might be a BLE, i.e. BT4, device, your Bluetooth v3.0 appears to be a plain-vanilla HC-0x BT2 device, repackaged, and with an extra coat of technobabble. It seems that you are unable to put the device into configuration mode, AT mode, and then make the changes you require. On typical HC-05 modules, this involves pushing a button. On this one it may involve a 3.3v signal on one of the pins. It is far from clear in the pretty useless Wiki, which apparently assumes you already know how to do this, but there appears to be a users' forum that may be helpful.
I raise this because there is no claim in the Wiki that it is a BLE device.

The code per se is pretty ragged but it should work - with the right module, hence my comment about the wiring. The main problem with it is that it doesn't provide any feedback, which is OK if you know what you are doing, but not OK here.

1 Like

Hi
Thank you very much @Nick_Pyner . The module should be "old school" Bluetooth (2.0).
Iiuc BLE would need some kind of vendor specific serial over BLE library and there'd be a deep rabbit hole to go down on it's own getting that working. So I was looking for a "transparent" solution. The wiring to the Arduino Mega2560 is correct as my code works at 9600 and transmits between the two.

On the seeed page are two data sheets, a general one about the HXxx modules in which no photograph agrees with my actual module and https://files.seeedstudio.com/wiki/Grove-Serial_Bluetooth_v3.0/res/Bluetooth_module.pdf which is about the module installed on the seed breakout.
On page 9 is a badly scanned schematic with a part (bottom right) which says baudrate select, no indication given which pins this should correspond to and totally unreadable which baudrate corresponds to which pull-up/down :crazy_face:
(counting on the schematic, this corresponds to pins 25-27, which are just indicated as GPIO in the data sheet...)
I have continued searching for a better picture of the schematic or the data sheet in general, but to no avail so far.

I'd still be grateful for any ideas to try to get my modules to 57600 baud :slight_smile:


LEDs on, showing that the boards are connected at 9600, sketch is working.


A schematic circuit diagram would be better

Well as written several times now, the sketch works at 9600, rx/tx and tx/rx are connected correctly on both boards...

DeadHorse

I made some progress though: I changed to a raspberry pi pico w and used Earle F. Philhower's BT implementation and bam it works. I can connect to my sensor from the computer directly to the pico W over BT, that one connects to the sensor over Serial1 at 57600 and back the other way. Had I known that the pico W supports Bluetooth 2.0 as well as BLE I'd have tried that from the get-go :slight_smile:
Here's the code that works for me on the pico W:

// A very simple Serial-over-BT app that reads input from the host and CAPITALIZES it.
// Released to the public domain by Earle F. Philhower, III, in February 2023

// Under Linux to connect to the PicoW
// 1. Pair to the "PicoW Serial XX:XX..." device using your favorite GUI, entering a PIN of "0000"
// 2. Execute "sudo rfcomm bind 0 00:00:00:00:00:00" to make a `/dev/rfcomm0" device, replacing the "00:00.." with the MAC as listed in the device name
// 3. Run "minicom -D /dev/rfcomm0" and type away
// 4. To remove the virtual serial port, execute "sudo rfcomm release rfcomm0"

// Under Windows to connect to the PicoW
// 1. Pair to the "PicoW Serial XX:XX..." device using the copntrol panel, ignoring any PIN it says to check for
// 2. At this point you will have a new COM: port.  You may need to use the Device Manager to find it's number.
// 3. Open up COMX: in your favorite terminal application and type away

// Under Mac to connect to the PicoW
// 1. Open System Preferences and go in the bluetooth section. You should find a bluetooth device called
//    PicoW Serial XX:XX:... Click Connect button.
// 2. A /dev/tty.PicoWSerialXXXX becomes available.
// 3. Connect to this device with your favorite terminal application.


#include <SerialBT.h>

void setup() {
  Serial1.setFIFOSize(128);
  //Serial1.setRX(1);
  //Serial1.setTX(0);
  Serial1.begin(57600);
  SerialBT.begin(57600);
}

void loop() {
  while (SerialBT) {

    while (SerialBT.available()) {
      Serial1.write(SerialBT.read());
    }

    while (Serial1.available()) {
      SerialBT.write(Serial1.read());
    }

  }
}

I'll not use the seeed boards anymore...

That's really not a solution though.

@runaway_pancake I don't really understand what I did to draw your ire in my first ever post on the Arduino forum?
You come in, mock me, observe the thread and then come in again to state that my solution (which consists in not wasting any more of my precious time on trying to get some badly documented Bluetooth-boards working) is no solution.
Maybe you were interested in how to get your seeed boards to work too? Maybe then you could ask a friendly "oh I figured out this and that and am stuck at this point as well", then the two of us could have tried figuring it out.
I'd be glad to invest some of my spare time to get it running and help the community if that's your goal.

But without that, I am happy to take the shortcut to "really not a solution" and use a compact 6 USD board instead of an Arduino Mega and a 17 Dollar BT-Board in order to get the sensor data to my computer wirelessly at ~10 percent of the hardware cost
Or 5 percent if I were to have continued on my Sensor-Arduino-BT BT-Arduino-computer solution.... The arduinos will find other uses.

I am sure one could use any of the arduino nano*ble/iot/RP2040 variety too to accomplish the same thing, but don't have one handy right now.

@algrauser
A verbal recounting isn't a schematic and throwing in the towel and going with something else isn't a solution.
That's neither mockery nor ire.
Sometimes people can be talked through these things, sometimes not.
I don't see where you noted what steps you took to try to get your modules into AT mode.

If that is really the case, I don't understand what your problem is. I thought you were having grief getting into AT mode but, if the boards are connected, I must now assume you successfully configured one as a master, without too much grief, so it is now merely a matter of sending the appropriate AT+BAUD command.

I actually think ditching the seeeed boards is a pretty good idea - if you can get a refund. You have been right royally ripped off and, if you had bought plain vanilla HC-05s for about $3, you probably wouldn't be fartarsing around like this.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.