Search code examples
arduinobluetoothsoftware-serial

Arduino SoftwareSerial Write bluetooth cutting off static text message write back


I am fairly new to Arduino, so this is likely to be some very simple C/C++ issue that I don't know

I am working on a RGB LED Cube that I made from parts based off of GreatScott's video. It works fine. I decided to improve wahat can be done with it by adding Bluetooth. I am using an HM-11 from DSD tech.

I am able to write commands from my phone to the arduino over bluetooth with no problems, and I use that to swap modes.

The issue I am facing is when I try to write back to my phone over bluetooth. I am sending back help text over bluetooth, so that whoever connects to it and sends help can find a list of supported commands. Using SoftwareSerial, I have the following (snippet of problem area):

if(strcmp(command,"help")==0){


    Serial.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"
                  "                         specified colour           \n"
                  "                         64 colours long. Faster    \n"
                  "                         than 64 pt calls           \n"));


    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"
                  "                         specified colour           \n"
                  "                         64 colours long. Faster    \n"
                  "                         than 64 pt calls           \n"));
  }

When this is runs, the serial port receives:

============== 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

but my phone receives at maximum:

============== 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

As you can see, this is truncated. I have tried many things, including shoving the string into progmem, cutting it apart into smaller stringsm Char array for loops, forcing it to save in flash, etc. Cutting it into smaller strings worked, but I don't really want to do that, as the next thing I want to add to it is a similar length write from phone to arduino.

Sometimes fewer characters make it also, but this is the average, and the maximum, making me think there is some form of limit, but it is not a mulitple of 2 (about 80ish last I counted)

Any help would be greatly appreciated.


Solution

  • It looks like you are able to send about 252 bytes before it gets truncated. That figure seems to be about the maximum data size in a BLE packet.

    There is some discussion around the maximum data size at: Maximum packet length for Bluetooth LE?

    BLE "long read" and "log write" functionality include an offset along with the handle in the request so that the characteristic value can be read/written in successive chunks over multiple request/response pairs. I am not aware if the Arduino library and HM-11 hardware support that functionality or not.