I have a project running on a XIAO nrf52840 with a Sharp MIP-display on SPI (needed for performance) and need to log a bit of data to the sd-card coming from sensors… basically timestamp, GPS lat/lng and 4 float values, with at least 2Hz, better 10.
So this would be:
it would be something like:
timestamp (The time stamp consists of the number of weeks since that zero point and the number of seconds since the last week number change (0 to 604,799).) - so f.e. 2200 (weeks) and 604000 (seconds) making it 220060400 - 9 digits long
GPS latitude and longitude (20.1234567, 10.1234567) so 20 digits
4 floats with 2 decimal places, so 5 digits each, 20 digits in sum
with crlf, separators etc. around 60 characters per update, 480 bytes, 10/s would then be 4800bytes/s
So can I use some SPI-adapter for an SD-card and just use a soft-SPI? Should be plenty fast enough, right?
@msfujino I imagine that the file open/close take a lot of the 30ms, so I could of course also “cache” them in RAM for a few seconds and then purge them into the SD every now and then, if that makes more sense?
I measured open, save, and close individually. Increasing the number of data was not proportional, perhaps due to the buffer.
If it can be closed properly before turning off the power, there is no need to open/close every time.
I think the Adafruit breakout board will work fine.
open : 13~14mS
save 60 digit : 3~7mS
close : 9~10mS
So I could basically get away with opening the file once on setup and close it on before shutdown. Or I could do it every minute to be on the safe side.
What would happen if the last “close” would be missing? Would just the data since the last open not be saved?
If I would understand how to power-down the XIAO including all connected peripherals (display, GPS, SD-card-adapter) with a button I would go this route. At the moment, I’m switching it with a hardware switch, which is unelegant but at least not using power when down
Btw @msfujino you are a great inspiration and I want to thank you again for all your generous help
Explained in the case of connecting a 3.7V battery to the pad and turning it on/off with the power switch. (This has been proven with XIAO_SAMD21, but not tried with XIAO_nRF52840.)
Monitor the battery voltage PIN_VBAT by AD conversion, and “close” and stop the sketch when the voltage drops below 3V, for example.
Monitor the battery voltage with COMP (datasheet 6.5 COMP–Comparator) and generate an interrupt to “close” and stop the sketch when the voltage drops below 3V, for example.
To ensure that “close” is executed, the operating voltage of XIAO and SD must be 3 V or higher for 10 mS, for example. You will need to connect a capacitor of about 1000uF (value not calculated) to the battery pad in case of a sudden battery disconnection or power switch off.
You will need to connect a capacitor of about 1000uF (value not calculated) to 3.3V pin in case of a sudden battery disconnection or power switch off.