I'm working on an Arduino project that sets up comms to an amateur radio through Bluetooth.
I have the code working perfectly when I load it into my ESP32 WROOM (runs over 1400 cycles of reading data every second without and error, all at about 10ms response time). But when I load the same code into my test Arduino MEGA (minor changes for Port Name) with an HC-05 connected to Serial3, the comms is very intermittent. I can get some responses through in 10ms, and they vary up to 2 seconds, and others appear to be lost (timeout).
I'm using the exact same code between the two devices, the ESP32 & Arduino MEGA/HC-05.
Actually, I have a second Arduino MEGA/HC-05 that is in use in my project, and it fails the same way (basically it's a duplicate MEGA & HC-05, it's not hardware error that I can tell).
The ESP32 and MEGA/HC-05 are slave mode in Bluetooth.
I have tried setting the HC-05 using 38400, 57600 & 115200 Baud (HC-05 "at+uart="...) Still intermittent response times, some fail, etc.
Questions:
Does the "at+uart=" AT command just set the serial comms rate, or does it ALSO set the Bluetooth baud rate?
What is the difference between the ESP32 and the MEGA/HC-05?
Any suggestions one where to look to try to solve the problem with the intermittent comms errors?
Could it be that the HC-05's that I have are what is at fault here?
I've been fighting this problem for months and can't find a solution.
You need to set the baud rate of your serial line to match the baud rate of the module. The BT communication rate is determined by the Bluetooth version and PHY.
Your esp has way more ram and is much faster and it’s not the same BT version (up to 5 versus 2)
do yourself a favour and please read How to get the best out of this forum and provide the code and necessary documentation. (Ie issue might be in your code for example)
Don’t think so. DIfferences between the 2 setup are big
Thanks for the response!
I read your response earlier this morning and I've been pondering it.
I had to look up the "PHY", understood...
Makes sense that the newer version would be more reliable. I've also been reading up on the Version 5...
I didn't want to include code, mostly because the code works with the ESP32, and I didn't figure that that was the problem. I tried to be as specific as possible.
Can you recommend another device, similar (connections) to the HC-05 that would support the BT version 5? Do you think an HM-10 would work for me?
I can't use the ESP32 because I have WAY too much design & hardware invested in the Arduino MEGA for this project, to start all over again. Also the ESP32 doesn't have the hardware support (pins, comm ports, etc.) that I need. Basically, I'm trying to add Bluetooth to an existing project.
I also found an HM-18 as a possibility... (Version 5, where the HM-10 appears to be Version 4.0).
The Bluetooth device (current HC-05) is connected to the Arduino MEGA via Serial3 Rx/Tx pins, setup as a slave device.
The master is an ICOM IC-705 amateur radio. It seems to handle most protocols:
Specifications show: Bluetooth
• Version: Bluetooth Version 4.2
• Transmission Output: Class 2
• Profile: HFP, HSP, SPP, GATT (Serial) over LE
• The maximum number of paired Bluetooth devices: 7 devices
• Maximum headsets or data devices are 4 devices each, and the maximum combination is 5 devices in total. Maximum Bluetooth Low Energy devices are 2 devices.
It's unclear to me what code you were using on the esp32 to work with the ICOM radio, as the esp32 has both classic bluetooth and Bluetooth Low Energy.
There is nothing that I'm doing in the setup() or loop() in order to get the comms to work.
I both cases, the Bluetooth connection is made as soon as power is added to the device. For the ESP32, when I reload code, I have to do a quick "Connect" in the Bluetooth menu or the radio. In the case of the HC-05, I don't loose the connection unless I remove power.
//ESP32 Specific:
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
and add:
void setup()
{
Serial.begin(115200);
SerialBT.begin("IC-705-ESP"); //Bluetooth device name
All the rest of the code is identical (other than renaming "Serial3" to "SerialBT" through the comms code.
I did order an HM-10 (version 4) and an HM-18 (version 5) to play with, see what happens with those devices.
Maybe ICOM has Bluetooth 2 as well, which you need to confirm, but, in the light of the above, I submit this entire thread is stuff and nonsense, and you will be well-advised to read reply #6 twice. It may be that you are simply making a bad use of words. Classic Bluetooth 2 devices can see BLE devices but that's as far as it goes. I guess it is faintly possible that your HC-05 can indeed connect with the radio, but you need to understand the difference between connect and communicate, and the former is irrelevant when there is none of the latter.
Bluetooth Low Energy (BLE) is a subset of Bluetooth v4.0 - meaning if you have a BT 4.x compliant device, it will often offer the standard BT stuff and BLE stuff.
In general, Bluetooth is backwards compatible: Bluetooth devices supporting the Bluetooth 4.2 standard should still be able to pair with devices using, say, the ancient Bluetooth 2.1, launched back in 2007
So I don't think it's nonsense and it's possible for the HC-05 to connect to the BT4.2 stack using SPP if this is a profile offered by the ICOM radio and it's possible that when using the ESP - depending on the code being used - that BLE is used (leading to different performance and behavior. an HC-05 could auto-pair with a previously known slave if within range)
The HM-18 device I ordered came in which is Version 5, and I've been trying to get it to connect, but I can't see it on my radio (ICOM IC-705) when I search for a "Data" device. There is also a headset search, but it doesn't come up there either. The radio is a Bluetooth Version 4.2.
I've renamed it to LDMOS-18 and I can see it on my Android phone as a device that I can connect to, so it is appears to be discoverable. There is a limit of 4 data devices on the radio, and I currently have only 2. (Yes, I've power cycled both.)
The AT parameters that I've set are (besides the name) are:
AT+BAUD7 (115200 baud) and AT+BAUD6 (57600 baud) and AT+BAUD5 (38400 baud)
AT+MODE1 (default Limited remote-control mode + Mode 0) & AT+MODE0 (transmission Mode)
AT+ROLE0 (called peripheral, which is I believe same as slave mode)
Is there some other parameter that I need to change to have it discoverable on my radio as a data device?
I've googled around and it appears that the 5.0 should be compatible with the 4.2.
Incidentally, I have a v4.2 (HM-10) device on order, waiting to come in...
The HM-18 does not offer BT 2.0 / SPP compatibility
so it's down to GATT (Generic Attribute Profile) over LE. It defines the way that two Bluetooth Low Energy devices transfer data back and forth using Services and Characteristics. probably need to dig into AT commands for this
When you are out BLE territory, it's all driven by profiles. So your radio was probably discussing using BT 2.x with the SPP profile with the HC-05
the HM-18 does not offer an SPP profile, and probably none of the 2 other supported profiles (HFP = Hands-Free Profile, HSP = Headset Profile) and does not Handle SPP.
The only "common" way of communication seems thus to be GATT that allows exchange of information using something close to "publish & subscribe" type of pattern.
All that AT+BAUD stuff has nothing to do with seeing it on the radio. I don't know anything about the HM-18 other than that it is a BLE device, and therefore should able to be seen by and connected to another BLE device - particularly as the spec suggests it is also kosher for v4.2. To do that, it should need no more than the appropriate power supply connected. So, what is the power supply situation?
I would assume that the « pairing » should be initiated using GATT by the HM-18. Once connected you could scan for exposed services and characteristics and see there something - possibly R/W - that lets you interact with the device.
Pairing per se is not done with BLE. No prearranged dance card, like HC-05. I imagine that applies to all BLE but my limited experience actually applies only to HM-10.
I’m still stumped.
The HM-10 (Version 4.0) that I ordered also came in and to my surprise, does not show up on my radio either! One thing that’s different about the HM-10 is that the AT command protocol requires no CR/NL to get it to work…
I’ve tried many of the same things with the HM-10 as I did with the HM-18. I see what you are suggesting in that the baud rate wouldn’t make a difference on the initial connection.
I have an ESP32 (version BT 5.0) that connects and works great! I wanted to compare the settings, but currently I’m unable to get the AT commands to work with it.
I’m still trying to find something on the web to explain the connection, protocols and how it may relate to the AT commands.
So am I....
HM-10 is as plain vanilla as you can get, but should be entirely adequate, so long as the radio is sending plain-vanilla data. If you can get ESP to work, you clearly know what you are doing - essentially - so maybe there is something truly stupid going on, something that will only happen once. I can only suggest that you try having Mega send a hellohello via HM-10 to a BLE terminal on the phone, like that by Morisch. I say this because, if it works, you can confidently point the bone at the Radio.
Note that the above may involve a proper serial BLE programme. I have found HM-10 unreliable, but that is likely to be because I have used it like an HC-05.