Convert Binary to ASCII? LI-FI

hello dear
I’m receiving from a capture light sensor module, an binaire code.
i whould to convert them to code ascii CARACTAIRE
THIS’S THE CODE OF RECEVIER :

for (int i = 0; i < 8; i++) {
if (analogRead(ldr) >= 800)
{ arr = 1; }
_ else{ arr = 0; }_
_ Serial.print(arr*); Serial.print(’\r’);
i++;
delay(200);

*_

Is your code really in italics in the IDE and where is the rest of it ?

Did you neglect to read this before posting a programming question ?

I would love if I could decode binary received over ldr back into ASCII text, but there doesn’t seem to be any documentation out there. For example:

Binary: 0100001001000101001000000101001101010101010100100100010100100000 0101010001001111001000000100010001010010010010010100111001001011 0010000001011001010011110101010101010010001000000100111101010110 010000010100110001010100010010010100111001000101

ASCII:

Also here

a few thing about your code:

delay(200)

is this the time for 1 bit?

not familiar LI-FI protocol but if all you are doing is using it as a media for tx/rx a serial (ie RS-232) byte then how are you determining the START or a byte ie

if no data is tx is “analogRead(ldr) >= 800” for example?

for serial tx for example, the line is HIGH when idle and LOW for 1 bit period to mark the start or a byte.

from there then all you need to do bit shift each read bit into a byte (char type) and print it!

something like this snippet:

void rx_byte(void)
{
    uint8_t data_val;
    uint8_t cnt;
    uint8_t err;

/* pin as input pull up */
    RX_PIN_INPUT_PULLUP();

    while(1)
    {
        data_val = 0U;
        err = 0U;
       
    /* while pin is high */
        while(analogRead(ldr) >= 800);
       
    /* 1.5 bit delay */
        delay(DELAY_US_1_5_BIT);
       
    /* get byte */
        for(cnt = 0U ; cnt < 8U ; cnt++)
        {
            data_val >>= 1;
            if(analogRead(ldr) >= 800) data_val |= 0x80;            
           
            /* 1 bit delay */
            delay(DELAY_US_1_0_BIT);         
        } 
       
    /* stop bit error low */
        if(analogRead(ldr) < 800)
        {
            err = 1;
        } 
}

bear in mind that ‘analogRead’ take some time to process meaning to would need to ‘tune’ all the delay timings to compensate

hope that helps

Try here

Can anyone smell sock?

What is sending the bits?

How does your sketch know when a new character is starting?

How does your sketch know when it is time to read a new bit?

Yes, I disabled that account and opened a new account in which my information is complete

Of course!

That’s the way to do it!

Reported.

0100001001000101001000000101001101010101010100100100010100100000 0101010001001111001000000100010001010010010010010100111001001011 0010000001011001010011110101010101010010001000000100111101010110 010000010100110001010100010010010100111001000101

Change to groups of 8:

01000010 01000101 00100000 01010011 01010101 01010010 01000101 00100000  01010100 01001111 00100000 01000100 01010010 01001001 01001110 01001011  00100000 01011001 01001111 01010101 01010010 00100000 01001111 01010110  01000001 01001100 01010100 01001001 01001110 01000101

Now they are ASCII.

If you want to interpret them manually: change groups of 4 into hexadecimal digits:

42 45 20 53 55 52 45 20 54 4F 20 44 52 49 4E 4B  20 59 4F 55 52 20 4F 56  41 4C 54 49 4E 45

And look them up in a table:
BE SURE TO DRINK YOUR OVALTINE

Lots of merging.

Desockinator deployed.