Author Topic: C++ Datalogger - FRAM read write  (Read 833 times)

C++ Datalogger - FRAM read write
« on: 31 December, 2023, 06:28:47 am »
Following on from this post https://yacf.co.uk/forum/index.php?topic=127388.0
I am adapting ESP8266 solar charge controller interface code for datalogging to local memory.

Have hacked and tested to the point where I'm confident my adaptions will work..

Now to write data to FRAM, I do have some ideas about how to do this, a 'byte-map' would seem best.
Write array to FRAM . Current record referenced by a pointer also saved in FRAM

Reading data back to CSV would just then be iterating back through the array and unpacking.

There is a FRAM library here.. https://github.com/RobTillaart/FRAM_I2C (one of several)
Code examples seem to be  rather more complex than I need, or am I just being too simple?

I am wondering whether I have taken on too much. my coding pencil is not at all sharp, but hey,
I'm retired and it keeps raining...

Some variables I have assigned with comments, give some idea of how little data I need to log and before anyone asks, I spent time considering SD cards, they use 10's of mA all the time, or many wires and FETS to power cycle.. I just don't need the space.

Code: [Select]
//FRAM Variables Hourly in some array RRD to overwrite oldest record
uint8_t day_hour;           // day, hour as packed BCD
uint8_t Solar_Wh;           // total solar
uint8_t Load_Wh;            // total load (derive battery)
uint8_t Bat_Vmin;
uint8_t Bat_Tmin;           // minimum battery temp
uint8_t Flags;                 // (Battery full(float volts and no current)), (Temp threshold)...

//  6 bytes/hr 144/day 1008 week
//  even better if you don't record night-time no load

//FRAM Variables daily in some array RRD to overwrite oldest record
uint8_t month_day;           // as packed BCD
uint8_t flgs_year;           //four flags : yy as packed BCD
uint16_t Solar_Wh;           // total solar max 1024 Wh 10 bits
uint8_t Load_Wh;             // total load max 254 Wh (derive battery)
uint8_t Bat_Vmin;
uint8_t Bat_Tmin;           // minimum battery temp
uint8_t Bat_Tmax;           //

// 8 bytes day , 56 week, 20,440 year.. ~2/3 of 32K FRAM
And finally if anyone want's to take a look-see..https://github.com/hedley-a/EpeverLoggerPowerSave
I do have another public repo with the changes to the GUI.. I know you can fork but...


Re: C++ Datalogger - FRAM read write
« Reply #1 on: 31 December, 2023, 08:27:35 am »
Your load_Wh variable doesn't have much head room. Is there a possibility it’ll exceed 255 in the future and making it 16 bit now might be worth doing? I am sure you will hsve put checks in your code to prevent overflow.

Re: C++ Datalogger - FRAM read write
« Reply #2 on: 31 December, 2023, 09:05:07 am »
Quote
Your load_Wh variable doesn't have much head room. Is there a possibility it’ll exceed 255 in the future and making it 16 bit now might be worth doing? I am sure you will have put checks in your code to prevent overflow.
You are right, just 40W max of lights + another 12(ish) of mobile bone USB charging..
Fine for hourly totals, bit tight for a day... Actually packing  < 999 wh as BCD is efficent, 12 bits..

Re: C++ Datalogger - FRAM read write
« Reply #3 on: 31 December, 2023, 10:41:07 am »
Ah ha!
I now haz the simple FRAM destructions...
https://github.com/adafruit/Adafruit_FRAM_I2C/blob/master/examples/Generic_I2C_EEPROM/Generic_I2C_EEPROM.ino
formating my variables into 8 bit chunks is the next exercise...