Creating more than one RTC variable

I am trying to create multiple variables using the RTC_DATA_ATTR program. There are two variables I would like to be stored between sleeps, so I tried the following commands:

RTC_DATA_ATTR int cnt = -1;
RTC_DATA_ATTR int 5min_cnt = 0;

Executing one of these lines worked, however in the same program I received an error. Is there a special way to declare multiple RTC variables?

Please post the code.
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

#include "driver/adc.h"
#include <iostream>
#define BAND        868E6  // you can set band here directly,  e.g. 868E6,915E6
#define EEPROM_SIZE 128     // bits per flash memory entry
#define Fbattery    3700   // the default battery is 3700mv when the battery is fully charged
#define ADC_PIN     39     // CT voltage
#define NSAMP       12     // number of 5 minute samples being stored in flash memory
#define Fbattery    3700  // the default battery is 3700mv when the battery is fully charged.


RTC_DATA_ATTR int cnt = -1;
RTC_DATA_ATTR int 5min_cnt = 0; // Might not need

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Error Message:

Arduino: 1.8.20 Hourly Build 2021/12/20 07:33 (Windows 10), Board: "Heltec WiFi LoRa 32(V2), Disabled, 240MHz (WiFi/BT), 921600, None, REGION_EU868, None"





















V3Test:13:19: error: expected unqualified-id before numeric constant

 RTC_DATA_ATTR int 5min_cnt = 0; // Might not need

                   ^~~~~~~~

exit status 1

expected unqualified-id before numeric constant



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Change 5min_cnt to ```fiveMin_cnt".

Use a structure.

struct Button {
  const uint8_t PIN;
  volatile uint32_t numberKeyPresses;
  volatile bool pressed;
};

RTC_DATA_ATTR  struct Button my_button;

From the C++ VALID IDENTIFIERS page.

The first character of an identifier must be alphabetic or an underscore (it cannot be a numeric digit).

1 Like

Oops thanks for the help! Slowly learning.

Guess how I found out about valid identifiers?

How did you find out about valid identifiers? :slight_smile:

Same way that you did. Used one in a program and got that error. Took me a while to search out the answer. Did not have the forum at that time.

Haha it's always the small things! This is my first time ever using a forum and I definitely saved a lot of time by trying it!

What we are here for. I do enjoy working with Arduino and hope to help others enjoy it too. Being stumped on a problem is no fun. I made most of the new user mistakes so it is easy to help.

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