If I just have a small sketch that only prints the bluetooth input everything works perfect.
But if I add this part to a larger sketch it sometimes just gets weird strings like you would get when you have set the wrong baud rate.
I'm using an arduino nano and a ble bluetooth module (hm-10 I think).
And I'm using "Serial Bluetooth Terminal" to send the commands from android to the bluetooth module.
I'm also using Software Serial on pin 8 and 9
It will be really hard to help unless you post your sketches.
I cannot send you the sketch but maybe I can reproduce the problem in an other, smaller sketch.
But is there something I have to keep in mind?
Because it does work in a really small sketch where only the bluetooth string get received and printed
but in an larger sketch there are sometimes wrong characters
(like "mo+m{c{⸮c⸮v⸮&VV⸮&VV⸮" instead of "mode_color") but after resending the command it does work correctly.
So I often need to send the command twice. The first one gets wrong characters and the second one does work.
Ok the problem occurs when for example:
I have a mode that changes the color of each LED to a random color and this repeats really fast (like a hardstyle dubstep flashing led-strip).
If I have a mode that slowly changes the color of all LEDs the problem does not occur.
So I think it is not directly a problem in my code. I think that it is because the first example executes really fast without a delay or with a really short delay and the second one executes really slow with a longer delay.
But what is a workaround for this if I need to execute some functions really fast?
My Code looks like this:
First check if (softSerial.available() > 0
then I have a 500ms delay just in case
then I create a string with the Bluetooth input
then I use the information to set the mode, color, speed etc.
and then I'm running the mode
Sorry for not uploading a sketch but hopefully I have time tomorrow to create a simplified version to upload
Ok so I found out that using SoftwareSerial should be avoided if possible and I changed my code to use HardwareSerial and now it does work. The only problem is that uploading a sketch while using the rx pin does not work but I guess that this is just a limitation that cant be avoided (on boards with only one serial port).