본문 바로가기

IT/IoT

Waspmote-SD Examples

 RTC 01: Setting and reading time

필요사항

1 x Waspmote

1 x MiniUSB wire

1 x Battery

노트

  • 시간을 정의하는 문자열은 "yy : mm : dd : dow : hh : mm : ss"로 표시됩니다.
  • 이 예제는 Waspmote v12 및 Waspmote v15에서 실행할 수 있습니다.

코드

/*  
 *  ------ [RTC_1] Setting and reading time example -------- 
 *  
 *  Explanation: This example shows how to set and read the Time using
 *  the Waspmote RTC
 * (설명 :이 예제는 Waspmote RTC를 사용하여 시간을 설정하고 읽는 방법을 보여줍니다.)
 *  
 *  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 <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           3.0
 *  Design:            David Gascón 
 *  Implementation:    Marcos Yarza
 */

void setup()
{
  // Open the USB connection
  USB.ON();
  USB.println(F("RTC_1 example"));

  // Powers RTC up, init I2C bus and read initial values
  USB.println(F("Init RTC"));
  RTC.ON();
  
  // Setting time [yy:mm:dd:dow:hh:mm:ss]
  RTC.setTime("17:11:09:06:17:40:00");
  USB.print(F("Setting time: "));
  USB.println(F("17:11:09:06:17:40:00"));
}

void loop()
{
  // Reading time
  USB.print(F("Time [Day of week, YY/MM/DD, hh:mm:ss]: "));
  USB.println(RTC.getTime());
  
  delay(1000); 
}

결과

SD 01: Create/delete SD file

필요사항

1 x Waspmote

1 x Battery

1 x SD card

1 x MiniUSB wire

노트

  • 파일과 디렉토리에는 8.3 SHORT FILE NAME만 유효하다는 것을 기억하십시오.
  • 이 예제에서 파일은 첫 번째 루프에서 한 번만 만들어집니다. 파일이 이미 생성되었으므로 연속 호출이 잘못됩니다.
  • 이 예제는 Waspmote v12 및 Waspmote v15에서 실행할 수 있습니다.

코드

/*  
 *  ------ [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. 
 *  (설명 : SD 카드를 켭니다. 파일 이름이있는 경우 삭제하십시오.
 *   첫 번째 루프는 파일을 만들지만 파일이 이미 있으므로 다음 루프가 생성되지 않습니다.)
 *  
 *  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 <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           3.0
 *  Design:            David Gascón 
 *  Implementation:    Yuri Carmona
 */

// define file name: MUST be 8.3 SHORT FILE NAME
char filename[]="FILE1.TXT";


void setup()
{
  // Open USB port
  USB.ON();
  USB.println(F("SD_1 example"));

  // Set SD ON
  SD.ON();

  // Delete file
  if(SD.del(filename)) 
  {
    USB.println(F("file deleted"));
  }
  else 
  {
    USB.println(F("file NOT deleted"));  
  }

}


void loop()
{  
  // Create file1
  if(SD.create(filename))
  {
    USB.println(F("file created"));
  }
  else 
  {
    USB.println(F("file NOT created"));  
  }  
    
  delay(5000);


}

결과

SD 02: Write file

필요사항

1 x Waspmote

1 x Battery

1 x SD card

1 x MiniUSB wire

노트

  • 단 8.3 SHORT FILE NAME만이 파일과 디렉토리에 유효하다는 것을 기억하십시오
  • SD 카드를 넣거나 빼기 전에 Waspmote가 꺼져 있는지 확인하십시오. 그렇지 않으면 SD 카드가 손상 될 수 있습니다.
  • SD 카드에 진행중인 읽기 또는 쓰기 작업이있는 동안에는 Waspmote를 끄거나 재설정하지 말아야합니다. 그렇지 않으면 SD 카드가 손상되어 데이터가 손실 될 수 있습니다. 진행중인 SD 작업이있을 수 있다고 생각되면 작업이 완료 될 때까지 잠시 기다리십시오.
  • 이 예제는 Waspmote v12 및 Waspmote v15에서 실행할 수 있습니다.

코드

/*  
 *  ------ [SD_02] - Write data to a SD file -------- 
 *  
 *  Explanation: Turn on the SD card. Write data in SD file
 *  indicating the position to write.
 * (설명 : SD 카드를 켭니다. 기록할 위치를 나타내는 SD 파일에 데이터를 씁니다.)
 *  
 *  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 <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           3.0
 *  Design:            David Gascón 
 *  Implementation:    Yuri Carmona
 */

// define file name: MUST be 8.3 SHORT FILE NAME
// 파일 이름 정의는 반드시 8.3보다 짧게 지어야 합니다.
char filename[]="FILE2.TXT";

// define hexadecimal data
// 16 진수 데이터 정의
uint8_t data[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0xAA,0xAA};

// define variable
// 변수 정의
uint8_t sd_answer;


void setup()
{
  // open USB port
  // USB 포트 열기
  USB.ON();
  USB.println(F("SD_2 example"));
  
  // Set SD ON
  // SD 카드 셋팅
  SD.ON();
    
  // Delete file
  // 파일 삭제
  sd_answer = SD.del(filename);
  
  if( sd_answer == 1 )
  {
    USB.println(F("file deleted"));
  }
  else 
  {
    USB.println(F("file NOT deleted"));  
  }
    
  // Create file
  // 파일 생성
  sd_answer = SD.create(filename);
  
  if( sd_answer == 1 )
  {
    USB.println(F("file created"));
  }
  else 
  {
    USB.println(F("file NOT created"));  
  } 
}


void loop()
{     
  
  // 1 - It writes “hello” in file at position 0    
  // 1 - 위치 0의 파일에 "hello"를 씁니다. 
  sd_answer = SD.writeSD(filename,"hello", 0);
  
  if( sd_answer == 1 ) 
  {
    USB.println(F("\n1 - Write \"hello\" in file at position 0 ")); 
  }
  else
  {
    USB.println(F("\n1 - Write failed"));  
  }
  
  // show file
  SD.showFile(filename);
  delay(1000);
  

  
  // 2 - It writes “goodbye” in file at position 5
  // 2 - 위치 5의 파일에 "goodbye"를 씁니다.
  sd_answer = SD.writeSD(filename,"goodbye", 5);
  
  if( sd_answer == 1 ) 
  {
    USB.println(F("\n2 - Write \"goodbye\" in file at position 5"));
  }
  else
  { 
    USB.println(F("\n2 - Write failed")); 
  }
  
  // show file
  // 파일 보이기
  SD.showFile(filename);
  delay(1000);



  // 3 - It writes “hel” in file at position 10 indicating 3-byte length
  // 3 - 바이트 길이를 나타내는 위치 10의 파일에 "hel"을 씁니다.
  sd_answer = SD.writeSD(filename,"hello", 10, 3);
  
  if( sd_answer == 1 ) 
  {
    USB.println(F("\n3 - Write \"hel\" in file at position 10 indicating 3-byte length"));
  }
  else
  {
    USB.println(F("\n3 - Write failed"));   
  }
 
   // show file
  SD.showFile(filename);
  delay(1000);
   
   
   
  // 4 - It writes hexadecimal data indicating the length to write
  // 4 - 쓸 길이를 나타내는 16 진수 데이터를 씁니다.
  sd_answer = SD.writeSD(filename, data, 0, 3);
  
  if( sd_answer == 1 ) 
  {
    USB.println(F("\n4 - Write hexadecimal data indicating 3 bytes to be written (offset=0)"));
  }
  else
  {
    USB.println(F("\n4 - Write failed"));  
  }
  
  // show file
  // 파일 보이기
  SD.showFile(filename);
  delay(1000);
   
   
   
  // 5 - It writes hexadecimal data
  // End of data array is defined by 0xAAAA
  // 5 - 16 진수 데이터를 씁니다.
  // 데이터 배열의 끝은 0xAAAA에 의해 정의됩니다.
  sd_answer = SD.writeSD(filename, data, 0);
  
  if( sd_answer == 1 )
  {
    USB.println("\n5 - Write array of bytes (offset=0). End of 'data' array is defined by 0xAAAA");
  }
  else
  {
    USB.println("\n5 - Write failed");
  }

  // show file
  SD.showFile(filename);   
  USB.println(F("\n***************************"));
  delay(10000);
}

결과

SD 03: Append data

SD 04: Read file

SD 05: Create/delete directories

SD 06: List files

필요사항

1 x Waspmote

1 x Battery

1 x SD card

1 x MiniUSB wire

노트

  • 파일과 디렉토리에는 8.3 SHORT FILE NAME 만 유효하다는 것을 기억하십시오
  • SD 카드를 넣거나 빼기 전에 Waspmote가 꺼져 있는지 확인하십시오. 그렇지 않으면 SD 카드가 손상 될 수 있습니다.
  • SD 카드에 진행중인 읽기 또는 쓰기 작업이있는 동안에는 Waspmote를 끄거나 재설정하지 말아야합니다. 그렇지 않으면 SD 카드가 손상되어 데이터가 손실 될 수 있습니다. 진행중인 SD 작업이있을 수 있다고 생각되면 작업이 완료 될 때까지 잠시 기다리십시오.
  • 이 예제는 Waspmote v12와 Waspmote v15에서 실행할 수 있습니다.

코드

/*  
 *  ------ [SD_06] - List files inside the SD card -------- 
 *  
 *  Explanation: Turn on the SD card. Firstly, delete all folder and
 *  all contained files. Secondly, create all directories specified in
 *  path. Finally, create files inside each subfolder and show the created 
 *  directories and files. 
 *  The rest of the program shows how to list the directories in several ways.
 * (설명 : SD 카드를 켭니다. 첫째, 모든 폴더와 모든 포함 된 파일을 삭제하십시오.
 * 둘째, path에 지정된 모든 디렉토리를 만듭니다. 마지막으로 각 하위 폴더에 파일을 만들고 생성 된 디렉토리와 파일을 표시합니다.
 * 프로그램의 나머지 부분에서는 여러 가지 방법으로 디렉토리를 나열하는 방법을 보여줍니다.)
 *  
 *  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 <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           3.0
 *  Design:            David Gascón 
 *  Implementation:    Yuri Carmona
 */


// Define folder path
// All directory names MUST be defined 
// according to 8.3 SHORT FILE NAME
// (폴더 경로 정의
// 8.3 SHORT FILE NAME에 따라 모든 디렉토리 이름을 정의해야합니다.)
char path[]="FOLDER1/FOLDER2/FOLDER3/";

// define variable(변수 정의)
uint8_t sd_answer;


void setup()
{
  // open USB port(USB Port 연결)
  USB.ON();
  USB.println(F("SD_06 example"));
 
  ///////////////////////////////////////////
  // 1. Set SD ON(SD 카드 셋팅)
  ///////////////////////////////////////////
  SD.ON();
  
  ///////////////////////////////////////////
  // 2. delete all directories at the beginning of execution(실행 시작시 모든 디렉토리 삭제)
  ///////////////////////////////////////////
  sd_answer = SD.rmRfDir("FOLDER1");
  
  if( sd_answer == 1 )
  { 
    USB.println(F("deleted folders and all contained files"));
  }
  else
  {
    USB.println(F("rmdir failed"));
  }
  
  ///////////////////////////////////////////  
  // 3. create directories(디렉토리 생성)
  ///////////////////////////////////////////  
  sd_answer = SD.mkdir(path);  
  
  if( sd_answer == 1 )
  {
    USB.println(F("/FOLDER1/FOLDER2/FOLDER3/ created"));
  }
  else 
  {
    USB.println(F("path NOT created"));
  }
    
  ///////////////////////////////////////////    
  // 4. create a file inside FOLDER1/ (FOLDER1 경로 안에 파일 생성)
  ///////////////////////////////////////////  
  sd_answer = SD.create("FOLDER1/file1");
  
  if( sd_answer == 1 )
  {
    USB.println(F("/FOLDER1/file1 created"));
  }
  else
  {
    USB.println(F("/FOLDER1/file1 not created"));
  }
    
  ///////////////////////////////////////////    
  // 5. create a file inside FOLDER1/FOLDER2/ (FOLDER1/FOLDER2 경로 안에 파일 생성)
  ///////////////////////////////////////////  
  sd_answer = SD.create("FOLDER1/FOLDER2/file2");
  
  if( sd_answer == 1 )
  {
    USB.println(F("/FOLDER1/FOLDER2/file2 created"));
  }
  else 
  {
    USB.println(F("/FOLDER1/FOLDER2/file2 not created"));
  }
    
  ///////////////////////////////////////////    
  // 6. create a file inside FOLDER1/FOLDER2/FOLDER3 (FOLDER1/FOLDER2/FOLDER3 경로 안에 파일 생성)
  ///////////////////////////////////////////  
  sd_answer = SD.create("FOLDER1/FOLDER2/FOLDER3/file3");
  
  if( sd_answer == 1 )
  {
    USB.println(F("/FOLDER1/FOLDER2/FOLDER3/file3 created"));
  }
  else 
  {
    USB.println(F("/FOLDER1/FOLDER2/FOLDER3/file3 not created"));
  }
     
}


void loop()
{     
  ////////////////////////////////////////////////////////  
  // 7 - list root directory: file size details by default(루트 디렉토리 목록 : 기본적으로 파일 크기 세부 정보)
  ////////////////////////////////////////////////////////
  USB.println(F("\n---------------------------"));
  USB.println(F("list (file size details by default):"));
  USB.println(F("---------------------------"));
  SD.ls();  
  USB.println(F("---------------------------"));
  
  delay(1000);
  
  ////////////////////////////////////////////////////////  
  // 8 - list root directory recursively(재귀적으로 루트 디렉토리를 나열하십시오.)
  ////////////////////////////////////////////////////////
  USB.println(F("\n---------------------------"));
  USB.println(F("list recursively:"));
  USB.println(F("---------------------------"));
  SD.ls( LS_R );  
  USB.println(F("---------------------------"));  
  
  delay(1000);  
  
  ////////////////////////////////////////////////////////
  // 9 - list root directory recursively showing file size(재귀적으로 파일 크기를 표시하는 루트 디렉토리 나열)
  ////////////////////////////////////////////////////////
  USB.println(F("\n---------------------------"));
  USB.println(F("list recursively showing file size:"));
  USB.println(F("---------------------------"));
  SD.ls( LS_R | LS_SIZE );  
  USB.println(F("---------------------------"));
    
  delay(1000);  
  
  ////////////////////////////////////////////////////////  
  // 10 - list root directory recursively showing date and file size(날짜와 파일 크기를 재귀 적으로 보여주는 루트 디렉토리 목록 표시)
  ////////////////////////////////////////////////////////
  USB.println(F("\n---------------------------"));
  USB.println(F("list recursively showing date and file size:"));
  USB.println(F("---------------------------"));
  SD.ls( LS_R | LS_DATE | LS_SIZE );   
  USB.println(F("---------------------------"));
  
  
  delay(5000);
}

결과

SD 07: Datalogger

SD 08: Change directories

SD 09: IndexOf pattern

SD 10: Write binary data

SD 12: Format SD

SD 13: SD card menu 


'IT > IoT' 카테고리의 다른 글

Waspmote 802.15.4  (0) 2017.12.28
Waspmote ZigBee Networking Guide  (0) 2017.12.28
Waspmote PRO v1.2 실습  (0) 2017.12.28
Waspmote event-sensor-board 2.0  (0) 2017.12.28
Waspmote Quickstart Guide  (0) 2017.12.28