Hello again,
my actual project is a windowsphone app. With this app i want to control some led lights over bluetooth -> means that a command string comes over softwareserial
I have already solved a lot myself, but now I need support.
First Problem is that these 2 Lines only prints an empty row on the serial console, but not the word TEST.
In a simple sketch this is working good! But not in my program, an i don't know why.
look at the simple example at the bottom
String pointer5 = "TEST";
Serial.println(pointer5);
Second, this has not worked:
if (pointer[5] == "True" {
}
.
.
Is there a solution?
#include <WS2811Driver.h>
#include <SoftwareSerial.h>
const int TX_BT = 13;
const int RX_BT = 12;
const int PIN_RED = 2;
const int PIN_GREEN = 14;
const int PIN_YELLOW = 7;
const int PIN_PROXIMITY_SENSOR = 5;
SoftwareSerial btSerial(TX_BT, RX_BT);
byte leds0[30];
WS2811Driver ledStrip;
const char* color = "";
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
int commandSize = 0;
int commandPos = 0;
char command[40];
char *pointer[6];
void processCommand(char* command) {
btSerial.end();
char *p = command;
char *str;
int i =0;
while ((str = strtok_r(p, ",", &p)) != NULL) // delimiter is comma
{
pointer[i] = str;
i++;
}
Serial.println("NEW COMMAND");
Serial.println(pointer[0]);
Serial.println(pointer[1]);
Serial.println(pointer[2]);
Serial.println(pointer[3]);
Serial.println(pointer[4]);
Serial.println(pointer[5]);
String pointer5 = "TEST";
Serial.println(pointer5); //This Line is printing an empty row, not TEST
btSerial.begin(9600);
}
//Setup MSP430 function
void setup() {
Serial.begin(9600);
//Serial.println("USB Connected");
btSerial.begin(9600);
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_YELLOW, OUTPUT);
pinMode(PIN_PROXIMITY_SENSOR, INPUT_PULLUP);
ledStrip.setLEDCount(10); // setup for 4 leds on a strip
ledStrip.begin();
}
//Loop MSP430 function
void loop() {
if(btSerial.available()) {
commandSize = (int)btSerial.read();
commandPos = 0;
while(commandPos < commandSize) {
if(btSerial.available()) {
char buffer = btSerial.read();
if(buffer == SOP) {
commandPos = 0;
command[commandPos] = '\0';
started = true;
ended = false;
}
else if(buffer == EOP){
ended = true;
break;
}
else
{
command[commandPos] = buffer;
commandPos++;
command[commandPos] = '\0';
}
}
} //end while
}
if(started && ended)
{
// The end of packet marker arrived. Process the packet
processCommand(command);
// Reset for the next packet
started = false;
ended = false;
commandPos = 0;
command[commandPos] = '\0';
}
} //this is the end
This is the console output:
Update: if I do not turn on software serial, the output of the strings works again
here's some simpler code which shows the strange behavior:
#include <SoftwareSerial.h>
String text = "blablabla";
SoftwareSerial btSerial(P1_4, P1_3);
char command[40];
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
//btSerial.begin(9600); // if you uncomment this line, the String text is not printed:
}
void processCommand(char* command) {
btSerial.end();
Serial.println("HELLO");
Serial.println(text); //works only with btSerial.begin(9600) commentet above
}
void loop() {
processCommand(command);
delay(500);
}