I'm trying to modify Ben Eater's eeprom programmer to flash a 32K eeprom, since the arduino has 32K of program data total the data wouldn't fit in the program. So I wrote a python program using pySerial to send the data in chunks of 256 bytes over serial. The arduino program works correctly when I manually send the data over the serial monitor, and the python program works correctly when I print the values to a console as a test, but when I actually run the program over serial it seems to only write zeros to the eeprom. Additionally, the Rx led on the arduino seems to be lighting up with the correct data, but like I said only zeros are written.
Here's the relevant arduino code:
void setup() {
pinMode(SHIFT_DATA, OUTPUT);
pinMode(SHIFT_CLK, OUTPUT);
pinMode(SHIFT_LATCH, OUTPUT);
digitalWrite(WRITE_EN, HIGH);
pinMode(WRITE_EN, OUTPUT);
Serial.begin(57600);
dataArrPage = 0;
//delay(1000);
//Serial.println("Reading EEPROM");
//printContents();
}
void loop() {
if (Serial.available() > 0) {
int len = Serial.readBytes(dataArr, 256);
for (int i = 0; i < 256; i++) {
writeEEPROM(dataArrPage + i, dataArr[i]); // writeEEPROM(address, data)
}
dataArrPage += 0x100;
Serial.write('s'); //success, writing is done
}
}
And the relevant python code:
import time
import serial
ser = serial.Serial('/dev/ttyUSB0', 57600)
time.sleep(4) # wait for arduino to initialize
filename = input("Enter file name: ")
f = open(filename, "rb")
data = f.read()
page = 0
for x in range(128): # 128 pages in 32K eeprom
for i in range(256):
#print(hex(data[(page * 256) + i])) # printing prints the correct values
ser.write(data[(page * 256) + i])
page += 1
#wait until receive 's' from arduino
while True:
if ser.in_waiting > 0:
suc = ser.read(size=1)
if suc == b's':
print("Success")
break
print("Writing done")
f.close()
ser.close()
I'm a beginner so sorry if it's something obvious.