This example shows how to turn on the SD card. Delete an specified filename. In the case it exists, the first loop creates the file, but the following loops will not because the file already exists.
Required Materials
1 x Waspmote
1 x Battery
1 x SD card
1 x MiniUSB wire
Notes
- Remember that only 8.3 SHORT FILE NAME are valid for files and directories
- In this example, the file is created just once in the first loop. The consecutive callings will be wrong as the file is already created.
- This example can be executed in Waspmote v12 and Waspmote v15
Code
/* * ------ [SD_01] - Create/delete SD file -------- * * Explanation: Turn on the SD card. Delete specified filename * in the case it exists. The first loop creates the file, but * the following loops will not because the file already exists. * * Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L. * http://www.libelium.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Version: 3.0 * Design: David Gascón * Implementation: Yuri Carmona */// define file name: MUST be 8.3 SHORT FILE NAMEchar filename[]="FILE1.TXT";voidsetup(){// Open USB portUSB.ON();USB.println(F("SD_1 example"));// Set SD ONSD.ON();// Delete fileif(SD.del(filename)) {USB.println(F("file deleted")); }else {USB.println(F("file NOT deleted")); }}voidloop(){ // Create file1if(SD.create(filename)) {USB.println(F("file created")); }else {USB.println(F("file NOT created")); } delay(5000);}
Output
H# SD_1 example file deleted file created file NOT created file NOT created ...