serial read error help

#include <MotorDriver.h>
void setup()
{
  Serial.begin(57600);
}
void loop()
{
  if (Serial.available() > 0)
  {
    char c = Serial.read();  //gets one byte from serial buffer
      Serial.print(c);
      if (c == ',')
  {
if (c == "Square just pressed")
{
  motordriver.goForward();
}

  }
  }}

Arduino: 1.6.5 (Windows 8.1), Board: “Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)”

DavesCarRXwps2.ino: In function ‘void loop()’:
DavesCarRXwps2:14: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
ISO C++ forbids comparison between pointer and integer [-fpermissive]

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

    char c = Serial.read();  //gets one byte from serial buffer
      Serial.print(c);
      if (c == ',')
  {
if (c == "Square just pressed")

How can you reasonably expect a single character, that IS a comma, to also be a string?

i have taken that out but even without it i get the same error. c reads as as it should but i cant add a function when that is read or i get that error

Show us the new code.

c is a single byte, and you are trying to compare it to a string literal.

Even if that wasn’t the case, the logic is flawed, as it could never be both a comma AND that string, so it would never get in there.

If you are going to compare something to a string, the something needs to also be a string, and needs to be compared the correct way.

The correct way is strcmp().

The something is a NULL terminated array of chars, populated by the characters read from the serial port that are NOT commas.

Just to add to PaulS answer, if you do go with strcmp, case matters, "THIS" and "this" are not considered the same.

Also strcmp() returns 0 if both strings match (note the ! before the function ):

char *test_p = "test";

if( !strcmp( test_p, "test" ))
{
    // strings are considered the same
}

no errors with this code but i know something is still not right

#include <MotorDriver.h>
String readString;
void setup()
{
  Serial.begin(57600);
}
void loop()
{
  if (Serial.available())
  {
    char c = Serial.read();  //gets one byte from serial buffer
      Serial.print(c);
      if (readString.length() > 0)
      {
        Serial.println(readString);
        if (readString == "Square just pressed")
        {
          motordriver.goForward();
        }
      }
    }
  }

Just to add to PaulS answer, if you do go with strcmp, case matters, "THIS" and "this" are not considered the same.

stricmp() will ignore case.

i know something is still not right

Care to share what you think is not right?

Aside from the facts that you are using the String class and that you never actually write anything to readString.

well my understanding is more than one char is a string and if the data recieved was printing as "Square just pressed" that i could say if its == to that but i see now its more complicated than that

char c = Serial.read();  //gets one byte from serial buffer

This line, which has your accurate comment on it, highlights why it will not work as it stands.

It reads one character, you have to build up your string by reading from serial until serial is no longer available.

You can then use stricmp() to check your string against a pre-determined command.

Don't confuse Strings with strings. The former is a class, and is generally memory hungry, but includes many helper functions and overloaded operators. The latter is an array of chars. I recommend using the latter.

well my understanding is more than one char is a string

Only if you save the characters.

Right now, you have:

String readString;
      if (readString.length() > 0)
      {
        Serial.println(readString);
        if (readString == "Square just pressed")

Since you never assign readString any new value, it's length will never be greater than 0, nor will the value ever equal "Square just pressed".

so define

String Square just pressed

String Square just released ?

Read Robins tutorial on retrieving data from Serial. Gives a decent primer:

tutorial

Its chapter 8, titled "CHAPTER 8 - RESPONSE FROM USER".

If you follow that you'll have a char array from Serial called "userResponse", it is then just a case of:

if(!stricmp( userResponse, "Square just pressed" ))
{
  // do stuff...
}

What are you sending to the serial port? If you are typing "Square just pressed", then the code you have is looking at each letter. 'S' is not comma, so throw it away. 'q' is not comma, so throw it away. Etc.

Is that REALLY what you want? Or, do you want: 'S' is not comma, so add it to readString. 'q' is not comma, so add it to readString. etc.

#include <MotorDriver.h>
String readString;
unsigned long currentMillis;

//======for user question========
const char question[] = "Please type some text and press ENTER";
const unsigned long questionInterval = 5000;
unsigned long prevResponseMillis = 0;
boolean waitingForResponse = false;

//=====for user response=========
const byte buffSize = 31;
char userResponse[buffSize];
const char endMarker = '\r';
byte bytesRecvd = 0;
boolean ackResponse = false;

void setup()
{
  Serial.begin(57600);
}
void loop()
{
  currentMillis = millis();
    askForUserInput();
    getUserResponse();
    acknowledgeResponse();


    if(!stricmp( userResponse, "Square just pressed" ))
{
  motordriver.goForward();
}
  }
  
  void askForUserInput() {
  if (waitingForResponse == true) {
    return;
  }
  
  if (currentMillis - prevResponseMillis >= questionInterval) {
    Serial.println(question);
    waitingForResponse = true;
    bytesRecvd = 0;
  }
}

void getUserResponse() {
  if (waitingForResponse == false) {
    return;
  }

  if(Serial.available() == 0) {
    return;
  }

  char inChar = Serial.read();
   
  if (inChar != endMarker) {
    userResponse[bytesRecvd] = inChar;
    bytesRecvd ++;
    if (bytesRecvd == buffSize) {
      bytesRecvd = buffSize - 1;
    }
  }
  else { // inChar is the endMarker
    waitingForResponse = false;
    userResponse[bytesRecvd] = 0;
    prevResponseMillis = currentMillis;
    ackResponse = true;
    
  }
}
void acknowledgeResponse() {
  if (ackResponse == false) {
    return;
  }
  Serial.println();
  Serial.println("Thank you");
  Serial.print("You entered the following ");
  Serial.print(bytesRecvd);
  Serial.println(" bytes ");
  Serial.print(" --- ");
  Serial.println(userResponse);
  Serial.println();
  
  ackResponse = false;
}

Arduino: 1.6.5 (Windows 8.1), Board: “Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)”

DavesCarRXwps2.ino: In function ‘void loop()’:
DavesCarRXwps2:30: error: ‘stricmp’ was not declared in this scope
‘stricmp’ was not declared in this scope

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

'stricmp' was not declared in this scope

So, don't use stricmp(). The String class has a toUpper() method and a toLower() method. Pick one, and make the literal match case.

that just changes it to lower or upper case right?

merkzilla: that just changes it to lower or upper case right?

Yes. What that accomplishes is allowing "SquARe C PreSSed" to be entered, but still match "square c pressed" or "SQUARE C PRESSED", depending on whether you convert to lower or upper case.

this should serial print in all upper case as well then right? butthis code still does not fallow through with the function

#include <MotorDriver.h>
String readString;
void setup()
{
  Serial.begin(57600);
}
void loop()
{
  if (Serial.available())
  {
    char c = Serial.read();  //gets one byte from serial buffer
      Serial.print(c);
      if (readString.length() > 0)
      { 
        readString.toUpperCase();
        Serial.println(readString);
        if (readString == "SQUARE JUST PRESSED")
        {
          motordriver.goForward();
        }
      }
    }
  }

Instead of the non-standard stricmp function, try the standard strcasecmp function.