Arduino recieves � data via bluetooth when sending anything

Okay so, the first example of code was originally working, but seems to have since stopped since making changes to other parts of the code. When commenting out the new changes it still doesn’t work. The data gets corrupted. I’ll send a word say ‘chase;’ to the arduino and send what it gets back to the phone, which is ‘c����’ that it recieves.

Here’s the code:

#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>

int bluetoothTx = 1;  // TX-O pin of bluetooth
int bluetoothRx = 0;  // RX-I pin of bluetooth
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;

void setup() {
  bluetooth.begin(9600);
  bluetooth.println("Hello from Arduino");
}

void loop() {
  recieveWithEndMarker();
  parseCommand();
}

void parseCommand() {
  if (newData == true) {
    bluetooth.print("This just in ... ");
    bluetooth.println(receivedChars); // this prints the bad characters
    if (strcmp("color", receivedChars) == 0) { 
      //do cool stuff
    }
    newData = false;
  }
}

void recieveWithEndMarker() {
  static byte ndx = 0;
  char endMarker = ';';
  char rc;
  while (bluetooth.available() > 0 && newData == false) {
    bluetooth.println("Recieving");
    rc = bluetooth.read();
    bluetooth.println(rc); //this prints at first 'c' then the bad character emoji
      if (rc != endMarker) {
          receivedChars[ndx] = rc;
          ndx++;
          if (ndx >= numChars) {
            ndx = numChars - 1;
          }
      } else {
      receivedChars[ndx] = '\0'; // terminate the string
      ndx = 0;
      newData = true;
    }
  }
}

and here’s the code that works, but it uses String which was causing my Arduino to crash, it also has a very long freeze as it reads the entire string, which when i’m trying to multitask the arduino it just doesn’t work. (i then read to never use String as it causes issues) This is just a simple test script i wrote to see if the issue lied with arduino or the HC-06

#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>

int bluetoothTx = 1;  // TX-O pin of bluetooth
int bluetoothRx = 0;  // RX-I pin of bluetooth
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup() {
  bluetooth.begin(9600);
  bluetooth.println("Hello from Arduino");
}

void loop() {
  while (bluetooth.available() > 0) {
    String rc = bluetooth.readString();
    bluetooth.println(rc);
  }
}
    rc = bluetooth.read();
    bluetooth.println(rc); //this prints at first 'c' then the bad character emoji

Using SoftwareSerial, you cannot transmit and receive simultaneously. Plus, you don’t want to put software serial onto hardware serial pins…

Try using this, which waits for a complete message then prints to bluetooth (Note that I moved your bluetooth off of pins zero and one because they are used for hardware serial . It is not a good idea to use those two pins for anything else but hardware serial, unless you really know how to do that)

#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>

const size_t MAX_MESSAGE_LENGTH = 32;

int bluetoothTx = 2;  // TX-O pin of bluetooth . <<<<<<<<<<<<<<<
int bluetoothRx = 3;  // RX-I pin of bluetooth . <<<<<<<<<<<<<<<
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup() {
  Serial.begin(9600);
  bluetooth.begin(9600);
  bluetooth.println("Hello from Arduino");
}

void loop() 
{
  if(const char* newMessage = checkForNewMessage(bluetooth, ';'))
  {
    Serial.print(F("Just Recieved:\t"));
    Serial.println(newMessage);
    bluetooth.print("This just in ... ");
    bluetooth.println(newMessage);
  }
}

const char* checkForNewMessage(Stream& stream, const char endMarker)
{
  static char incomingMessage[MAX_MESSAGE_LENGTH] = "";
  static byte idx = 0;
  if(stream.available())
  {
    incomingMessage[idx] = stream.read();
    if(incomingMessage[idx] == endMarker)
    {
      incomingMessage[idx] = '\0';
      idx = 0;
      return incomingMessage;
    }
    else
    {
      idx++;
      if(idx > MAX_MESSAGE_LENGTH - 1)
      {
        idx = 0;
        incomingMessage[idx] = '\0';
      }
    }
  }
  return nullptr;
}