Need help in LCD showing Conversion from 'void' to non-scalar type 'String' requested ERROR

Hi I don't know why in this piece of code why conversion from 'void' to non-scalar type 'String' requested Error shows up this is the code

  if (Serial.available()>0){
    String inp = Serial.readStringUntil("\n");
    int charlength = inp.length();
    if (charlength >= 17) {
      String data = inp.remove(0,16);
      lcd.setCursor(0,1)
      lcd.write(data);
    }

on this line String data = inp.remove(0,16);
any help would be appreciated .

remove() modifies the String itself, and does not return a value.

yeah that's the point I want it to print 17th char onwards

inp.remove(0,16) will modify inp, removing the first 16 characters. There is no return value from remove(), so you cannot set another String to the non-existent return value.

    if (charlength >= 17) {
      inp.remove(0,16);
      lcd.write(inp);
    }

Instead of

you could write

String data = inp;
data.remove(0,16);

or

String data = inp.substring(17);

so how could I print 17th onwards?

Any of the suggestions above

its saying no matching function for call to 'LiquidCrystal::write(String&)'

Post your complete code

#include <LiquidCrystal.h>

// initialize the library by associating LCD pins
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  byte smiley[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b10001,
  0b01110,
  0b00000
};
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Hi");
  lcd.createChar(1,smiley);
  lcd.print("I ");
  lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
  lcd.print(" Arduino! ");
  lcd.setCursor(9,0);
  lcd.write((byte)1);
  delay(3000);
  lcd.clear();
}

void loop() {
  // AUJAS type a note over here so you understand what is going on.
  int seconds = millis() / 1000;
  lcd.setCursor(0,0);
  if (Serial.available()>0){
    String inp = Serial.readStringUntil("\n");
    int charlength = inp.length();
    if (charlength >= 17) {
      String data = inp;
      data.remove(0,16);
      lcd.setCursor(0,1);
      lcd.write(data);
    }
    else{
      lcd.write(inp);
    }
     delay(20000);
     lcd.clear();
  }
  if(seconds >= 120 && Serial.available()==0){
    Serial.print("sleeping...");
  }
}

the error is here it is saying lcd.write(inp);

could you kindly help?

No, I cannot see the problem.

Post the complete set of error messages between code tags. There is a button to copy the error messages, above and on the right side of where the messages appear on the IDE.

got any idea?cause I don't

hey @PaulRB got any thing?

Try lcd.print instead of lcd.write

it worked !!!! but why idk

write is used to write byte values to the LCD, either a single byte, or a number of bytes if you also specify how many as a 2nd argument to the write function. write does not know what to do with a String.

print is overloaded to accepts may different types of data, one of which is String, so it is able to send that to the LCD.

1 Like

thanks :grinning:

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