My LoRaWAN Signal Mapping MSc summer project. This is a copy of the actual repository with personal information removed.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.9 KiB

SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 9
LED on pin 5
This example code is in the public domain.
#include <SPI.h>
#include <SD.h>
#define PIN_SPI_DATA 9
File myFile;
void setup()
int i;
Serial.println("\r\nHobbytronics Test Program for SD card...");
Serial.println("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
if (!SD.begin(PIN_SPI_DATA)) {
Serial.println("initialization failed!");
Serial.println("initialization done.");
if (SD.exists("test.txt"))
myFile ="test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.println("Writing to test.txt...");
Serial.println("Hobbytronics Test");
for(i=0; i<20; i++)
myFile.println("Hobbytronics Test of file writing");
// close the file:
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
// re-open the file for reading:
Serial.println("\n\rReading from test.txt...");
myFile ="test.txt");
if (myFile) {
// read from the file until there's nothing else in it:
while (myFile.available()) {
// close the file:
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
Serial.println("Test Complete.");
void loop()
// nothing happens after setup