How can I put an asset file in a tab

I am a (very) white haired almost newby. I have a rather long sketch that sends information, instructions and advice to an Android device via bluetooth classic that acts as a more or less dumb display. This all works perfectly. At the moment the instructions etc. that are sent are held in PROGMEM to preserve space but I would like to remove this 'stuff' to a separate asset file in a separate tab to make adding/changing this stuff easier. I am not sure how to do this. I attach a sketch that shows what I have done to try and do this. Not surprisingly all that is returned is the first character in the relevant array entry. I am not sure how to declare the size of the array in the asset tab as well as declaring that the array entry will be an integer value. Can somebody give me a reference to help how to do all this. Should the asset file be a .c or .h or .ino? Many thanks.
Here are some print outs - I understand that both the main sketch and asset array are regarded as .ino files by the IDE.

(main sketch named: function_d)
const PROGMEM prog_char array1 [14] [10] {
  {"q1y"}, {"q2yy"}, {"w3yyy"}, {"e4yyyy"}, {"r5yyyyy"}, {"t1y"}, {"z2yy"}, {"u3yyy"}, {"i4yyyy"}, {"o5yyyyy"}, {"p1y"}, {"a2yy"}, {"s3yyy"},
};
char arrayBuffer1[20];
void setup() {
  int n;
  Serial.begin(115200);
  // using PROGMEM
  Serial.println("trial with PROGMEM");
  for (n = 0; n < 10; n++) {
    memcpy_P (&arrayBuffer1, &array1 [n], sizeof arrayBuffer1);
    Serial.println(arrayBuffer1);
  }
  // trying to use external asset tab
  Serial.println("trial with external asset tab");
  for (n = 0; n < 10; n++) {
    Serial.println(asset2(n));
  }
}

void loop() {
}
(Asset array in next tab named: assetArray)
char asset2(int x) {
  char array2 [14] [10] = {
    {"q1y"}, {"q2yy"}, {"w3yyy"}, {"e4yyyy"}, {"r5yyyyy"}, {"t1y"}, {"z2yy"}, {"u3yyy"}, {"i4yyyy"}, {"o5yyyyy"}, {"p1y"}, {"a2yy"}, {"s3yyy"},
  };
  Serial.print(array2 [x]); // check have we read the right stuff?
  Serial.print(", ");
  return *array2 [x];
}

(print out)
trial with PROGMEM
q1y
q2yy
w3yyy
e4yyyy
r5yyyyy
t1y
z2yy
u3yyy
i4yyyy
o5yyyyy
trial with external asset tab
q1y, q
q2yy, q
w3yyy, w
e4yyyy, e
r5yyyyy, r
t1y, t
z2yy, z
u3yyy, u
i4yyyy, i
o5yyyyy, o

If you put an .ino file into a tab it will simply be compiled into the sketch. If you put a .h file into a tab then you need to #include it into your sketch

Why not simply try it ?

Thanks for your quick reply, Bob. I tried as you suggested (indeed I tried before submitting my question) and I get the same result. If I take out the dereference function (*) then I get an advice 'address of local variable 'array2' returned' and no printout of the returned function (as expected).
The real problem for me is how to get more than one character returned - ie how to define that the sent array from the tab and the received array to the main sketch should be many characters long and not just the one character found by the pointer.

Do you want the "asset array" (odd term, never heard it before) that's in the separate file to also be PROGMEM? If so, why does your trial have it in RAM?

I don't understand that at all. Your arrays contain character strings not integers.

Hi gfvalvo. Thanks for the reply. I'll try and answer as best I can.
First: It would be good to have the asset information in PROGMEM as before to save space. But at the moment I would just like to try to understand how to get the info from the tab to the sketch. Tricky stuff like putting it in PROGMEM would only confuse me at the moment (I am a bear of very little brain!) One step at a time. However if you think it would work better to go directly to PROGMEM thwn any help would be appreciated.
Second: I need to pick a character string from the array to pass across to the main sketch. This array element is defined by its 'address' in the array. It is this address that is the integer, not the elements of the array itself. Therein lies (I think) the problem - how to declare the array as multiple dimension and the 'address' of the element that I need. It is all a bit confusing for me too.
Incidentally I called it an 'asset array' analog to the asset files in MIT AI2.

Something like this:

main.ino file:

#include "asset.h"

void setup() {
  char charBuffer[20];
  Serial.begin(115200);
  delay(1000);

  for (size_t i = 0; i < numAssets; i++) {
    strcpy_P(charBuffer, array1[i]);
    Serial.println(charBuffer);
  }
}

void loop() {
}

asset.h:

#ifndef ASSET_H
#define ASSET_H

#include <Arduino.h>
#define ASSET_LENGTH 10

extern const char array1[][ASSET_LENGTH];
extern const size_t numAssets;

#endif

asset.cpp:

#include "asset.h"

const PROGMEM char array1[][ASSET_LENGTH] {
  {"q1y"}, {"q2yy"}, {"w3yyy"}, {"e4yyyy"},
  {"r5yyyyy"}, {"t1y"}, {"z2yy"}, {"u3yyy"},
  {"i4yyyy"}, {"o5yyyyy"}, {"p1y"}, {"a2yy"}, {"s3yyy"}
};

const size_t numAssets = sizeof(array1) / sizeof(array1[0]);

Thanks gfvalvo. I am a bit tied up for the moment but will give your solution a try and attempt to understand what it all means when I get a cahnce.
Thanks again.

Hi gfvalvo. Thanks, that works perfectly, brilliant - I just have to try and figure out what is going on.
All the best and thanks again for your time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.