Hello,
I have an Arduino Mega 2560 board connected to an SH-HC-08 Bluetooth Low Energy Module.
I’m trying connect the module to Blynk through the BLE Widget inside the Blynk app, but it just gets stuck on “Connecting…”, and sometimes displays the message “Connecting… Can’t connect. Please retry or choose another device.”
The devices that I have tried this on: iPhone 7+, Google Nexus 6, and HTC One M8. All 3 have BLE capabilities as far as I know.
I have tried connecting to the SH-HC-08 with AND without pairing it before directly to the phone through the Settings app.
The sketch uploaded to the arduino is blank (just an empty setup and loop), but the Bluetooth module should still connect to the app?!
I will try that in a second. Just to make sure the config on my HC-08 module is fine:
Baud rate is 9600 (Module DEFAULT)
There are 3 types that I can choose:
0. Not need PIN Code (Module DEFAULT)
Auth no PIN
Auth with PIN
Is the baud rate okay and does the type influence anything?
I’m assuming they should all work with the iPhone?
Also, from the example, can I use the other Serial Pins on the Arduino Mega?
For example: using pin 19(which is labeled RX1) and pin 18(which is labeled TX1)?
You can use the hardware serial ports that are on the Mega, but then you need comment out:
// SoftwareSerial SerialBLE(10, 11); // RX, TX
And use:
Serial1.begin(9600); // Use Mega Hard Serial1 wired appropriately to your serial device.
Blynk.begin(Serial1, auth);
The Arduino Mega has three additional serial ports: Serial1 on pins 19 (RX) and 18 (TX), Serial2 on pins 17 (RX) and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX).
This is unrelated to the above topic, but how would I be able to still run code even while Blynk is not connected? Right now if I don’t connect it just sits in setup at the line Blynk.begin(SerialBLE, auth); trying to connect and does not keep going
That is normal… Blynk usually requires a connection to server for most WiFi applications, and connection to the phone/app for BT/BLE connection.
There are alternative connection commands, that will allow “unconnected” sketches to keep running… but I don’t know if they work the same for a BT/BLE application.
I have another question. What’s special about pins 10 and 11? I tried to use other pins such as 2 and 3 on the Mega and Blynk fails to connect when using those
When using SoftwareSerial, the supported pins vary with the Arduino board types.
When using the MEGA, use one of the auxiliary hardware serial options (Serial1, Serial2, Serial3) instead of the Software Serial library, for better reliability.