(Arduino Mega 2560 Board)
I have a program that needs to quickly send and receive small quantities of data over a Serial Port, when the Arduino is ready to receive it.
I am using an HC-05 Bluetooth module, when I run the following Arduino and Processing programs over the USB port of my laptop, every thing goes super fast as intend it too. However when I use the BC-05 to transmit data, there's delay of several hundred milliseconds. (Just read the code you'll get what's going on.)
I spent days trying to fix this, thinking the problem was with the data and the way I was writing/reading it. But after dozens of alterations, it turns out my code was always fine (I think). HC-05 or Bluetooth in general has a truck load of latency between transmissions.
So I wrote a test code to check where the issue is arising. The code is basically a handshake, which happens pretty quickly over the USB A (at the laptop) to USB B (at the Arduino) Cable (Literally ). But over the HC-05, there is an eye watering amount of delay between 2 complete handshakes.
Read files "Arduino code" and "Processing code"**
Have a look at the Console window of Processing to get a better idea of what I'm talking about.
Read files "Processing output over USB" and "Processing output over HC-05"**
Both Console Programs were allowed to run for ~5 seconds.
- When using USB cable:
There's so many handshakes happening so quickly that the original first few outputs are not available in the window!!!!!!(WHICH IS EXACTLY WHAT I NEED)
Notice how there's only about 4 ms delay between handshakes? And there's so many of them that the first few aren't even available in the window anymore (the outputs started printing at about 2000)! (Again exactly what I need)
And now the bone of contention, the issue that has been driving me absolute NUTS since damn 4 days/b]
2. Processing console output when using HC-05
(Again made to run for ~5 seconds)
Nearly 100-150 ms delay !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
And like a handful of handshakes (no pun in-10-dead) in whole 5 seconds! and over usb theres like hundreds per second!
Question 1:
why? why? why WHY? WHY? WHY? WHY? WHY? WHY? WHYYYYYYYY IS this happening???!!!!
Question 2:
Now, I see there's a similar but BT 4.0 HM-10 module. Will that be any better?
Question 3:
My actual goal is to just send data from PC to Arduino over the Internet.
I need bluetooth because I am thinking of doing it this way: from PC ---> Internet ---> Android Smartphone ---> Bluetooth module ---> Arduino.
Will the ESP8266 NodeMCU WIFI module cut out the middleman (Android + Bluetooth mod), AND be able to offer me similar data transfer as that over USB (not including the delay over the Internet of course, that can't be avoided.)
Thanks a ton for making it this far. Please help me I'm on the verge clawing my eyes out trying to troubleshoot this since forever.
Arduino Code.txt (911 Bytes)
Processing Code.txt (438 Bytes)
Processing output over USB.txt (13.6 KB)
Procssing console output over Hc-05.txt (811 Bytes)