1
votes

I am writing some code for a project where I have a GSM module interfaced with an Arduino to communicate certain notifications when a sensor is triggered and to receive commands via SMS. One such command is to set the 'call out' number via SMS. IE if I send the word 'Set' to the GSM module, the number the message is received from becomes the new number that the GSM module will call out to when sensors are triggered.

I have to initialise a default phone number in the code:

char ph_number[]="+35387914xxxx";

Then within my program I have some code to check for any SMS' that contain the 'Set' command and if so set ph_number = to the senders number.

I need to then permanently save that new number to become the default call out number, even if the Arduino is reset, until such time as a new Set command received. Is there a way to do this? Is it even possible?

2
That was a lot of unnecessary text to simply ask: Is there any permanent storage on the Arduino and, if so, how can I use it?mah

2 Answers

2
votes

You could store it in a special location in the FLASH or EEPROM, and read it from there on startup.

1
votes

You can read / write to the EEPROM using the Arduino EEPROM library. This allows you to access one point in the memory at a time, an example sketch would be:

#include <EEPROM.h>

int a = 0;
int value;

void setup()
{
  a = EEPROM.read(0); //reads from point 0 in the memory (the first point)
}

void loop()
{
   value = analogRead(A0);
   if(value != a){
       a = value;
       EEPROM.write(0, a);
   }
}

When saving chars, they are first converted into their decimal equivalents before being saved, and must be converted out again afterwards. It's also important to remember that each point in the memory can store only 1 byte of data with a maximum value of 255, and the EEPROM has a limited number of read/writes - the factory specified maximum is 100000 but it can probably go higher.