Geetings, Im trying to read String files to an arduino from a header file (.h). Its compiling fine but i cant call the string. When I serial print the string only gibberish shows up on the monitor. This is my arduino Code:
#include <epd4in2.h>
#include <epdif.h>
#include <epdpaint.h>
#include <fonts.h>
#include <SPI.h>
#include "epd4in2.h"
#include "imagedata.h"
#include "epdpaint.h"
#include "list.h"
#define COLORED 0
#define UNCOLORED 1
String test1;
String test2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.print("port test");
Epd epd;
if (epd.Init() != 0) {
Serial.println("e-Paper init failed");
return;
}
test1 = String(DATA_1[0]);\
Serial.println(test1);
test2 = String(DATA_1[1]);
Serial.println(test2);
/* This clears the SRAM of the e-paper display */
epd.ClearFrame();
/* Due to RAM not enough in Arduino UNO, a frame buffer is not allowed. */
unsigned char image[1500];
Paint paint(image, 400, 28); //width should be the multiple of 8
paint.Clear(UNCOLORED);
paint.DrawStringAt(0, 0, "test1", &Font24, COLORED);
epd.SetPartialWindow(paint.GetImage(), 100, 40, paint.GetWidth(),
paint.GetHeight());
paint.Clear(COLORED);
paint.DrawStringAt(100, 2, "test2", &Font24, UNCOLORED);
epd.SetPartialWindow(paint.GetImage(), 0, 64, paint.GetWidth(),
paint.GetHeight());
/* This displays the data from the SRAM in e-Paper module */
epd.DisplayFrame();
/* Deep sleep */
epd.Sleep();
}
void loop() {
// put your main code here, to run repeatedly:
}
and here the data in the .h file:
extern const String DATA_1[] PROGMEM = { "bat", "2244"};
extern const String DATA_2[] PROGMEM = { "bmp", "15662"};
extern const String DATA_3[] PROGMEM = { "docx", "16670"};
extern const String DATA_4[] PROGMEM = { "jpg", "150645"};
extern const String DATA_5[] PROGMEM = { "mp3", "9882324"};
extern const String DATA_6[] PROGMEM = { "txt", "807"};
extern const String DATA_7[] PROGMEM = { "url", "118"};
I created this list using a .bat script.
Im pretty new to this so any help would be appreciated. Kind Regards Luigi
When you use PROGMEM, the initialised value is stored in the program memory, and a pointer to the location is given to the variable.
But when you use
test1 = String(DATA_1[0]);
the code searches with the same address in the ram and not the program memory.
You can read about it here. https://www.nongnu.org/avr-libc/user-manual/pgmspace.html
I have faced the same problem before, but I was storing bytes, not strings. So I was able to get away with using pgm_read_byte. You may have to put in some effort to make the program work.
I hope this helps and Good luck.