Search code examples
arduinobluetoothsoftware-serial

Arduino sequential softwareserial.print() overwrites itself


I am still having problems with writing from HM-11 bluetooth from DSD tech back to a phone app (Serial Bluetooth Terminal 1.35 on play store).

My code currently has a large string cut into 2, as per the result of my last post, due to BLE havving a maximum buffer of about 252 bytes. The issue I am facing is the fact that the dealy(450) is currently required to prevent gibberish.

    BTSerial.print(F( "============== RGBCube Bluetooth Help ==============\n"
                      "Commands:                                           \n"
                      "  mode:#                 select mode to operate in  \n"
                      "  help                   pull up help screen (this) \n"
                      " Mode 4 only:                                       \n"
                      "  reset                  resets cube to black       \n"
                      "  pt:x,y,z=r,g,b         sets led at (x,y,z) to rgb \n"
                      "  set:r,g,b;r,g,b...     sets entire cube to the    \n"
                      ));
    delay(450);
    BTSerial.print(F( "                         specified colour           \n"
                      "                         64 colours long. Faster    \n"
                      "                         than 64 pt calls           \n"
                      ));

Output with delay:

============== RGBCube Bluetooth Help ============== Commands:
mode:# select mode to operate in
help pull up help screen (this) Mode 4 only:
reset resets cube to black
pt:x,y,z=r,g,b sets led at (x,y,z) to rgb set:r,g,b;r,g,b... sets entire cube to the
specified colour
64 colours long. Faster
than 64 pt calls

without delay:

============== RGBCube Bluetooth Help ============== Commands:
mode:# select mode to operate in
help pull up help screen (this) Mode 4 only:
reset resets cube to black
,b;r,g,b... setspt:x,y,z=r,g,b entire cube to the

I think it is something to do with how fast serial can be cleared out, but this does not make sense to take that long, as 450ms is ridiculously long in computer time, especially at 115200 baud for the bluetooth


Solution

  • From what I have gathered, this is a limitation of the BLE messaging system. There is no such thing as serial communication for BLE, everything is type packet based. Somehow the app on my phone is able to communicate and send it packets up to 252 bytes long and disguise it as serial such that it is not noticeable. After this much, BLE is incapable of sending this much data, and the buffers gets messed up. Someone with more BLE experience may be able to explain, but this is my result.

    To remedy, swap over to regular bluetooth (HC-05, or HC-06 or equivalent, not BLE) which only support serial. As there is no such thing as a typed packet, it works. I just swapped out the component (exact same pinout, so 1 for 1 swap) and issue resolved. Thank you to those above for their suggestions, but this turned out to have been the problem.