Jul-25-2022, 07:51 AM
(Jul-25-2022, 06:00 AM)deanhystad Wrote: What does struct.unpack() return? Have you read the documentation for the struct library? The answer is there.
Got it! Thank you. I changed the "I" to "H" which is for unsigned short (2 bytes) and I was able to receive the values combining every 2 bytes. But I got stuck into this tricky part where I only want to write every other value in the file. For example, write value[0], ignore value[1], write value[2], and so on...To work on this, I made the following change, but now the data is not being written into the file at all...any hints?
def spi_process(gpio,level,tick): data = bytes([0]*2048) spi.xfer2([0x02]) for x in range(1): recv = spi.xfer2(data) values = struct.unpack(">" +"H"*1024, bytes(recv)) f.write("\n") num=1 while num in range(0,2047): if num%2==0: f.write("\n") f.write(str(x))