Hi,
I have to do a project, where I need to transfer data from one ESP32 to another with light (optical fiber). One has keyboard with led and other one display. I can choose from 0-9, and I want to send it to the other one digitally.
I need to convert a char that I get from keyboard to binary array.
change a state of led to indicate that I am about to send some data
begin sending the data by blinking a led with the stored 1s and 0s in array
on the other one save received bits into array
transfer that binary array back to char so I can print it out on display
I know how to send and receive data, but I don't know how to transfer char like '4' to binary array and back. Can someone help with that ?
Do you actually need to convert the char to a binary array ? Why not read the bits of the char variable using the bitRead() function and use their values
Oh okay but how can I then send the bits one by one with the LED ? I was thinking to store them into array and then use for to cycle all stored 1s 0s. I am open to any suggestions even if you send some link or small code to represent how would you solve this problem.
for example I receive from keyboard '0'
in ASCII:
0, dec: 48, hex: 30, oct: 60, bin: 110000
now I want to store the binary value of that '0' so I can blink the 1s and 0s with LED to the another receiver EPS32
Oh nice this looks good ! Thank you !
But how do I store bits on the other site ? There I probably need that array to store bits one by one and then how do I transfer them to a char ?
Okay I will need to look up something more about those bitWrite,Read functions never used them before.
And I want to always send a 8bit long data. The LED is always on until I hit the "SEND" button, then it will change the status to LOW and the other one will indicate the change and will begin receiving function. I will send 1 bit every 100ms and the other one will read every 100ms but in the middle so reading will be shifted by 50ms
here is little scheme, if you have any better ideas fill me in !
Yes I was thinking about UART too but I have 0 experience with it. If you can help me out with that or you have any good explanation video hit me with it !
And I am using a photoresistor to receive data because I also have to me measure a strength of the signal and I don't know if I can use that with UART, any suggestions ?
Very strange asking about how to connect two devices together with either optical fibre or wire when they are specifically designed to communicate by radio.
Just a few meters, I have different types of length (1, 2, 5 meters) and it has to represent for children how digital data are transferred with optical cable.
Your full requirements are gradually emerging. If only you had given us the full picture at the start. Is there anything else that you want to tell us ?
Be able to set the brightness and color of the RGB LED, and monitor the signal strength (brightness) on the other one modul - this is working with RGB LED diode and photo resistor.
Now I need to use this set color of the signal to transfer simple data from the 3x4 keyboard (numbers from 0-9) and display them on LCD - it has to represent how data are transferred via optical cable and if the bend it or damage in some way (loss of a signal strength) it corrupts the data it sending, in the future I would like to upgrade it so you could send a full message with a serial monitor on PC, but for now I just need to transfer simple char numbers from keyboard
And I was thinking to use UART, it will be faster and better, but idk how I would do it with the photoresistor I am using and I have never done anything with UART
Or develop my "own" data transfer protocol that will always send 8 bits of data and I will be able to set my own detection value for 1s and 0s and the speed of transfer so the kids can see it how it is transferring data and will have time to disturb it.
So I am open to any ideas, I never done a transfer of data between 2 Arduinos so no skill with UART but I know it is a useful thing that would solve my problem, but idk how and if it will make my requirements.
Again big thanks to you guys for trying to help me, sorry for not specifying my problem correctly this is my first post on any forum.