Hi everyone,
Please help with the code. It is necessary to output data from the matrix synchronously with the fronts of incoming pulses. Previously, the code for outputting matrix data through memory PSRAM on Teensy 4.1 was implemented. But the memory is limited to 8+8 = 16 Mbytes. But now I need more. Therefore, I will try to use a soldered flash memory chip W25N01GVZEIG. It is necessary to read the matrix (where the data is stored in bytes to reduce the memory size by 8 times) directly from the flash. These matrices represent only "0" and "1". I have written the code and am doing the check on a small size 2x2 matrix. Filled the matrix file with data in bytes 254 128 and the second line 0 127. Got the result;
"LittleFS Matrix Read Test
Volume size: 125 MByte
File opened successfully. Reading and sending data...
0011001000110101 0011010000100000 0011000100110010 0011100000001101 0000101000110000 0010000000110001 0011001000110111 0000110100001010
Data has been sent successfully."
And it should be:
11111110 10000000 00000000 01111111
What is the problem. Below is my code
Thanks in advance for your community support.
#include <LittleFS.h>
LittleFS_QSPIFlash myfs; // NOR FLASH
LittleFS_QPINAND myfs_NAND; // NAND FLASH 1Gb
const int rows = 2; // 2000
const long cols = 2; // 72000
bool dataSent = false;
void setup() {
pinMode(5, INPUT);
pinMode(8, INPUT);
pinMode(2, OUTPUT);
Serial.begin(9600);
while (!Serial); // wait for Arduino Serial Monitor
Serial.println("LittleFS Matrix Read Test");
if (!myfs_NAND.begin()) {
Serial.println("Error initializing NAND FLASH");
while (1); //
}
Serial.printf("Volume size: %d MByte\n", myfs_NAND.totalSize() / 1048576);
}
void loop() {
if (!dataSent) {
readAndSendData();
dataSent = true;
}
}
void readAndSendData() {
File file = myfs_NAND.open("/mbyte2-2.txt", FILE_READ);
if (!file) {
Serial.println("Error: could not open mbyte2-2.txt");
return;
}
Serial.println("File opened successfully. Reading and sending data...");
while (file.available()) {
if(digitalRead(8)) {
while(digitalRead(8) == 1);
}
while(digitalRead(8) == 0);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
int byteValue = file.read(); // Reading one byte
for (int bitPos = 7; bitPos >= 0; bitPos--) {
int bitValue = (byteValue >> bitPos) & 0x01; // Getting a bit
if(digitalRead(5)) {
while(digitalRead(5) == 1);
}
// The pin is now LOW, wait for it to go HIGH
while(digitalRead(5) == 0);
// Sending a bit through a port
Serial.print(bitValue); // Sending to Serial for Debugging
digitalWrite(2, bitValue);
}
}
Serial.print(" "); // Separator between lines for clarity
// }
break; // End the loop once the data has been sent once
}
}
file.close();
Serial.println("\nData has been sent successfully.");
}
Please help with the code. It is necessary to output data from the matrix synchronously with the fronts of incoming pulses. Previously, the code for outputting matrix data through memory PSRAM on Teensy 4.1 was implemented. But the memory is limited to 8+8 = 16 Mbytes. But now I need more. Therefore, I will try to use a soldered flash memory chip W25N01GVZEIG. It is necessary to read the matrix (where the data is stored in bytes to reduce the memory size by 8 times) directly from the flash. These matrices represent only "0" and "1". I have written the code and am doing the check on a small size 2x2 matrix. Filled the matrix file with data in bytes 254 128 and the second line 0 127. Got the result;
"LittleFS Matrix Read Test
Volume size: 125 MByte
File opened successfully. Reading and sending data...
0011001000110101 0011010000100000 0011000100110010 0011100000001101 0000101000110000 0010000000110001 0011001000110111 0000110100001010
Data has been sent successfully."
And it should be:
11111110 10000000 00000000 01111111
What is the problem. Below is my code
Thanks in advance for your community support.
#include <LittleFS.h>
LittleFS_QSPIFlash myfs; // NOR FLASH
LittleFS_QPINAND myfs_NAND; // NAND FLASH 1Gb
const int rows = 2; // 2000
const long cols = 2; // 72000
bool dataSent = false;
void setup() {
pinMode(5, INPUT);
pinMode(8, INPUT);
pinMode(2, OUTPUT);
Serial.begin(9600);
while (!Serial); // wait for Arduino Serial Monitor
Serial.println("LittleFS Matrix Read Test");
if (!myfs_NAND.begin()) {
Serial.println("Error initializing NAND FLASH");
while (1); //
}
Serial.printf("Volume size: %d MByte\n", myfs_NAND.totalSize() / 1048576);
}
void loop() {
if (!dataSent) {
readAndSendData();
dataSent = true;
}
}
void readAndSendData() {
File file = myfs_NAND.open("/mbyte2-2.txt", FILE_READ);
if (!file) {
Serial.println("Error: could not open mbyte2-2.txt");
return;
}
Serial.println("File opened successfully. Reading and sending data...");
while (file.available()) {
if(digitalRead(8)) {
while(digitalRead(8) == 1);
}
while(digitalRead(8) == 0);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
int byteValue = file.read(); // Reading one byte
for (int bitPos = 7; bitPos >= 0; bitPos--) {
int bitValue = (byteValue >> bitPos) & 0x01; // Getting a bit
if(digitalRead(5)) {
while(digitalRead(5) == 1);
}
// The pin is now LOW, wait for it to go HIGH
while(digitalRead(5) == 0);
// Sending a bit through a port
Serial.print(bitValue); // Sending to Serial for Debugging
digitalWrite(2, bitValue);
}
}
Serial.print(" "); // Separator between lines for clarity
// }
break; // End the loop once the data has been sent once
}
}
file.close();
Serial.println("\nData has been sent successfully.");
}