Getting Error: invalid conversion from 'char' to 'const char*'

Hi at all,

coud you please help my tired brain, I'm quite new to C and I can't solve this issue:

invalid conversion from 'char' to 'const char*' [-fpermissive]

Here is my loop:

void loop() {
  // while loop begins here, continous loop:
  char Buf[50];
  if (Serial.available()) {    // check for incoming data --> if available
    delay(20); // just wait a little bit for more characters to arrive
    while (Serial.available())
    {
      inByte = Serial.read();      // store incoming data

      if ((!(inByte == '/')) && (!(inByte == ':'))) {
        text.concat(inByte);
      }
      if (inByte == ':') {
        data[count][0] = text;
        text = "";
      }
      if (inByte == '/') {
        data[count][1] = text;
        text = "";
        count++;
      }
      if (inByte == '#') {
        strip.clear();
        for (int i = 0; i < 154; i++) {
          for (int j = 0; j < count; j++) {
            if (data[j][0].toInt() == i) {
              if (String(data[j][1]) == 'g') {
                strip.setPixelColor(j, 0, 255, 0);
              }
              if (data[j][1] == 'b') {
                strip.setPixelColor(j, 0, 0, 255);
              }
              if (data[j][1] == 'l') {
                strip.setPixelColor(j, 148, 0, 211);
              }
              if (data[j][1] == 'r') {
                strip.setPixelColor(j, 255, 0, 0);
              }

              //Serial.print(i);
              //Serial.print(data[j][1]);
            }
            else {
              strip.setPixelColor(j, 0, 0, 0);
            }
          }
        }
        strip.show();
      }

    }

  }

I defined the variables as follows:

int count;
char inByte;  // incoming serial byte
String text = "";
String data[25][2];

Thank you!

The compiler told you exactly where the problem was, but you chose to make us go look for it.
Why?

(Your code is incomplete)

300 bytes of wasted RAM :open_mouth:

Sorry, was not my intension :wink:

C:\Users\xxx.ino: In function 'void loop()':
C:\Users\xxx.ino:65:41: warning: invalid conversion from 'char' to 'const char*' [-fpermissive]
               if (String(data[j][1]) == 'g') {
                                         ^~~
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232:0,
                 from sketch\iNoWa.ino.cpp:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:143:16: note:   initializing argument 1 of 'unsigned char String::operator==(const char*) const'
  unsigned char operator == (const char *cstr) const {return equals(cstr);}
                ^~~~~~~~
iNoWa:98:1: error: expected '}' at end of input
 }
 ^
exit status 1
expected '}' at end of input

why wasted?

Because an empty String takes 6 bytes.
You appear to be trying to store single characters in Strings.

Each String object takes 6 bytes of memory in addition to the content of the String (or its buffer).
For elements that seem to be mostly characters (1 byte long) this is a massive waste.

You are attempting to compare a string to a single character. The comparison needs to be between strings - put regular double quote marks around the letter "g" instead of single quotes 'g' if you really need to use a string for a single character comparison.

@anon73444976 @Whandall Thank you, ok now I undesrstand.
So for the data array, I should use char instead of string?

But then, how to

data[count][0] = text;

, as text is string type? Sorry, I'm really new into this :wink:

What does your incoming serial data look like?

Perhaps if @constantininthemountains posted their whole sketch we could provide more help

like this, eg:

140:g/120:g/55:b/44:l/67:r/#

Best to avoid Strings. They frequently cause memory problems and program crashes.

You may find this tutorial helpful: Serial Input Basics - updated

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.