Working offline
If your data is more sensitive and you don't want to share it across the Wi-Fi network or you don't have Wi-Fi connectivity, a solution is to store your data on an SD card.
Let's see how data can be stored on an SD card.
Necessary hardware that will be used:
- Wemos D1 mini:
![](https://static.packt-cdn.com/products/9781787282629/graphics/e3a30a35-2f51-4e30-a047-cb0b85b8c514.png)
- microSD card shield:
![](https://static.packt-cdn.com/products/9781787282629/graphics/07534761-9067-4836-b818-62e699b2ab23.png)
- microSD card:
![](https://static.packt-cdn.com/products/9781787282629/graphics/51a5e773-380b-4a39-9d76-d6e3f71075a9.png)
Since the microSD card is a shield for the Wemos D1 mini, it is easy to stack them; you just need to solder the pins that are coming into the package:
![](https://static.packt-cdn.com/products/9781787282629/graphics/d61520ee-a94e-495c-868b-d29b85ebb703.png)
Let's determine the size of the SD card with the following sketch.
Include the SPI.h
and the SD
library:
#include <SPI.h> #include <SD.h>
Set up variables using the SD utility library functions:
Sd2Card card; SdVolume volume; SdFile root; const int chipSelect = D8;
In the setup
function, we will determine if the card is inserted or not and the card details will be read over SPI:
void setup() { Serial.begin(115200); Serial.print("\nInitializing SD card...");
Use the initialization code from the utility libraries...