I'm pretty new to Python and am trying to do something a bit tricky. So essentially I'm trying to send data over light; just a small amount of text. So I have a line of code to encode the ASCII to binary, and that works fine and leaves me with a list with the binary as strings like
n=['0','b','1','0','1']
and so on. I have one raspberry pi
set up to send with the code below, and one to receive with the code further down. It all seems to work but I think the timing is off between the two and the list at the received end is shifted and sometimes has random 0's where there shouldn't be. (I think it's reading faster than sending). Is there any way to fix this that you can easily see? The for loops both start at the same time via pushbutton.
Sending:
For x in range(2,130):
If myList[x] != '1':
Led.off()
Sleep(.5)
Led.off()
Elif myList == '1':
Led.on()
Sleep(.5)
Led.off()
Receiving:
For x in range(2,130):
If gpio.input(14) == True:
myList[x] = '1'
Sleep(.5)
Elif gpio.input(14) ==False:
myList[x] = '0'
Sleep(.5)
The gpio.input(14)
is connected to a photodiode
that is receiving the signals from an led. I'm assuming the code for receiving runs faster than the sending code and why timing is off but I don't know how to fix it.