Printing bytes and strings over serial

Hey guys,

I have a couple of bytes stored in EEPROM, that I'd like to send over serial in just 1 command.

I know I could do it like:

Serial.print("a,");
Serial.print(EEPROM.read(1));
Serial.print(",");
Serial.print(EEPROM.read(2));

However, this will take up a LOT of memory, doing the same function over and over. I have tried concatenating like this:

String dumpstring1 = "a";
          dumpstring1 = "," + EEPROM.read(1) + "," + EEPROM.read(2) + "," + EEPROM.read(3) + "," + EEPROM.read(4) + "," + EEPROM.read(5) + "," + EEPROM.read(6) + "," + EEPROM.read(7) + "," + EEPROM.read(8) + "," + EEPROM.read(9) + "," + EEPROM.read(10);
          Serial.println(dumpstring1);

However, get the error: error: invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'

Which I am assuming is because I'm trying to concatenate strings and bytes together.

Does anyone have any links or examples on how I could do this?

Cheers, Dan

Another place where "for" loops save memory and make your program shorter. I can't recommend them highly enough. Or more frequently.

I've changed the two dimensional array type to int.

However, there is an issue that, the array is filled with eeprom values in the setup() function.

if I put a serial.println(array[0][0]);

Right after the array is filled, I get the correct number.

However, if I put that same serial print in my loop() function, it just continually returns zero?

Cheers, Dan

However, if I put that same serial print in my loop() function, it just continually returns zero?

Maybe it is a different array.

Post your code.

int notearray[3][10]; /// For some reason, it doesn't think the array is declared if I don't put it up here ..

void setup(void) 
{
  Serial.begin(9600); // 31250
  mode = MODE_CLOSED;
  
  /// EEPROM READING DONE HERE ///
  
int notearray[3][10] = {
  {EEPROM.read(1), EEPROM.read(2), EEPROM.read(3), EEPROM.read(4), EEPROM.read(5), EEPROM.read(6), EEPROM.read(7), EEPROM.read(8), EEPROM.read(9), EEPROM.read(10)},
  {EEPROM.read(11), EEPROM.read(12), EEPROM.read(13), EEPROM.read(14), EEPROM.read(15), EEPROM.read(16), EEPROM.read(17), EEPROM.read(18), EEPROM.read(19), EEPROM.read(20)},
  {EEPROM.read(21), EEPROM.read(22), EEPROM.read(23), EEPROM.read(24), EEPROM.read(25), EEPROM.read(26), EEPROM.read(27), EEPROM.read(28), EEPROM.read(29), EEPROM.read(30)}
};

Serial.println(notearray[0][0]); // This one works
}
void loop(void) 
{
  switch (mode)
  {
    //---------------------------------------------------------------------
    case MODE_CLOSED: // All Off
      {
        // Clear the playarray - active is high - 1
        for (int i = 0; i < 10; i++){
            _playarray[0][i] = 0;
        }
        for (int i = 0; i < 10; i++){
            _playarray[1][i] = 0;
        }
        prevRow = 0;
        currRow = 1;
        
        digitalWrite(BLANKING_RED, LOW);
        digitalWrite(BLANKING_GREEN, LOW);
        int result = ButtonRead();
        if (result == BUTTON_RED)
        {
          mode = MODE_OPENING;
        }
        if (result == BUTTON_BLACK)
        {
          mode = MODE_CAL;
        }
        if (dumpdata == 1){
          //String dumpstring1 = "a";
          //dumpstring1 = dumpstring1 + "," + notearray[0][1] + "," + notearray[0][2];
          Serial.println(notearray[0][0]);  // This one doesn't
          dumpdata = 0;
        }
}
}
}

If I remove that int notearray[3][10]; from the top, it complains about notearray not being defined (On the 2nd Serial.print, but not the first one). It’s almost like the array is being contained within setup, and not shared with the loop?

Cheers,
Dan

Maybe it is a different array.

http://arduino.cc/en/Reference/Scope

http://arduino.cc/en/Reference/For

Does anyone have any links or examples on how I could do this?

The sprintf function will handle converting the numbers to strings and writing everything into a char array.

However…

I know I could do it like:…However, this will take up a LOT of memory

is wrong.

It will involve more typing, but less memory. The sprintf() function takes memory.

In your code, you have to separate the declaration of the array (the notearray global declaration) from the initialization of the array (in setup).

When you do that, the combined definition/declaration shorthand can not be used, and you must initialize each element individually.

Of course, you can use two for loops, as has been recommended many times, to do it with just 7 lines of code, including the curly braces.