PROGMEM data gets corrupted

Hi Everybody
To save SRAM i try to store constant data in the flash memory using PROGMEM.
Running the following sketch on my arduino mega the data set at position 47 shows random bytes when reading back. In my big project context the same happens, but on a different data set.
Any help or workarround is aprecciated
Best regads

// PROGMEM gets corrupted at dataset 47 
// With Arduino IDE 1.8.7./Arduino Mega/Programmer AVRISP mkII 

enum pinType {w,r,g,p1,p2,p3,p4,p5,donotcare}; 
const int N_edges = 89;
const int N_nodes = 74;

struct Element_Data{ 
 const char* Name;
 byte Sch_neighbor1; 
 pinType pin_neighbor1; 
 byte Sch_neighbor2; 
 pinType pin_neighbor2;
 byte Sch_neighbor3;  
 pinType pin_neighbor3;
 byte Sch_neighbor4; 
 pinType pin_neighbor4;
 byte Sch_neighbor5; 
 pinType pin_neighbor5;
 };

void PrintPinType(pinType startpin) {

switch (startpin) {
        case w:
        Serial.print("w");
        break;

        case r:
        Serial.print("r");
        break;

        case g:
        Serial.print("g");
        break;

        case p1:
        Serial.print("p1");
        break;

        case p2:
        Serial.print("p2");
        break;

        case p3:
        Serial.print("p3");
        break;

        case p4:
        Serial.print("p4");
        break;

        case p5:
        Serial.print("p4");
        break;

        case donotcare:
        Serial.print("donotcare");
        break;
      }
}


//topology in flash, size 17 x 164 = 2788 Bytes
const static Element_Data topology[N_edges+N_nodes+1] PROGMEM ={
{"noElem",0,donotcare,0,donotcare,0,donotcare}, 
{"A:A2",  53, p2, 10, w}, //1      
{"A:A4",  7, g, 10,  r},       
{"A:A5",  7, r, 11,  r},       
{"A:A6",  8, r, 12,  r},       
{"A:A7",  9, r, 12,  g},  //5     
{"A:A9",  45,  w, 9, w},       
{"A:Wk1", 8, g, 3, p1,  2, p1},    
{"A:Wk2", 9, g, 4, p1,  7, w},   
{"A:Wk3", 6, p2,  5, p1,  8, w},   
{"A:Wu4", 1, p2,  2, p2,  11,  w}, //10   
{"A:Wu5", 10,  g, 3, p2,  12,  w},   
{"A:Wu6", 11,  g, 4, p2,  5, p2},    
{"B:A2",  155, w, 22,  w},       
{"B:A4",  19,  g, 22,  r},       
{"B:A5",  19,  r, 23,  r}, //15      
{"B:A6",  20,  r, 24,  r},       
{"B:A7",  21,  r, 24,  g},       
{"B:A9",  148, w, 21,  w},       
{"B:Wk1", 20,  g, 15,  p1,  14,  p1},    
{"B:Wk2", 21,  g, 16,  p1,  19,  w}, //20   
{"B:Wk3", 18,  p2,  17,  p1,  20,  w},   
{"B:Wu4", 13,  p2,  14,  p2,  23,  w},   
{"B:Wu5", 22,  g, 15,  p2,  24,  w},   
{"B:Wu6", 23,  g, 16,  p2,  17,  p2},    
{"C:A1",  36,  w, 120, w},       
{"C:A2",  36,  r, 37,  w},       
{"C:A4",  32,  g, 37,  r},       
{"C:A5",  32,  r, 38,  r},       
{"C:A6",  33,  r, 39,  r},       
{"C:A7",  34,  r, 40,  r},       //30
{"C:A8",  35,  r, 40,  g},       
{"C:Wk1", 33,  g, 28,  p1,  27,  p1},    
{"C:Wk2", 34,  g, 29,  p1,  32,  w},   
{"C:Wk3", 35,  g, 30,  p1,  33,  w},   
{"C:Wk4", 36,  g, 31,  p1,  34,  w},   
{"C:Wk5", 25,  p1,  26,  p1,  35,  w},  
{"C:Wu6", 26,  p2,  27,  p2,  38,  w},   
{"C:Wu7", 37,  g, 28,  p2,  39,  w},   
{"C:Wu8", 38,  g, 29,  p2,  40,  w},   
{"C:Wu9", 39,  g, 30,  p2,  31,  p2}, //40   
{"1:A1",  46,  r, 47,  r},       
{"2:A3",  43,  p2,  47,  g},       
{"2:A2",  46,  g, 42,  p1},        
{"3:A2",  152, w, 55,  w},         
{"W21", 6, p1,  53,  p1,  46,  w},   
{"W22", 45,  g, 41,  p1,  43,  p1},    
{"Wk2",3,  48,  g, 41,  p2,  42,  p2},    
{"Wk24",  50,  p1,  54,  p3,  47,  w},   
{"W25", 50,  p2,  55,  g, 163, p2},    
{"Svd22", 48,  w, 49,  w},       //50
{"3:A2",  53,  p4,  52,  p1},        
{"3:A4",  51,  p2,  54,  p2},        
{"Wu31",  45,  r, 1, p1,  67,  p1,  51,  p1},
{"Wu32",  70,  p3,  52,  p2,  48,  r, 55,  r},
{"W33", 44,  p2,  54,  p4,  49,  r},   
{"4:A1",  0, donotcare,  57,  p1},        
{"4:A2",  56,  p2,  67,  p2},        
{"4:A4",  67,  p4,  59,  p1},        
{"4:A5",  58,  p2,  60,  p1},        
{"4:A6",  59,  p2,  68,  w},       //60
{"4:A8",  73,  g, 0, donotcare},        
{"451", 75,  r, 71,  r},       
{"461", 74,  r, 72,  r},       
{"471", 74,  g, 73,  r},       
{"44",  70,  p4,  71,  w},       
{"49",  116, p2,  75,  w},       
{"Wu41",  53,  p3,  57,  p2,  86,  p1,  58,  p1},
{"W42", 60,  p2,  69,  p2,  70,  p2},    
{"Wk43",  87,  p3,  68,  r, 70,  p1,  88,  p1},
{"Wu44",  69,  p3,  68,  g, 54,  p1,  65,  p1}, //70
{"W45", 65,  p2,  62,  p2,  72,  w},   
{"W46", 71,  g, 63,  p2,  73,  w},   
{"W47", 72,  g, 64,  p2,  61,  p1},    
{"W48", 75,  g, 63,  p1,  64,  p1},    
{"W49", 66,  p2,  62,  p1,  74,  w},   
{"5:A1",  0, donotcare,  86,  p2},        
{"5:A2",  86,  p4,  78,  p1},        
{"5:A3",  77,  p2,  79,  p1},        
{"5:A4",  78,  p2,  87,  p2},        
{"5", 88,  p4,  89,  w},       //80
{"53",  82,  p2,  88,  p3},        
{"531", 120, g, 81,  p1},        
{"5:A7",  119, p2,  90,  g},       
{"5:A8",  118, p2,  90,  r},       
{"5:A9",  117, p2,  89,  r},       
{"Wu51",  67,  p3,  76,  p2,  93,  r, 77,  p1},
{"Wu52",  95,  p2,  79,  p2,  69,  p1,  88,  p2},
{"Wu53",  69,  p4,  87,  p4,  81,  p2,  80,  p1},
{"W54", 80,  p2,  85,  p2,  90,  w},   
{"W55", 89,  g, 84,  p2,  83,  p2}, //90   
{"6", 93,  w, 94,  g},       
{"6:A1",  0, donotcare,  93,  g},       
{"61",  91,  p1,  86,  p3,  92,  p2},    
{"62",  95,  p1,  96,  p2,  91,  p2},    
{"67",  94,  w, 87,  p1},        
{"7", 0, donotcare,  94,  r},       
{"100", 0, donotcare,  110, w},       
{"102", 109, r, 0, donotcare},        
{"110", 0, donotcare,  111, g},       
{"111", 0, donotcare,  111, r},       //100
{"112", 112, w, 124, p1},        
{"10:A1", 108, r, 103, p1},        
{"10:A2", 102, p2,  107, p3},        
{"10:A3", 110, g, 105, p1},        
{"10:A4", 104, p2,  107, p4},        
{"10:A5", 107, p5,  0, donotcare},        
{"103", 103, p2,  105, p2,  106, p1},    
{"W101",  109, g, 102, p1,  112, r},   
{"W102",  110, r, 98,  p1,  108, w},   
{"W103",  97,  p2,  109, w, 104, p1}, //110   
{"W111",  112, g, 100, p2,  99,  p2},    
{"W112",  101, p1,  108, g, 111, w},   
{"12:A1", 122, w, 114, p1},        
{"12:A2", 113, p2,  115, p1},        
{"12:A3", 114, p2,  123, w},       
{"12:A7", 125, g, 66,  p1},        
{"12:A8", 126, r, 85,  p1},        
{"12:A9", 127, r, 84,  p1},        
{"12:A10",  127, g, 83,  p1},        
{"W121",  25,  p2,  122, r, 82,  p1},    //120
{"W122",  137, p2,  122, g, 144, p1},    
{"W123",  113, p1,  120, r, 121, r},   
{"W124",  115, p2,  145, p3,  124, p2},    
{"Wu125", 101, p2,  123, g, 146, r, 125, w},
{"W126",  124, p4,  126, w, 116, p1},    
{"W127",  125, r, 117, p1,  127, w},   
{"W128",  126, g, 118, p1,  119, p1},    
{"140", 144, p4,  134, p1},        
{"141", 0, donotcare,  140, r},       
{"142", 0, donotcare,  140, g},       //130
{"143", 0, donotcare,  141, r},       
{"144", 0, donotcare,  143, r},       
{"145", 0, donotcare,  143, g},       
{"146", 128, p2,  145, p2},        
{"148", 147, w, 138, p1},        
{"14:A1", 0, donotcare,  137, p1},        
{"14:A2", 136, p2,  121, w},       
{"14:A3", 135, p2,  139, p1},        
{"14:A4", 138, p2,  0, donotcare},        
{"W141",  141, g, 129, p2,  130, p2}, //140   
{"W142",  142, g, 131, p2,  140, w},   
{"W143",  144, p2,  143, w, 141, w},   
{"W144",  142, r, 132, p2,  133, p2},    
{"Wu145", 121, g, 142, w, 149, p3,  128, p1},
{"Wk146", 150, r, 134, p2, 123, r ,146, g},
{"W147",  147, r, 124, p3,  145, p4},    
{"W148",  135, p1,  146, w, 151, p3},    
{"W151",  18,  p1,  156, p2,  149, p2},    
{"Wk152", 157, r, 148, g, 144, p3,  153, p1},
{"W153",  151, p2,  145, p1,  154, p2},    //150
{"Wu154", 159, p2,  150, w, 147, g, 152, r}, 
{"W155",  44,  p1,  151, p4,  161, p2},    
{"15:A1", 149, p4,  154, p1},        
{"15:A2", 153, p2,  150, g},       
{"Wk161", 13,  p1,  162, p1,  156, p1},    
{"Wk162", 155, g, 148, r, 157, g, 160, p1},
{"W163",  158, p1,  149, p1,  156, p3},    
{"16:A1", 157, w, 159, p1},        
{"16",  158, p2,  151, p1},        
{"17:A1", 156, p4,  161, p1},        //160
{"Svd172",  160, p2,  152, g},       
{"18:A1", 155, r, 163, p1},        
{"18:A2", 162, p2,  49,  g},        //163
};

const char* GetName(byte schluessel){
  return pgm_read_word(&topology[schluessel].Name);
}


void setup() {
  Serial.begin(9600);

pinType aa;

// print topology
for (byte i = 0; i < N_edges+N_nodes+1; i++) {
Serial.print(i);Serial.print(" ");Serial.print( GetName(i));Serial.print(" ");
Serial.print( pgm_read_byte(&topology[i].Sch_neighbor1 ));Serial.print(" ");
aa = pgm_read_word(&topology[i].pin_neighbor1 );
PrintPinType(aa);Serial.print(" ");
Serial.print( pgm_read_byte(&topology[i].Sch_neighbor2 ));Serial.print(" ");
aa = pgm_read_word(&topology[i].pin_neighbor2 );
PrintPinType(aa);Serial.print(" ");
Serial.print( pgm_read_byte(&topology[i].Sch_neighbor3 ));Serial.print(" ");
aa = pgm_read_word(&topology[i].pin_neighbor3 );
PrintPinType(aa);Serial.print(" ");
Serial.print( pgm_read_byte(&topology[i].Sch_neighbor4 ));Serial.print(" ");
aa = pgm_read_word(&topology[i].pin_neighbor4 );
PrintPinType(aa);Serial.print(" ");
Serial.print( pgm_read_byte(&topology[i].Sch_neighbor5 ));Serial.print(" ");
aa = pgm_read_word(&topology[i].pin_neighbor5 );
PrintPinType(aa);Serial.println(" ");
}
  
}

void loop() {}

This probably results in the pointer, not the content of the string, to be written to PROGMEM. Perhaps try:

char const Name[7];

To retrieve the name, you may want to try replacing the following,

with:

char buf[7];
strcpy_P(buf, reinterpret_cast<char const*>(&topology[i].Name));
Serial.print(buf);

Disclaimer: nothing was tested.

1 Like

Welcome to the forum.

I'm not fixing the bug :grimacing: Can you improve the code ?

Can you upgrade to Arduino IDE 2.0 ?
Please turn on the compiler warnings. Go to "Preferences" and set the compiler warnings to "All". I have also the verbose compiler output enabled.
You may ignore the warnings for "new" and "delete", those are mistakes in the library.

The compiler has trouble with the initializing of your table. Not everything is initialized.
You are supposed to fill each and every item. Can you fix the table ? What happens if you print a item that does not exist ?

You don't have to put helper functions above setup() and loop(). The Arduino pre-processor was confused in the past, but you can put all those functions at the end of the file.

If you make a pointer to text in a struct "const char* Name;" and then put the struct in PROGMEM, then pointer to the text is in PROGMEM and the text itself is still in SRAM :exclamation:
That is why I get this: Sketch uses 5922 bytes (2%) of program storage space. Global variables use 926 bytes (11%) of dynamic memory. (It was reduced from 926 to 236 with all the things in this post).

Your Mega has enough Flash memory, so I suggest: const char Name[16];

Once the text is in PROGMEM, you can use Serial.print(). The Serial.print() detects if the string is in PROGMEM or not. But there are other functions that use a PROGMEM pointer. For example strcpy_P(), that takes text from PROGMEM and put it in a normal buffer.

May I suggest code that is easier to maintain ? I would like to copy the complete struct element into SRAM and then use it.

Is this a bug ?

    case p5:
      Serial.print("p4");
      break;

I think that it is easier to put those in a table, and I would like to assign value 0 to "donotcare".

const char* pinTypeText[] = { "donotcare", "w", "r", "g", "p1", "p2", "p3", "p4", "p5" };

Note that those texts and the array with pointers are all in SRAM.

This takes a lot of time when I read the source code:

for (byte i = 0; i < N_edges+N_nodes+1; i++) {

To check that code I have to calculate "N_edges+N_nodes+1" and see if a byte is enough. It is easier to use just 'int'.

Your table is almost impossible to maintain. I would like to shorten the "donotcare" of the enum to "X" and then align your table in the sketch.

const Element_Data topology[N_edges + N_nodes + 1] PROGMEM = {
  {"noElem" ,   0 ,  X,  0,  X,  0,  X},
  {"A:A2"   ,  53 , p2, 10,  w,  0,  X}, //1
  {"A:A4"   ,   7 ,  g, 10,  r,  0,  X},
  {"A:A5"   ,   7 ,  r, 11,  r,  0,  X},
  {"A:A6"   ,   8 ,  r, 12,  r,  0,  X},
  {"A:A7"   ,   9 ,  r, 12,  g,  0,  X},  //5

A programming language is to create something just once and then do it multiple times.
Is is possible to put the neighbors in an array ?
One way to do that is:

struct Element_Data {
  char Name[16];
  byte Sch_neighbor[5];
  pinType pin_neighbor[5];
};

But then you have to change the table. If you want to keep the table good to read, then you can do this:

struct Element_Pin {
  byte Sch_neighbor;
  pinType pin_neighbor;
};

struct Element_Data {
  char Name[16];
  Element_Pin[5];
};

In that case, your table will be like this:

  { "noElem" , {{0, X}, {0, X}, {0, X}, {0, X}, {0, X}}},

You may rely on the compiler to understand the data, so you may remove some '{' and '}'.

To print an element, I would create a function for that. It would be like this:

enum pinType { X, w, r, g, p1, p2, p3, p4, p5};
const char* pinTypeText[] = { "X", "w", "r", "g", "p1", "p2", "p3", "p4", "p4"};

/* ... table ... */

void setup() {
  Serial.begin(9600);

  // print topology
  for (int i = 0; i < N_edges + N_nodes + 1; i++) {
    ElementPrint( i);
  }
}

void loop() {}

void ElementPrint( int index)
{
  Element_Data myElement;

  // Copy the struct item to sram to make it easier to handle
  memcpy_P( &myElement, &topology[index], sizeof(Element_Data));
 
  Serial.print(index); 
  Serial.print(" : "); 
  Serial.print( myElement.Name);
  Serial.print(" ");
  for( int j=0; j<5; j++)
  {
    Serial.print("{");
    Serial.print( myElement.Pin[j].Sch_neighbor); 
    Serial.print(" ");
    Serial.print( pinTypeText[myElement.Pin[j].pin_neighbor]);
    Serial.print("}, ");
  }
  Serial.println();
}

Here is a test in Wokwi, but I have not fixed the table yet:

[UPDATE]
I used the sketch in Wokwi to print the output in a different way, formatted to what the source code should look like, then I copied the output from the Serial Monitor into the sketch.
Is this your table ?

const Element_Data topology[N_edges + N_nodes + 1] PROGMEM = {
  {"noElem", {{  0,  X}, {  0,  X}, {  0,  X}, {  0,  X}, {  0,  X}}}, //   0
  {"A:A2"  , {{ 53, p2}, { 10,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //   1
  {"A:A4"  , {{  7,  g}, { 10,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //   2
  {"A:A5"  , {{  7,  r}, { 11,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //   3
  {"A:A6"  , {{  8,  r}, { 12,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //   4
  {"A:A7"  , {{  9,  r}, { 12,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, //   5
  {"A:A9"  , {{ 45,  w}, {  9,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //   6
  {"A:Wk1" , {{  8,  g}, {  3, p1}, {  2, p1}, {  0,  X}, {  0,  X}}}, //   7
  {"A:Wk2" , {{  9,  g}, {  4, p1}, {  7,  w}, {  0,  X}, {  0,  X}}}, //   8
  {"A:Wk3" , {{  6, p2}, {  5, p1}, {  8,  w}, {  0,  X}, {  0,  X}}}, //   9
  {"A:Wu4" , {{  1, p2}, {  2, p2}, { 11,  w}, {  0,  X}, {  0,  X}}}, //  10
  {"A:Wu5" , {{ 10,  g}, {  3, p2}, { 12,  w}, {  0,  X}, {  0,  X}}}, //  11
  {"A:Wu6" , {{ 11,  g}, {  4, p2}, {  5, p2}, {  0,  X}, {  0,  X}}}, //  12
  {"B:A2"  , {{155,  w}, { 22,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  13
  {"B:A4"  , {{ 19,  g}, { 22,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  14
  {"B:A5"  , {{ 19,  r}, { 23,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  15
  {"B:A6"  , {{ 20,  r}, { 24,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  16
  {"B:A7"  , {{ 21,  r}, { 24,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  17
  {"B:A9"  , {{148,  w}, { 21,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  18
  {"B:Wk1" , {{ 20,  g}, { 15, p1}, { 14, p1}, {  0,  X}, {  0,  X}}}, //  19
  {"B:Wk2" , {{ 21,  g}, { 16, p1}, { 19,  w}, {  0,  X}, {  0,  X}}}, //  20
  {"B:Wk3" , {{ 18, p2}, { 17, p1}, { 20,  w}, {  0,  X}, {  0,  X}}}, //  21
  {"B:Wu4" , {{ 13, p2}, { 14, p2}, { 23,  w}, {  0,  X}, {  0,  X}}}, //  22
  {"B:Wu5" , {{ 22,  g}, { 15, p2}, { 24,  w}, {  0,  X}, {  0,  X}}}, //  23
  {"B:Wu6" , {{ 23,  g}, { 16, p2}, { 17, p2}, {  0,  X}, {  0,  X}}}, //  24
  {"C:A1"  , {{ 36,  w}, {120,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  25
  {"C:A2"  , {{ 36,  r}, { 37,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  26
  {"C:A4"  , {{ 32,  g}, { 37,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  27
  {"C:A5"  , {{ 32,  r}, { 38,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  28
  {"C:A6"  , {{ 33,  r}, { 39,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  29
  {"C:A7"  , {{ 34,  r}, { 40,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  30
  {"C:A8"  , {{ 35,  r}, { 40,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  31
  {"C:Wk1" , {{ 33,  g}, { 28, p1}, { 27, p1}, {  0,  X}, {  0,  X}}}, //  32
  {"C:Wk2" , {{ 34,  g}, { 29, p1}, { 32,  w}, {  0,  X}, {  0,  X}}}, //  33
  {"C:Wk3" , {{ 35,  g}, { 30, p1}, { 33,  w}, {  0,  X}, {  0,  X}}}, //  34
  {"C:Wk4" , {{ 36,  g}, { 31, p1}, { 34,  w}, {  0,  X}, {  0,  X}}}, //  35
  {"C:Wk5" , {{ 25, p1}, { 26, p1}, { 35,  w}, {  0,  X}, {  0,  X}}}, //  36
  {"C:Wu6" , {{ 26, p2}, { 27, p2}, { 38,  w}, {  0,  X}, {  0,  X}}}, //  37
  {"C:Wu7" , {{ 37,  g}, { 28, p2}, { 39,  w}, {  0,  X}, {  0,  X}}}, //  38
  {"C:Wu8" , {{ 38,  g}, { 29, p2}, { 40,  w}, {  0,  X}, {  0,  X}}}, //  39
  {"C:Wu9" , {{ 39,  g}, { 30, p2}, { 31, p2}, {  0,  X}, {  0,  X}}}, //  40
  {"1:A1"  , {{ 46,  r}, { 47,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  41
  {"2:A3"  , {{ 43, p2}, { 47,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  42
  {"2:A2"  , {{ 46,  g}, { 42, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  43
  {"3:A2"  , {{152,  w}, { 55,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  44
  {"W21"   , {{  6, p1}, { 53, p1}, { 46,  w}, {  0,  X}, {  0,  X}}}, //  45
  {"W22"   , {{ 45,  g}, { 41, p1}, { 43, p1}, {  0,  X}, {  0,  X}}}, //  46
  {"Wk2"   , {{  3,   }, {  3,   }, {  5,   }, {  5,  X}, {  0,  X}}}, //  47
  {"Wk24"  , {{ 50, p1}, { 54, p3}, { 47,  w}, {  0,  X}, {  0,  X}}}, //  48
  {"W25"   , {{ 50, p2}, { 55,  g}, {163, p2}, {  0,  X}, {  0,  X}}}, //  49
  {"Svd22" , {{ 48,  w}, { 49,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  50
  {"3:A2"  , {{ 53, p4}, { 52, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  51
  {"3:A4"  , {{ 51, p2}, { 54, p2}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  52
  {"Wu31"  , {{ 45,  r}, {  1, p1}, { 67, p1}, { 51, p1}, {  0,  X}}}, //  53
  {"Wu32"  , {{ 70, p3}, { 52, p2}, { 48,  r}, { 55,  r}, {  0,  X}}}, //  54
  {"W33"   , {{ 44, p2}, { 54, p4}, { 49,  r}, {  0,  X}, {  0,  X}}}, //  55
  {"4:A1"  , {{  0,  X}, { 57, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  56
  {"4:A2"  , {{ 56, p2}, { 67, p2}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  57
  {"4:A4"  , {{ 67, p4}, { 59, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  58
  {"4:A5"  , {{ 58, p2}, { 60, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  59
  {"4:A6"  , {{ 59, p2}, { 68,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  60
  {"4:A8"  , {{ 73,  g}, {  0,  X}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  61
  {"451"   , {{ 75,  r}, { 71,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  62
  {"461"   , {{ 74,  r}, { 72,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  63
  {"471"   , {{ 74,  g}, { 73,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  64
  {"44"    , {{ 70, p4}, { 71,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  65
  {"49"    , {{116, p2}, { 75,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  66
  {"Wu41"  , {{ 53, p3}, { 57, p2}, { 86, p1}, { 58, p1}, {  0,  X}}}, //  67
  {"W42"   , {{ 60, p2}, { 69, p2}, { 70, p2}, {  0,  X}, {  0,  X}}}, //  68
  {"Wk43"  , {{ 87, p3}, { 68,  r}, { 70, p1}, { 88, p1}, {  0,  X}}}, //  69
  {"Wu44"  , {{ 69, p3}, { 68,  g}, { 54, p1}, { 65, p1}, {  0,  X}}}, //  70
  {"W45"   , {{ 65, p2}, { 62, p2}, { 72,  w}, {  0,  X}, {  0,  X}}}, //  71
  {"W46"   , {{ 71,  g}, { 63, p2}, { 73,  w}, {  0,  X}, {  0,  X}}}, //  72
  {"W47"   , {{ 72,  g}, { 64, p2}, { 61, p1}, {  0,  X}, {  0,  X}}}, //  73
  {"W48"   , {{ 75,  g}, { 63, p1}, { 64, p1}, {  0,  X}, {  0,  X}}}, //  74
  {"W49"   , {{ 66, p2}, { 62, p1}, { 74,  w}, {  0,  X}, {  0,  X}}}, //  75
  {"5:A1"  , {{  0,  X}, { 86, p2}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  76
  {"5:A2"  , {{ 86, p4}, { 78, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  77
  {"5:A3"  , {{ 77, p2}, { 79, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  78
  {"5:A4"  , {{ 78, p2}, { 87, p2}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  79
  {"5"     , {{ 88, p4}, { 89,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  80
  {"53"    , {{ 82, p2}, { 88, p3}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  81
  {"531"   , {{120,  g}, { 81, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  82
  {"5:A7"  , {{119, p2}, { 90,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  83
  {"5:A8"  , {{118, p2}, { 90,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  84
  {"5:A9"  , {{117, p2}, { 89,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  85
  {"Wu51"  , {{ 67, p3}, { 76, p2}, { 93,  r}, { 77, p1}, {  0,  X}}}, //  86
  {"Wu52"  , {{ 95, p2}, { 79, p2}, { 69, p1}, { 88, p2}, {  0,  X}}}, //  87
  {"Wu53"  , {{ 69, p4}, { 87, p4}, { 81, p2}, { 80, p1}, {  0,  X}}}, //  88
  {"W54"   , {{ 80, p2}, { 85, p2}, { 90,  w}, {  0,  X}, {  0,  X}}}, //  89
  {"W55"   , {{ 89,  g}, { 84, p2}, { 83, p2}, {  0,  X}, {  0,  X}}}, //  90
  {"6"     , {{ 93,  w}, { 94,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  91
  {"6:A1"  , {{  0,  X}, { 93,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  92
  {"61"    , {{ 91, p1}, { 86, p3}, { 92, p2}, {  0,  X}, {  0,  X}}}, //  93
  {"62"    , {{ 95, p1}, { 96, p2}, { 91, p2}, {  0,  X}, {  0,  X}}}, //  94
  {"67"    , {{ 94,  w}, { 87, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  95
  {"7"     , {{  0,  X}, { 94,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  96
  {"100"   , {{  0,  X}, {110,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  97
  {"102"   , {{109,  r}, {  0,  X}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  98
  {"110"   , {{  0,  X}, {111,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, //  99
  {"111"   , {{  0,  X}, {111,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 100
  {"112"   , {{112,  w}, {124, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 101
  {"10:A1" , {{108,  r}, {103, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 102
  {"10:A2" , {{102, p2}, {107, p3}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 103
  {"10:A3" , {{110,  g}, {105, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 104
  {"10:A4" , {{104, p2}, {107, p4}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 105
  {"10:A5" , {{107, p4}, {  0,  X}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 106
  {"103"   , {{103, p2}, {105, p2}, {106, p1}, {  0,  X}, {  0,  X}}}, // 107
  {"W101"  , {{109,  g}, {102, p1}, {112,  r}, {  0,  X}, {  0,  X}}}, // 108
  {"W102"  , {{110,  r}, { 98, p1}, {108,  w}, {  0,  X}, {  0,  X}}}, // 109
  {"W103"  , {{ 97, p2}, {109,  w}, {104, p1}, {  0,  X}, {  0,  X}}}, // 110
  {"W111"  , {{112,  g}, {100, p2}, { 99, p2}, {  0,  X}, {  0,  X}}}, // 111
  {"W112"  , {{101, p1}, {108,  g}, {111,  w}, {  0,  X}, {  0,  X}}}, // 112
  {"12:A1" , {{122,  w}, {114, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 113
  {"12:A2" , {{113, p2}, {115, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 114
  {"12:A3" , {{114, p2}, {123,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 115
  {"12:A7" , {{125,  g}, { 66, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 116
  {"12:A8" , {{126,  r}, { 85, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 117
  {"12:A9" , {{127,  r}, { 84, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 118
  {"12:A10", {{127,  g}, { 83, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 119
  {"W121"  , {{ 25, p2}, {122,  r}, { 82, p1}, {  0,  X}, {  0,  X}}}, // 120
  {"W122"  , {{137, p2}, {122,  g}, {144, p1}, {  0,  X}, {  0,  X}}}, // 121
  {"W123"  , {{113, p1}, {120,  r}, {121,  r}, {  0,  X}, {  0,  X}}}, // 122
  {"W124"  , {{115, p2}, {145, p3}, {124, p2}, {  0,  X}, {  0,  X}}}, // 123
  {"Wu125" , {{101, p2}, {123,  g}, {146,  r}, {125,  w}, {  0,  X}}}, // 124
  {"W126"  , {{124, p4}, {126,  w}, {116, p1}, {  0,  X}, {  0,  X}}}, // 125
  {"W127"  , {{125,  r}, {117, p1}, {127,  w}, {  0,  X}, {  0,  X}}}, // 126
  {"W128"  , {{126,  g}, {118, p1}, {119, p1}, {  0,  X}, {  0,  X}}}, // 127
  {"140"   , {{144, p4}, {134, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 128
  {"141"   , {{  0,  X}, {140,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 129
  {"142"   , {{  0,  X}, {140,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 130
  {"143"   , {{  0,  X}, {141,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 131
  {"144"   , {{  0,  X}, {143,  r}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 132
  {"145"   , {{  0,  X}, {143,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 133
  {"146"   , {{128, p2}, {145, p2}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 134
  {"148"   , {{147,  w}, {138, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 135
  {"14:A1" , {{  0,  X}, {137, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 136
  {"14:A2" , {{136, p2}, {121,  w}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 137
  {"14:A3" , {{135, p2}, {139, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 138
  {"14:A4" , {{138, p2}, {  0,  X}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 139
  {"W141"  , {{141,  g}, {129, p2}, {130, p2}, {  0,  X}, {  0,  X}}}, // 140
  {"W142"  , {{142,  g}, {131, p2}, {140,  w}, {  0,  X}, {  0,  X}}}, // 141
  {"W143"  , {{144, p2}, {143,  w}, {141,  w}, {  0,  X}, {  0,  X}}}, // 142
  {"W144"  , {{142,  r}, {132, p2}, {133, p2}, {  0,  X}, {  0,  X}}}, // 143
  {"Wu145" , {{121,  g}, {142,  w}, {149, p3}, {128, p1}, {  0,  X}}}, // 144
  {"Wk146" , {{150,  r}, {134, p2}, {123,  r}, {146,  g}, {  0,  X}}}, // 145
  {"W147"  , {{147,  r}, {124, p3}, {145, p4}, {  0,  X}, {  0,  X}}}, // 146
  {"W148"  , {{135, p1}, {146,  w}, {151, p3}, {  0,  X}, {  0,  X}}}, // 147
  {"W151"  , {{ 18, p1}, {156, p2}, {149, p2}, {  0,  X}, {  0,  X}}}, // 148
  {"Wk152" , {{157,  r}, {148,  g}, {144, p3}, {153, p1}, {  0,  X}}}, // 149
  {"W153"  , {{151, p2}, {145, p1}, {154, p2}, {  0,  X}, {  0,  X}}}, // 150
  {"Wu154" , {{159, p2}, {150,  w}, {147,  g}, {152,  r}, {  0,  X}}}, // 151
  {"W155"  , {{ 44, p1}, {151, p4}, {161, p2}, {  0,  X}, {  0,  X}}}, // 152
  {"15:A1" , {{149, p4}, {154, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 153
  {"15:A2" , {{153, p2}, {150,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 154
  {"Wk161" , {{ 13, p1}, {162, p1}, {156, p1}, {  0,  X}, {  0,  X}}}, // 155
  {"Wk162" , {{155,  g}, {148,  r}, {157,  g}, {160, p1}, {  0,  X}}}, // 156
  {"W163"  , {{158, p1}, {149, p1}, {156, p3}, {  0,  X}, {  0,  X}}}, // 157
  {"16:A1" , {{157,  w}, {159, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 158
  {"16"    , {{158, p2}, {151, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 159
  {"17:A1" , {{156, p4}, {161, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 160
  {"Svd172", {{160, p2}, {152,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 161
  {"18:A1" , {{155,  r}, {163, p1}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 162
  {"18:A2" , {{162, p2}, { 49,  g}, {  0,  X}, {  0,  X}, {  0,  X}}}, // 163
};
1 Like

Thanks for the welcom, thanks for the contribution to enhance readability and maintainablility. Your coding even works with IDE 1.8.7. Great job in short time - I am speechless.
After correcting my fault in the dataset 47

{"Wk23" , {{ 48, g}, { 41, p2}, { 42, p2}, { 0, X}, { 0, X}}}, // 47

all works fine.

Thanks for the reinterpret-cast <char const*> idea. Thats new for me.

Hmm, after reading it again, I think the cast is not even needed. The following should also work if I am not mistaken.

char buf[7];
strcpy_P(buf, topology[i].Name);
Serial.print(buf);

Maybe it is best to forget my previous suggestion for now, a reinterpret_cast is best to be avoided.

2 Likes

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