String to byte

Hi, How can I convert string(char*) representation of byte (received through serial and cmdmessanger). I would like to send 8 bytes in format 0b0000,0b11111.... and then fill byte array to display lcd.char. Thanks in advance

and then fill byte array

With what?

to display lcd.char.

If you want to display characters on an LCD, why would you not use a char array?

I guess I was not clear enough. Here is part of my code so you can get better picture :)

void cdisplaychar(){
  lcd.setCursor(cmdMessenger.readInt16Arg(),cmdMessenger.readInt16Arg());
  byte lchar[8]={cmdMessenger.readStringArg(),cmdMessenger.readStringArg().........}; //8 times
  lcd.createChar(0,lchar); 
  lcd.write(0);
}

So idea is to send from PC something like: 1,0,0,0b11111,0b10001,0b10001,0b10001,0b10001,0b10001,0b10001,0b11111; there is lcd char generator at omerk.github.io/lcdchargen ...

This code obviously can not work because lchar is byte and can not be filled with char* returned by cmdMessanger.readStringArg(). So question is how to convert it to byte from char* hat is binary representation of byte.

This code obviously can not work because lchar is byte and can not be filled with char* returned by cmdMessanger.readStringArg().

The obvious question is why is lchar a byte array? The type of the variable on the left of the equal sign should be the same as the type the function on the left is returning.

The second question is why you are using char in the name of a variable whose type is not char.

The third question is why anyone on his/her right mind would use l as the first letter of a variable name, unless the name as lightXXX or leftXXX or lastXXX where the l is clearly distinguishable (by context, not shape) from a 1.

The first line of code in your snippet should be:

char *whatToShow = cmdMessenger.readStringArg();

The function returns a pointer to a collection of characters, not a single character.

The next line may require that you lie to the compiler. Don’t worry, though, you won’t rot in hell for this little lie:
lcd.createChar(0,(byte *)whatToShow);

The obvious question is why is lchar a byte array?

Im not thst good at programing and I tend to use premade libraries. So lcd library has example and this is how it looks:

byte armsUp[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b10101,
  0b01110,
  0b00100,
  0b00100,
  0b01010
};
lcd.createChar(4, armsUp);
lcd.write(4);

The second question is why you are using char in the name of a variable whose type is not char.

LCD Character not variable type ::)

he third question is why anyone on his/her right mind would use l as the first letter of a variable name

You are absolutely right... point taken...

Im still at the begging of my problem... I guess I unnecessary complicated question. Ill try to make it simple. How can I convert: char* something="0b11111" to byte something_else that equals 31?

How can I convert: char* something=“0b11111” to byte something_else that equals 31?

Why would you send “0b” as the start of the string, when you KNOW that the string contains the binary representation of a value?

If you can’t prevent sending/storing “0b”, then removing it is pretty simple:
something[0] = ’ ';
something[1] = ’ ';

Then, converting " 11111" to a byte simply involves a for loop:

byte equivalent = 0;
for(byte i=0; i<strlen(something); i++)
{
   if(something[i] == '0')
   {
      equivalent *= 2;
   }
   else if(something[i] == '1')
   {
      equivalent *= 2;
      equivalent++;
   }
}

equivalent starts out 0. The first one makes equivalent 1. The second ‘1’ makes equivalent 3 (2 * 1 + 1). The next one makes it 7, then 15, then 31.

Great. Thank you!