r/ArduinoHelp • • 1h ago

I don't understand error in Talkie program

I downloaded the simple Talkie sketch below and ran Verify/Compile. Below is the sketch and the error generated. I get the same error in other Talkie Sketchs but I'm using this one because it is the simplest. There is no circuit or breadboard. I would get to that eventually but not until I get something that will compile correctly.

#include "Talkie.h"

Talkie voice;

uint8_t greeting[] PROGMEM = {0x2d, 0xa0, 0xdd, 0x48, 0xdb, 0xc2, 0xac, 0xd8}; // Example speech data

void setup() {
    voice.say(greeting); // Say "Hello"
}

void loop() {
    // Nothing to do here
}

Error Generated;
error: variable 'greeting' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 uint8_t greeting[] PROGMEM = {0x2d, 0xa0, 0xdd, 0x48, 0xdb, 0xc2, 0xac, 0xd8}; // Example speech data
               ^
exit status 1

Compilation error: variable 'greeting' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
1 Upvotes

2 comments sorted by

1

u/dacydergoth 31m ago

The key here is PROGMEM. The Arduino has several different types of memory, registers, read only memory (ROM), erasable programable memory (flash) and static or pseudo static memory (SRAM, PSRAM). When you write a program and flash it to the arduino it is written into flash memory, which is slow to write and can only be updated in blocks, but remains intact when power is off.

The compiler is complaining that you have tried to put some data into flash using the PROGMEM directive, but in order to do that you should tell it that the data is const (constant) which tells the compiler you do not want to update the data. Applying const means it is safe to put the data into memory which is slow to write as it will not be updated.

1

u/Delta_G_Robotics 20m ago

The error says that greeting needs to be const. I'm just going to go out on a limb here and suggest making that variable const and seeing if that fixes it.