thanks in advance for any help on this.
I am writing some code to send data from a Mac to an Arduino board so that I can program a flash memory device. I have a Python program which negotiates a link to the arduino board and then should send 256 byte chunks of data read from a file to the arduino. Code running on the Arduino programs the memory device in 256 byte pages using an SPI link. Here's the Python code:
import serial, time, sys
try:
dataFile = open(sys.argv[1], "rb")
except IOError:
sys.exit("file cannot be opened")
arduino = serial.Serial('/dev/cu.usbmodem2101', 19200, timeout=1)
time.sleep(1) # give the connection a second to settle
arduino.write(("WAKEUP").encode('ascii'))
if( arduino.readline() != ("ACK").encode('ascii') ):
sys.exit("no initial ACK from programmer")
print("received initial ACK")
for block in range(1, 131073): # 256Mb is 131072 x 256B blocks
blockData = dataFile.read(256)
checksum = 256 - (sum(blockData) % 256) # checksum when added to summed data should result in 0
arduino.write(blockData) # send the data
arduino.write(checksum) # send the checksum
if( arduino.readline() != ("ACK").encode('ascii') ): # wait for the block to be processed
sys.exit("Failed to complete data transfer")
print("Block = " + str(block) + " sent succesfully" )
arduino.close()
dataFile.close()
Instead of sending the data the program just sends 0x00 over and over. If I modify the code to read a single byte of data from the file at a time and send the data one byte at a time it works fine. Please can anyone advise me what I'm doing wrong with the code shown above?