My project is a Doll House, specifically the lighting of led in a number of rooms.
I have the sketch in Wokwi [Doll House Light - Wokwi Arduino and ESP32 Simulator]
( I know the SD is not correctly connected yet).
The file should contain the state of each led etc., like a config file which will be used when starting up.
My problem/question is what is a good way to store the data should - use enum or Structure or even a txt file.
const uint8_t brightnessMin = 0; // minimum brightness
const uint8_t brightnessMax = 255; // maximum brightness
const uint8_t brightnessInc = 10; // increase brightness by
uint8_t brightness = brightnessMax; // container for current brightness
uint8_t currentButton = -1; // container for current button pressed
uint16_t received = 0; // received container
// TIME
const unsigned long SamplePeriod = 1000; // sampling period in milliseconds
const uint16_t long delay_1 = 1000; // delay used for testing
How many records do you intend to store on the SD?
From the variable definitions, you apparently intend on updating some data elements and storing them: apparently by overwriting the old data.
The nature of SD flash will make this rewrite operation slower than sequential writes as you are effectively doing random record updates.
A far better approach would be external flash IC storage or even better FRAM.
Alternately, just keep the power on the Arduino and maintain all your states in SRAM.
Thanks for your reply, I would cap the number of records at 20.
Since this is on a nano I didn't think it would have enough memory.
Also I am not familiar Using SRAM.
You are already using SRAM. That is where all program variables are stored.
The suggestion was to keep the Arduino on, and your program running at all times.
You can store quite a bit of data in EEPROM and it will be maintained during power off. One byte of EEPROM would store the on/off states of 8 LEDs, for example.
Thi swould not be do able.
Thanks for the eeprom info I have looked into this and thought that with my MCU being a nano the would not be enough memory.
i was unsure as to how to ; use enum or structure to read and write the information using either a SD card or EEPROM.
From what has been posted here I will use structure.(as a database record).
It is suggested here that using a SD card for 20 records should be reconsidered.
So I would like to used EEPROM.
Hope this answers your question.
No. With a "database" you supply an interface program with some key data that may be part of the database indexing structure. The interface program returns that matching data or an indicator that the data does not exist. If more than one database entry matches the key data, the subsequent matches will be returned one at a time.
An SD card file is a continuous set of records, one after another. There are many creating record for the file and updating them. You could even create a secondary file of indexing data from the records and include the record number in the first file. Then you could sort the second file to some order and use those sorted records to give you the "record number" in the first file and then you could randomly read that record.
Lots of ways to skin the cat. I just followed our cat through the snow to neighboring property 1/4 mile away. Never did find him. Have to wait till he gets hungry!
I hope your cat comes home as I am sure he/she will.
Your response is much appreciated and informative, however it further confuses me as to which is the best way to proceed.
Yeah, he came back home. His first home was with a young lady in a small trailer on a big cattle ranch about 25 miles East of here. There were lots of barns and other buildings there. We don't have that many and I think he was looking for familiar territory.
The minimum memory buffers needed for any SD file is 512 bytes for the directory and another 512 bytes reserved for your data, even if you use only one byte.
Suggest you make an array of structures for your project. You mentioned 20, so 20 entries of your control structure. All stored in EPROM and returned from EPROM when your program is started. That will take up much less Arduino memory than SD card.
Glad he came home, I am struggling with a simple, clear,write, read EEPROM sample.
I have some difficulty understanding most of the examples that I have googled. I learn better by doing so if someone could look at my last sample wokwi and help me I would appreciate it.