analyse SoftwareSerial input

Ive written this code to receive an input and react. but Im getting an error message can`t compare pointer to integer (line 15)
please help :astonished:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

void setup()  
{
  mySerial.begin(9600);
  mySerial.println("Device ready");
}

void loop()
{
  if (mySerial.available() )
  {
    char inpt  = mySerial.read();
    if (inpt == "Led_on")
    {
    mySerial.println("turning Led on");
    }
  }
}

moderator edit: added code tags and some indenting

You are trying to compare a single character to an array of them (a string). You will need a more sophisticated method for reading chars into an array try searching for SOP or start of packet in the forums to find an example.

Alternatively, make your sketch respond to commands that are a single character, like this:

   char inpt  = mySerial.read();
    if(inpt == 'H')

Note the single quotes.

Thanks man, it works :slight_smile:

but I can't imagine how to write a method to respond to a string... could you please show an example?

could you please show an example?

#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

it works, but when I print the result i get crap like this: º?ϾÂB????Â
what went wrong?

what went wrong?

Who knows. You posted no code. You said nothing about what is sending data to the Arduioo.

Its just your code with 3 added println-methods:

#include <SoftwareSerial.h>
#define SOP '<'
#define EOP '>'
SoftwareSerial blue(2, 3);

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   blue.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all blue data available, as fast as possible
  while(blue.available() > 0)
  {
    char inChar = blue.read();
    if(inChar == SOP)
    {
      blue.print("start");
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
      blue.println("end");
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        blue.println("get char");
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
        
      }
    }
  }

  // We are here either because all pending blue
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet
    blue.println(inData);
    blue.println("data read");
    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

I've send

I've send

From what? Is that device communicating at 57600?

Yes its still that baud rate you defined