HUM: SD CARD MODULE

You are a beginner with Dasduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by soldered where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Dasduino and the basic code. Everything else is left to your imagination.
INTRODUCTION
In this tutorial we will learn how to store data from Dasduino to an SD card using the SD card module. SD card module allows connecting an SD card of up to 32GB to Dasduino and we can store different data that is important and later process it on the computer or use it again on Dasduino. Using this module we can also read data from an SD card and display them on the LCD display or use them for another function.
SD CARD PREPARATION
To work, the module uses an SD card to which it stores data, but in order to work with the card it is necessary to format the card in the FAT16 or FAT32 format. For micro SD card it is necessary to use an adapter and if the card does not work with it, we must set the switch marked with Lock (in the picture) to the upper position in order to work with the card (if it is under you will not be able to format it). When you format the card in the FAT16 or FAT32 format you are ready to work. It is not necessary to have a file saved on the card if we want to write on it because Croduino will create a file itself, with the name we set in the code.
HOW TO CONNECT IT?
The module uses SPI communication so we need to connect the pins of the module to Dasduino pins that are used for SPI communication. Pin CS can be connected to any other Dasduino pin, only then we must change which pin we have connected it to in the code.
SD-Modul >>>>>>>>>>Dasduino
MOSI >>>>>>>>>>>>>>>> D11
MISO >>>>>>>>>>>>>>>> D12
SCK >>>>>>>>>>>>>>>>> D13
CS >>>>>>>>>>>>>>>>>> D10
+5V >>>>>>>>>>>>>>>> +5V
GND >>>>>>>>>>>>>>>> GND
When we connect Dasduino and the SD module we are ready to program Dasduino in order for it to store data to an SD card or read from the card.
ARDUINO CODE
In the following example we read values from the analog pin and store them on the card. To the analog pin we can connect the potentiometer (one end of the potentiometer to +5V, the other to GND, and the slider to the analog pin) or if nothing is connected, we will get random values between 0 and 1024.
We save the data to the Podaci.csv file, and later we can enter data from it to Excel and process it, and that is why data is divided by commas and each data has its own serial number which is set by the variable ocitanje. If we do not need data processing we can change it so that the data is saved to a .txt file (only replace csv with txt). The name of the file must not exceed 8 signs, because the program will not work. To work with the SD module it is not necessary to download a library because it is in the Arduino IDE along with the library for SPI communication.