I have a 2d array:
const byte messages_for_measurement[2][8] PROGMEM =
{
{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 },
{ 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 },
};
I want to send one of these sub-array over software serial.
Initially, this produced junk data:
swSerial.write( messages_for_measurement[0], sizeof(messages_for_energy_meter[0]) );
Then I learned about pgm_read_byte_near()
and pgm_read_word()
. I tried every combination but I did not get this to work:
swSerial.write(pgm_read_byte_near(pgm_read_word(messages_for_measurement[0]))), sizeof(pgm_read_byte_near(pgm_read_word(messages_for_measurement[0])));
and
swSerial.write(pgm_read_byte_near(&pgm_read_word(messages_for_measurement[0]))), sizeof(pgm_read_byte_near(pgm_read_word(&messages_for_measurement[0])));
and
swSerial.write(char(pgm_read_byte_near(pgm_read_word(messages_for_measurement[0])))), sizeof(char(pgm_read_byte_near(pgm_read_word(messages_for_measurement[0]))));
and
swSerial.write(char(pgm_read_byte_near(pgm_read_word(&messages_for_measurement[0])))), sizeof(char(pgm_read_byte_near(pgm_read_word(&messages_for_measurement[0]))));
How can I send the sub-array over serial, when the 2d array is in PROGMEM?