Skip to main content

RAK15002 WisBlock Micro SD Card Module Quick Start Guide

Prerequisite

What Do You Need?

Before going through each and every step on using the RAK15002 WisBlock module, make sure to prepare the necessary items listed below:

Hardware

Software

Arduino

Product Configuration

Hardware Setup

The RAK15002 is a Micro SD card module that can be mounted to the IO slot of the WisBlock Baseboard. It allows the usage of Micro SD cards as a data storage medium. This module uses a 4-line SPI interface to access the SD card and supports the card insert detection feature.

For more information about RAK15002, refer to the Datasheet.

Figure 3685: RAK15002 connection to WisBlock Base

Assembling and Disassembling of WisBlock Modules

Assembling Procedure

The RAK15002 module can be mounted on the IO slot of the WisBlock Base board, as shown in Figure 2. Also, always secure the connection of the WisBlock module by using compatible screws.

Figure 3686: RAK15002 mounting connection to WisBlock Base module
Disassembling Procedure

The procedure in disassembling any type of WisBlock modules is the same.

  1. First, remove the screws.
Figure 3687: Removing screws from the WisBlock module
  1. Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.
Figure 3688: Detaching silkscreen on the WisBlock module
  1. Apply force to the module at the position of the connector, as shown in Figure 5, to detach the module from the baseboard.
Figure 3689: Applying even forces on the proper location of a WisBlock module
NOTE

If you will connect other modules to the remaining WisBlock Base slots, check on the WisBlock Pin Mapper tool for possible conflicts.

SD Card Preparation

The Micro SD Card should be formatted as FAT before using. You can use SD Card Formatter by SD Association or other third-party applications.

  1. Open the SD Card Formatter application.
Figure 3690: SD Card Formatter Application
  1. Plug in your Micro SD Card using Micro SD Card Reader, and choose your SD Card assigned drive.

  2. Select Format and proceed. Formatting will remove your SD Card's files and contents.

Figure 3691: Formatting Confirmation
  1. After successfully formatting, you will receive a message, as shown in Figure 8.
Figure 3692: Formatting Success
  1. You can now use your Micro SD Card on RAK15002 Micro SD Card Module.

Software Configuration and Example

In the following example, you will be using the RAK15002 WisBlock SD Card Module.

These are the quick links that go directly to the software guide for the specific WisBlock Core module you use:

RAK15002 in RAK4631 WisBlock Core Guide

Arduino Setup
Figure 3693: RAK15002 in RAK4631 Connection
  1. Select the RAK4631 WisBlock Core.
Figure 3694: Selecting RAK4631 as WisBlock Core
  1. Next, copy the following sample code into your Arduino IDE.
/**
@file RAK15002_SD_Card.ino
@author rakwireless.com
@brief Read, write, delete SD card file for RAK4631.
@version 0.1
@date 2021-3-11
@copyright Copyright (c) 2021
**/

#include "SPI.h"
#include "SD.h"//http://librarymanager/All#SD

/**
@brief This function is used to read data from a file.
*/
void readFile(const char * path)
{
Serial.printf("Reading file: %s\n", path);

File file = SD.open(path, FILE_READ); // re-open the file for reading.
if (file)
{
Serial.println("Read from file: ");

while (file.available())
{
Serial.write(file.read()); // read from the file until there's nothing else in it.
}
file.close(); // close the file.
}
else
{
Serial.println("Failed to open file for reading."); // if the file didn't open, print an error.
return;
}
}

/**
@brief This function is used to write data to a file.
*/
void writeFile(const char * path, const char * message)
{
Serial.printf("Writing file: %s\n", path);

File file = SD.open(path, FILE_WRITE);

if (file) // if the file opened okay, write to it:
{
if(file.print(message))
{
Serial.println("File written.");
}
else
{
Serial.println("Write failed.");
}
file.close();
}
else
{
Serial.println("Failed to open file for writing.");
return;
}
}

/**
@brief This function is used to delete a file.
*/
void deleteFile(const char * path)
{
Serial.printf("Deleting file: %s\n", path);

if(SD.remove(path))
{
Serial.println("File deleted.");
}
else
{
Serial.println("Delete failed.");
}
}

/**
@brief This function is used to test read and write file speed.
*/
void testFileIO(const char * path)
{
Serial.println("Test read and write file speed.");
Serial.printf("Writing file: %s\n", path);

static uint8_t buf[512];
size_t len = 0;
uint32_t start = millis();
uint32_t end = start;

File file = SD.open(path, FILE_WRITE);

if (file)// if the file opened okay, write to it.
{
size_t i;
start = millis();
for(i=0; i<2048; i++)
{
file.write(buf, 512);
}
end = millis() - start;
Serial.printf("%u KB written for %u ms\n", 2048 * 512/1024, end);
file.close();
}
else
{
Serial.println("Failed to open file for writing.");
return;
}
delay(10);

file = SD.open(path, FILE_READ);
if (file)
{
len = file.size();
size_t flen = len;
start = millis();
while(len)
{
size_t toRead = len;
if(toRead > 512)
{
toRead = 512;
}
file.read(buf, toRead);
len -= toRead;
}
end = millis() - start;
Serial.printf("%u KB read for %u ms\n", flen/1024, end);
file.close();
}
else
{
Serial.println("Failed to open file for reading.");
return;
}
}

void setup()
{
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}

Serial.println("=====================================");
Serial.println("RAK15002 SD Card Test.");
Serial.println("=====================================");

if (!SD.begin())
{
Serial.println("Card Mount Failed! Please make sure the card is inserted!");
return;
}

deleteFile("RAK15002.txt");

writeFile("RAK15002.txt", "RAK15002 SD Card Test.\n");

readFile("RAK15002.txt");

testFileIO("RAK15002.txt");
}

void loop()
{
}

NOTE

If you experience any error in compiling the example sketch, check the updated code for the RAK4631 WisBlock Core Module that can be found on the RAK15002 WisBlock Example Code Repository.

  1. Click the link highlighted in red to locate the library, as shown in Figure 11.
Figure 3695: Locating the required library in the Library Manager
  1. Install the required library, as shown in Figure 12.
Figure 3696: Installing the Library
  1. Select the correct port and upload your code, as shown in Figure 13 and Figure 14.
Figure 3697: Selecting the correct Serial Port
Figure 3698: Uploading code
  1. When you have successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the RAK15002 read/write message, as shown in Figure 15. You will be able to see the status and the function performed on your SD Card.
Figure 3699: RAK15002 logs
  1. To verify the content, you can use a card reader and open the text file generated, as shown in Figure 16 and Figure 17.
Figure 3700: The file generated using the code
Figure 3701: Text file contents

RAK15002 in RAK11200 WisBlock Core Guide

Arduino Setup
Figure 3702: RAK15002 in RAK11200 Connection
  1. Select the RAK11200 WisBlock Core.
Figure 3703: Selecting RAK11200 as WisBlock Core
  1. Next, copy the following sample code into your Arduino IDE.
/**
@file RAK15002_SD_Card.ino
@author rakwireless.com
@brief Read, write, delete SD card file for RAK11200.
@version 0.1
@date 2021-3-11
@copyright Copyright (c) 2021
**/

#include "FS.h"
#include "SD.h"
#include "SPI.h"

/**
@brief This function is used to read data from a file.
*/
void readFile(fs::FS &fs, const char * path)
{
Serial.printf("Reading file: %s\n", path);

File file = fs.open(path);
if(!file)
{
Serial.println("Failed to open file for reading.");
return;
}

Serial.println("Read from file: ");
while(file.available())
{
Serial.write(file.read());
}
file.close();
}

/**
@brief This function is used to write data to a file.
*/
void writeFile(fs::FS &fs, const char * path, const char * message)
{
Serial.printf("Writing file: %s\n", path);

File file = fs.open(path, FILE_WRITE);
if(!file)
{
Serial.println("Failed to open file for writing.");
return;
}
if(file.print(message))
{
Serial.println("File written.");
}
else
{
Serial.println("Write failed.");
}
file.close();
}

/**
@brief This function is used to append data to a file.
*/
void appendFile(fs::FS &fs, const char * path, const char * message)
{
Serial.printf("Appending to file: %s\n", path);

File file = fs.open(path, FILE_APPEND);
if(!file)
{
Serial.println("Failed to open file for appending.");
return;
}
if(file.print(message))
{
Serial.println("Message appended.");
}
else
{
Serial.println("Append failed.");
}
file.close();
}

/**
@brief This function is used to delete a file.
*/
void deleteFile(fs::FS &fs, const char * path)
{
Serial.printf("Deleting file: %s\n", path);
if(fs.remove(path))
{
Serial.println("File deleted.");
}
else
{
Serial.println("Delete failed.");
}
}

/**
@brief This function is used to test read and write file speed.
*/
void testFileIO(fs::FS &fs, const char * path)
{
Serial.println("Test read and write file speed.");
Serial.printf("Writing file: %s\n", path);

static uint8_t buf[512];
size_t len = 0;
uint32_t start = millis();
uint32_t end = start;

File file = fs.open(path, FILE_WRITE);
if(file)// if the file opened okay, write to it.
{
size_t i;
start = millis();
for(i=0; i<2048; i++)
{
file.write(buf, 512);
}
end = millis() - start;
Serial.printf("%u KB written for %u ms\n", 2048 * 512/104, end);
file.close();
}
else
{
Serial.println("Failed to open file for writing.");
return;
}

file = fs.open(path, FILE_READ);
if(file)
{
len = file.size();
size_t flen = len;
start = millis();
while(len)
{
size_t toRead = len;
if(toRead > 512)
{
toRead = 512;
}
file.read(buf, toRead);
len -= toRead;
}
end = millis() - start;
Serial.printf("%u KB read for %u ms\n", flen/1024, end);
file.close();
}
else
{
Serial.println("Failed to open file for reading.");
return;
}
}

void setup()
{
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("=====================================");
Serial.println("RAK15002 SD Card Test.");
Serial.println("=====================================");

if(!SD.begin(SS,SPI,80000000,"/sd",5))// Start access to the SD.
{
Serial.println("Card Mount Failed! Please make sure the card is inserted!");
return;
}

deleteFile(SD, "/RAK15002.txt");

writeFile(SD, "/RAK15002.txt", "RAK15002 SD Card Test.\n");

readFile(SD, "/RAK15002.txt");

testFileIO(SD, "/RAK15002.txt");
}

void loop()
{
}

NOTE

If you experience any error in compiling the example sketch, check the updated code for the RAK11200 WisBlock Core Module that can be found on the RAK15002 WisBlock Example Code Repository.

  1. Click the link highlighted in red to locate the library, as shown in Figure 20.
Figure 3704: Locating the required library in the Library Manager
  1. Install the required library, as shown in Figure 21.
Figure 3705: Installing the Library
  1. Select the correct port and upload your code, as shown in Figure 22 and Figure 23.
Figure 3706: Selecting the correct Serial Port
Figure 3707: Uploading code
NOTE

RAK11200 requires the BOOT0 pin to be configured properly before uploading. If not done properly, uploading the source code to RAK11200 will fail. Check the full details on the RAK11200 Quick Start Guide.

  1. When you have successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the RAK15002 read/write message, as shown in Figure 24. You will be able to see the status and the function performed on your SD Card.
Figure 3708: RAK15002 logs
  1. To verify the content, you can use a card reader and open the text file generated, as shown in Figure 25 and Figure 26.
Figure 3709: The file generated using the code
Figure 3710: Text file contents

RAK15002 in RAK11300 WisBlock Core Guide

Arduino Setup
  1. Select the RAK11300 WisBlock Core, as shown in Figure 27.
Figure 3711: Selecting RAK11300 as WisBlock Core
  1. Next, copy the following sample code into your Arduino IDE.
/**
@file RAK15002_SD_Card.ino
@author rakwireless.com
@brief Read, write, delete SD card file for RAK4631.
@version 0.1
@date 2021-3-11
@copyright Copyright (c) 2021
**/

#include "SPI.h"
#include "SD.h"//http://librarymanager/All#SD

/**
@brief This function is used to read data from a file.
*/
void readFile(const char * path)
{
Serial.printf("Reading file: %s\n", path);

File file = SD.open(path, FILE_READ); // re-open the file for reading.
if (file)
{
Serial.println("Read from file: ");

while (file.available())
{
Serial.write(file.read()); // read from the file until there's nothing else in it.
}
file.close(); // close the file.
}
else
{
Serial.println("Failed to open file for reading."); // if the file didn't open, print an error.
return;
}
}

/**
@brief This function is used to write data to a file.
*/
void writeFile(const char * path, const char * message)
{
Serial.printf("Writing file: %s\n", path);

File file = SD.open(path, FILE_WRITE);

if (file) // if the file opened okay, write to it:
{
if(file.print(message))
{
Serial.println("File written.");
}
else
{
Serial.println("Write failed.");
}
file.close();
}
else
{
Serial.println("Failed to open file for writing.");
return;
}
}

/**
@brief This function is used to delete a file.
*/
void deleteFile(const char * path)
{
Serial.printf("Deleting file: %s\n", path);

if(SD.remove(path))
{
Serial.println("File deleted.");
}
else
{
Serial.println("Delete failed.");
}
}

/**
@brief This function is used to test read and write file speed.
*/
void testFileIO(const char * path)
{
Serial.println("Test read and write file speed.");
Serial.printf("Writing file: %s\n", path);

static uint8_t buf[512];
size_t len = 0;
uint32_t start = millis();
uint32_t end = start;

File file = SD.open(path, FILE_WRITE);

if (file)// if the file opened okay, write to it.
{
size_t i;
start = millis();
for(i=0; i<2048; i++)
{
file.write(buf, 512);
}
end = millis() - start;
Serial.printf("%u KB written for %u ms\n", 2048 * 512/1024, end);
file.close();
}
else
{
Serial.println("Failed to open file for writing.");
return;
}
delay(10);

file = SD.open(path, FILE_READ);
if (file)
{
len = file.size();
size_t flen = len;
start = millis();
while(len)
{
size_t toRead = len;
if(toRead > 512)
{
toRead = 512;
}
file.read(buf, toRead);
len -= toRead;
}
end = millis() - start;
Serial.printf("%u KB read for %u ms\n", flen/1024, end);
file.close();
}
else
{
Serial.println("Failed to open file for reading.");
return;
}
}

void setup()
{
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}

Serial.println("=====================================");
Serial.println("RAK15002 SD Card Test.");
Serial.println("=====================================");

if (!SD.begin())
{
Serial.println("Card Mount Failed! Please make sure the card is inserted!");
return;
}

deleteFile("RAK15002.txt");

writeFile("RAK15002.txt", "RAK15002 SD Card Test.\n");

readFile("RAK15002.txt");

testFileIO("RAK15002.txt");
}

void loop()
{
}

NOTE

If you experience any error in compiling the example sketch, check the updated code for the RAK11300 WisBlock Core Module that can be found on the RAK15002 WisBlock Example Code Repository.

  1. Click the link highlighted in red to locate the library, as shown in Figure 28.
Figure 3712: Locating the required library in the Library Manager
  1. Install the required library, as shown in Figure 29.
Figure 3713: Installing the Library
  1. Select the correct port and upload your code, as shown in Figure 30 and Figure 31.
Figure 3714: Selecting the correct Serial Port
Figure 3715: Uploading code
  1. When you have successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the RAK15002 read/write message, as shown in Figure 32. You will be able to see the status and the function performed on your SD Card.
Figure 3716: RAK15002 logs
  1. To verify the content, you can use a card reader and open the text file generated, as shown in Figure 33 and Figure 34.
Figure 3717: The file generated using the code
Figure 3718: Text file contents