Question about lv_textarea_set_text and \n ( newline )

hi there - I am using a serial/mqtt input that is string i convert it to Char using this method below
but it does not seam to recognized \n in the character array sent to lv_textarea_set_text. would you know what I am missing

int part2_len = part2.length() + 1;
char buf[part2_len];
part2.toCharArray(buf, part2_len);
lv_textarea_set_text(ui_TaD2, buf);

sent package consist of this “high: 18\nlow: 6\n20 km/h\n0 mm”
but it does not translate with the newline break
high: 18
low: 6
20 km/h
0 mm
it translate too single line “high: 18\nlow: 6\n20 km/h\n0 mm” in the text area with out the newline breaks

would you have suggestion on a method of correction


Have you enabled lv_text_are_set_one_line_mode? If so it will really ignore \ns to make the text a single line.

An other thing? What happens if you set the text directly?
lv_textarea_set_text(ui_TaD2, "high: 18\nlow: 6\n20 km/h\n0 mm");

when I set it directly it works fine and displays correctly . just when I pass as variable it does not
the serial code looks something like this: i pass this cmd_1(payload) through the serial connection

      char c =;
      if (c == ')')
       command += c;

then it sent tobe parse the cmd reference number and payload

void parseCommand(String com)
//--com variables  
  String part1;
  String part2;  // payload
  part1 = com.substring(6, com.indexOf("("));
  //int test = part1.toInt();
  part2 = com.substring(com.indexOf("(")+1);
  if (part1 == "1")
int part2_len = part2.length() + 1;
char buf[part2_len];
part2.toCharArray(buf, part2_len);
lv_textarea_set_text(ui_TaD2, buf);
//other if statements for different cmd_#( ):

i would like to do it a single operation using \n and hopefully not some more complex way

okay i thought about it. it not as efficient as a single line would be but does the job i guess

I added a payload parse

void parsePayload(String payload)
  //Serial.println("entering parse2");
 // Serial.println(payload); 
  int    ind1 = payload.indexOf('@');  
  String    tmp1 = payload.substring(0, ind1); 
  int tmp1_len = tmp1.length() + 1;
  char line1[tmp1_len];
  tmp1.toCharArray(line1, tmp1_len);  

  int    ind2 = payload.indexOf('@', ind1+1 );  
  String    tmp2 = payload.substring(ind1+1, ind2);  
  int tmp2_len = tmp2.length() + 1;
  char line2[tmp2_len];
  tmp2.toCharArray(line2, tmp2_len);  

  int    ind3 = payload.indexOf('@', ind2+1 );
  String    tmp3 = payload.substring(ind2+1, ind3);
  int tmp3_len = tmp3.length() + 1;
  char line3[tmp3_len];
  tmp3.toCharArray(line3, tmp3_len); 

  int    ind4 = payload.indexOf('@', ind3+1 );
  String    tmp4 = payload.substring(ind3+1);
  int tmp4_len = tmp4.length() + 1;
  char line4[tmp4_len];


and passed it on the line breaks using the @ as delimiter and then using lv_textarea_add_text for the new lines

And does it work this way? :slight_smile:

yes it does work this way. not my favourite way of doing it I use similar method in AI text box. but that only sends a new line every few seconds after it speaks the sentence and when it starts a new sentence it print the next sentence . for line break after such a small amount of characters it causes bottle neck and stuff does not get printed so you have add time delay before each write to get consistent writes