Hi
I’m hoping someone can help me, I have just started working with flash memory using the SPImemory library so I do apologize if this is something that is easy. I have a string of data 255,255,255 which represents a LED, I have 300 LED’s so I have 255,255,255 x 300, I want to store each string (each 255,255,255) inside the flash memory.
I had tried to store all of it into a string variable however that wastes a lot of space and doesn’t work so my idea was to store each led variable into a different memory address. Example address 0 = 255,255,255, address 1 = 255,255,255, address 3 = 255,255,255 etc, I believe this is the best way.
So I have a issues when it comes to storing all the data using a for loop as it doesn’t seem to work
#include <Tlc5940.h>
#include <SPIMemory.h>
SPIFlash flash;
#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)
// Required for Serial on Zero based boards
#define Serial SERIAL_PORT_USBVIRTUAL
#endif
#if defined (SIMBLEE)
#define BAUD_RATE 250000
#define RANDPIN 1
#else
#define BAUD_RATE 115200
#if defined(ARCH_STM32)
#define RANDPIN PA0
#else
#define RANDPIN A0
#endif
#endif
String inputString;
//String inputString2;
String outputString;
String readString;
//uint32_t strAddr[3];
void setup() {
// put your setup code here, to run once:
Serial.begin(BAUD_RATE);
#if defined (ARDUINO_ARCH_SAMD) || (__AVR_ATmega32U4__) || defined(ARCH_STM32) || defined(NRF5)
while (!Serial) ; // Wait for Serial monitor to open
#endif
delay(50); //Time to terminal get connected
//Serial.print(F("Initialising"));
for (uint8_t i = 0; i < 10; ++i)
{
Serial.print(F("."));
}
Serial.println();
randomSeed(analogRead(RANDPIN));
flash.begin();
Serial.println("Start");
}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available() > 0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(5); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
if(readString == "Delete"){
Delete();
}
if(readString == "Upload"){
Upload();
}
if(readString == "Read"){
Read();
}
}
readString="";
}
void Delete() {
Serial.println("Deleting.....");
if (flash.eraseChip()){
Serial.println(F("Chip erased"));
}
else {
Serial.println(F("Error erasing chip"));
}
}
void Upload() {
Serial.println("Uploading.....");
inputString = "255,255,255";
for (uint8_t i = 0; i < 300; i++) {
if (flash.writeStr(i, inputString)) {
Serial.println("Writing Success");
}
else {
Serial.println("Write Failed");
}
}
Serial.println("Upload Finished");
}
void Read() {
for (uint8_t i = 0; i < 300; i++) {
flash.readStr(i, outputString);
Serial.println(outputString);
}
Serial.println("Read Finished");
}
As you can see from my above code which im using for testing, the upload functions starts a for loop using the int i as the memory address to put the string variable into, however it doesn’t seem to work the way I imagined, this is where I need help
I also have the function to read those address back, which means I need to know which address I wrote to hence another for loop using int i as the address point to read from.
I hope this is understandable and any help would be great
Thank you