0

I'm trying to make an RC controller.

I have a problem with my LCD.

Lcd with japanese and indescribable char like

I have already double-checked the wiring and the connections are great.

I made a PCB with Kicad and order it to JLCPCB. I have some mistake, you can see the soldered wire.

PCB designed with kicad and made by JLCPCB

Schema Kicad

Before the PCB, I did my project with a breadboard and it worked fine.

const String menuElem[4] = {"Models", "Trims", "Reverse command", "Channel"};

const int rs = 3, en = 4, d4 = 5, d5 = 6, d6 = 7, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void menu() {
  lcd.clear();
  //lcd.setCursor(0,0);
  //byte pos = 0;
  //int sizeOfanArray = *(&array + 1) - array;
  byte menuElemLength = *(&menuElem + 1) - menuElem;
  for (byte i = 0; i < menuElemLength; i++) {
    lcd.setCursor(2, i);
    lcd.println(menuElem[i]);
  }
  showMenuNav(currentMenuPos);
}
3
  • 1
    try const char* menuElem[4] = {"Models", "Trims", "Reverse command", "Channel"}; – Juraj Jan 25 at 18:45
  • The pictures of your custom board and wiring job don't really tell us anything. It looks to me like you have a bug in your code. You're getting SOME characters from your strings, which tells me that the LCD is working. It looks to me like your strings are being sent with the wrong lengths. – Duncan C Jan 25 at 19:22
  • Thank you @Juraj it solves the problem. I understand my mistake. I replaced String by char* in my code and in every class. I use strcat to concatenate my char* but I don't know if this is the best solution. @DuncanC Yes, at start i believed that I have bad connection or something like that. – 2CoB9 Jan 25 at 19:34
2

Your code to calculate the length of your Strings does not make sense. The String type is an object type. The addresses of your String objects will not match the length of the charcters in those strings. You should use an array of C strings as suggested by Juraj, and then you should use strlen() to get the length of those strings (C strings have a null terminating byte, and strlen() uses that null to calculate the length. Note that C strings can't handle Unicode.)

The String type is best avoided on Arduino anyway, as String objects tend to fragment the extremely limited heap memory on Arduino devices and cause out-of-memory crashes.

1
  • Yes, my mistake is to use a String object like a char* pointer. I would use ``char*` pointer instead of String object in my future code. Thank you for your reply! – 2CoB9 Jan 25 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.