I'm trying send 64 bit from one raspberry to another, using gpio. My problem is synchronize to raspberry, so I can receive correct data.

TX program is:

Code: Select all

```
import RPi.GPIO as GP
import numpy as np
import bitstring as bs
GP.setmode(GP.BCM)
GP.setup(17,GP.OUT)
SIGIFS=np.array([0.0000,0.79308,0.05000,3.4908,0.10000,7.6360,.......900,25.976,86.950,25.933,87.000,25.889,87.050,25.848,87.100,25.813,87.150]);
SIGIF=SIGIFS[1::2]#take only odds values from SIGIFS
lung_SIGIF=len(SIGIF)#length of SIGIF
lung_SIGIFS=len(SIGIFS)#length of SIGIFS
length_stop=bs.Bits(int=9999,length=64);#convert 9999 to binary with length 64 bit to stop TX
length_start=bs.Bits(int=1000, length=64);#convert 1000 to binary with length 64 bit to stop RX
Y=np.zeros(64);#I create an array of 64 positions to insert the bits that make up the val value in binary of the i-th value of SIGIF
arrive_SIGIF=np.zeros(lung_SIGIF);#I create an array of the length necessary to contain the starting array
start=np.zeros(64);#I create an array of the length necessary to contain the start int 1000
#send array to start rx
for i in range(0,64):
GP.output(17,length_start[i])
for i in range(0,lung_SIGIF):
val=SIGIF[i];#take 'i' value of SIGIF
binary=bs.Bits(float=val,length=64);#convert val to bin
for x in range(0,64):
GP.output(17,int(binary.bin[x]));#write bit on port number 17
#send array to stop tx
for i in range(0,64):
GP.output(17,length_stop[i])
GP.cleanup();
```

and the RX code is:

Code: Select all

```
import RPi.GPIO as GP
import numpy as np
import bitstring as bs
GP.setmode(GP.BCM)
GP.setup(27,GP.IN)
SIGIFS=np.array([0.0000,0.79308,0.05000,3.4908,0.10000,7.6360,.......900,25.976,86.950,25.933,87.000,25.889,87.050,25.848,87.100,25.813,87.150]);
SIGIF=SIGIFS[1::2]#take only odds values from SIGIFS
lung_SIGIF=len(SIGIF)#length of SIGIF
lung_SIGIFS=len(SIGIFS)#length of SIGIFS
length_stop=bs.Bits(int=9999,length=64);#convert 9999 to binary with length 64 bit to stop TX
length_start=bs.Bits(int=1000, length=64);#convert 1000 to binary with length 64 bit to stop RX
Y=np.zeros(64);#I create an array of 64 positions to insert the bits that make up the val value in binary of the i-th value of SIGIF
arrive_SIGIF=np.zeros(lung_SIGIF);#I create an array of the length necessary to contain the starting array
start=np.zeros(64);#I create an array of the length necessary to contain the start int 1000
#read array to start rx
while 1:
for x in range(0,64):
start[x]=GP.input(22);
str1 = ''.join(str(e) for e in start.astype(int))#I transform the array created in string str1
aa=bs.Bits(bin=str1);#I recreate the starting binary number
g=aa.int
if str1==g:
break;
while 1:
for i in range(0,lung_SIGIF):
for x in range(0,64):
k=GP.input(22);#I read the received bit
Y[x]=int(k);#I insert the received bit inside the position
str2 = ''.join(str(e) for e in Y.astype(int))#I transform the array created in string str1
aa=bs.Bits(bin=str2);#I recreate the starting binary number
g2=aa.float;#I convert the binary number received in float
arrive[i]=g2;#insert the value val sent in the same position of the starting array SIGIF
#stop to receive
if int(g)==9999:
break;
```

Thank you

Steve