Datenübertragungsproblem (Android -> HC05)

Hallo Leute!
Ich bin gerade dabei meinen Infinity Mirror zu bauen und bin auf ein Problem gestoßen:

Über ein Terminal-Programm, welches auf meinem Android-Handy läuft, würde ich gerne meinen RGB-LED-Streifen steuern. Problem bei der ganzen Sache ist jedoch: Wenn ich am Handy zum Beispiel "CR70" (Control Red auf den Wert 70) eingebe, kommt beim Arduino Nano jedoch nur "CR0" an. Der "7" wird bei der Übertragung einfach weggeschnitten und ich kann mit dem Befehl "CR0" nichts anfangen. Mit dem Befehl würde normalerweise der RGB-Rot-Wert auf 70 festgelegt werden.

Danke schon mal im Vorfeld!
Bin gespannt auf eure Ideen.

Code:

// strip.setPixelColor(i, strip.Color( red,   green,   blue));


#include <Adafruit_NeoPixel.h>
#include "string.h"

#define LED 6                               // Pin für die Kommunikation mit den LEDS
#define PIXELS 288                          // Anzahl der verwendeten LEDs

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, LED, NEO_GRB + NEO_KHZ800);   //strip ist jetzt der LED-Streifen

char bluetooth[32];    //Übergabewert von Bluetooth-Modul

// RED
int red = 0;          //Rot-Wert
int redLengh = 0;     //Zählen wie Lang der Rot-Wert ist
int R_pos = 0;        //Bestimmung des Anfangs von Rot-Wert (bei R immer 0)
char R[3];            //Char um den Rot-Wert umzuwandeln

// GREEN:
int green = 0;
int greenLengh = 0;
int G_pos = 0;
char G[3];

// BLUE:
int blue = 0;
int blueLengh = 0;
int B_pos = 0;
char B[3];

int pos = 0;
int textpos = 0;

// Times:
int time_rainbow = millis();
int time_pulse = millis();

//Counter:
int einlesen = 0;

//Manuel:
char manred[3];
char mangreen[3];
char manblue[3];
int man_red = 0;
int man_green = 0;
int man_blue = 0;

//Status:
bool st_rainbow = false;


void Option_Colour_Circle()
{
  for (int i = 0; i < PIXELS; i++)
  {
    strip.setPixelColor(i, strip.Color(red, green, blue));
  }
}


void bluetooth_Auswerten()
{
  pos = 0;                                      // pos zurücksetzen

  if (bluetooth[pos] == 'R')                    // testen ob an Stringstelle Pos ein R steht
  {
    for (int i = 0; i < 3; i++)                 // Maximal 3 R-Stellen möglich
    {
      redLengh++;                               // Anzahl an R-Stellen herausfinden
      pos++;                                    // Arraystelle erhöhen
      if (bluetooth[pos + 1] == 'G')            // Schauen ob die nächste Stelle ein G ist
      {
        G_pos = pos;                            // G-Stelle merken
        break;                                  // Schleife abbrechen
      }
    }
  }
  if (bluetooth[pos] == 'G')
  {
    for (int i = 0; i < 3; i++)
    {
      greenLengh++;
      pos++;
      if (bluetooth[pos + 1] == 'B')
      {
        B_pos = pos;
        break;
      }
    }
  }
  if (bluetooth[pos] == 'B')
  {
    for (int i = 0; i < 3; i++)
    {
      blueLengh++;
      pos++;
      if (bluetooth[pos + 1] == '\n')
      {
        break;
      }
    }
  }

  for (int i = 0 ; i < 3; i++)                     // Maximale Farbanzahl = 3
  {
    if (i < redLengh)                              // Farb-Array beschreiben
    {
      R[i] = bluetooth[R_pos + i];                 // Gemerkte Farbstelle + Laufvariable auf Farb-Array schreiben
      R[i + 1] = '\n';                             // Falls der Farbwert < 100 ist -> Array abschließen
    }
    if (i < greenLengh)
    {
      G[i] = bluetooth[G_pos + i];
      G[i + 1] = '\n';
    }
    if (i < blueLengh)
    {
      B[i] = bluetooth[B_pos + i];
      B[i + 1] = '\n';
    }
  }
  red = atoi(R);                                   // Farb-Array auf int Variable schreiben
  green = atoi(G);
  blue = atoi(B);

}
void Rainbow()
{

  for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256)
  {
    if (Serial.available())
    {
      char c = Serial.read();
      Serial.print(c);
      bluetooth[textpos] = c;
      textpos++;

      if (c == '\n')                 // Aktion bei "Neue Zeile" Zeichen
      {
        bluetooth[textpos] = 0;      // Texte mit 0 Zeichen abschließen !!!
        textpos = 0;
      }
      if (strstr("AUS", bluetooth))
      {
        aus();
        
        break;
      }
    }
    if (millis() - time_rainbow > 10)
    {
      time_rainbow = millis();
      for (int i = 0; i < strip.numPixels(); i++)
      {
        int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
        strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
      }
      strip.show();
    }
  }
  
  if (strstr("AUS", bluetooth))
  {
    aus();
    
  }
  else
    Rainbow();
}

void aus()
{
  man_red = 0;
  man_green = 0;
  man_blue = 0;
  for (int i = 0; i < PIXELS; i++)
  {
    strip.setPixelColor(i, strip.Color( 0,   0,   0));
  }
  strip.show();
  
  
}
void white()
{
  for (int i = 0; i < PIXELS; i++)
  {
    strip.setPixelColor(i, strip.Color( 255,   255,   255));
  }
  strip.show();
  
}

void colorWipe(uint32_t color) {
  for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
    if (Serial.available())
    {
      char c = Serial.read();
      Serial.print(c);
      bluetooth[textpos] = c;
      textpos++;

      if (c == '\n')                 // Aktion bei "Neue Zeile" Zeichen
      {
        bluetooth[textpos] = 0;      // Texte mit 0 Zeichen abschließen !!!
        textpos = 0;
      }
      if (strstr("AUS", bluetooth))
      {
        aus();
        break;
      }
    }
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    strip.show();                          //  Update strip to match

  }
}

void Pulse()
{
  if (strstr("AUS", bluetooth))
  {
    aus();
  }
  else
  {
    colorWipe(strip.Color(255,   0,   0)); // Red
    colorWipe(strip.Color(  0, 255,   0)); // Green
    colorWipe(strip.Color(  0,   0, 255)); // Blue
    Pulse();
  }
}



void manuel()
{
  if (bluetooth[1] == 'R')
  {
    manred[0] = bluetooth[2];
    manred[1] = bluetooth[3];
    manred[2] = bluetooth[4];
    man_red = atoi(manred);
  }
  if (bluetooth[1] == 'G')
  {
    mangreen[0] = bluetooth[2];
    mangreen[1] = bluetooth[3];
    mangreen[2] = bluetooth[4];
    man_green = atoi(mangreen);
  }
  if (bluetooth[1] == 'B')
  {
    manblue[0] = bluetooth[2];
    manblue[1] = bluetooth[3];
    manblue[2] = bluetooth[4];
    man_blue = atoi(manblue);
  }

  for (int i = 0; i < PIXELS; i++)
  {
    strip.setPixelColor(i, strip.Color( man_red,   man_green,   man_blue));
  }
  strip.show();
}

void setup()
{
  pinMode(LED, OUTPUT);

  strip.begin();
  strip.show();             // Alle LEDs aus
  strip.setBrightness(50);
  Serial.begin(9600);      // Serielle Kommunikation aufbauen
}
void loop()
{
  if (Serial.available())
  {
    char c = Serial.read();
    Serial.print(c);
    bluetooth[textpos] = c;
    textpos++;

    if (c == '\n')                 // Aktion bei "Neue Zeile" Zeichen
    {
      bluetooth[textpos] = 0;      // Texte mit 0 Zeichen abschließen !!!
      textpos = 0;
    }
  }
  if (strstr(bluetooth, "Rainbow"))
  {
    
    Rainbow();
  }
  else if (strstr(bluetooth, "AUS" ))
  {
    
    bluetooth[0] == '0';
    aus();
    
  }
  else if (strstr(bluetooth, "Pulse"))
  {
    
    Pulse();
  }
  else if (strstr(bluetooth, "Manuel"))
  {
   
    manuel();
  }
  else if (bluetooth[0] == 'C')
  {
   
    manuel();
  }
  else if (strstr(bluetooth, "WEISS"))
  {
    
    white();
    
  }
 
  //bluetooth_Auswerten();                  // Auswerten des bluetooth-arrays
  //Option_Colour_Circle();                 // Alle LEDs auf die gewünschte Farbe stellen

}

Bluetooth.ino (1.9 KB)

Was meinst Du, sollen wir ohne Kenntnis Deines Sketches dazu sagen?
Wenn Du Dir sicher bist, dass nur CR0 ankommt, dann wird das wohl am sendenden Programm liegen.

Gruß Tommy

Ich entschuldige mich jetzt schon für meinen Programmierstil, bin noch nicht besonders erfahren was das Programmieren angeht.

Bluetooth.ino (1.9 KB)

    if (bluetooth[einlesen+1] == '\n')

Das scheint etwas seltsam. Du solltest vor dem Abspeichern überprüfen ob du das Linefeed hast. Und nur das Abspeichern was wirklich Text ist. Das LF gehört eigentlich nicht in das Array, auch wenn es nicht immer schadet

Hier ist eine Einlese-Funktion die richtig funktioniert:
https://forum.arduino.cc/index.php?topic=634159.msg4293510#msg4293510
Erklärung dazu hier:
https://forum.arduino.cc/index.php?topic=637784.msg4317883#msg4317883

@TO: Setze Deinen Code bitte in Codetags (</>-Button oben links im Forumseditor oder [code] davor und [/code] dahinter ohne *).
So ist er auch auf portablen Geräten lesbar. Das kannst Du auch noch nachträglich ändern.

Gruß Tommy