Seeeduino LoRaWAN with the SD Card Shield

Hi Philipp



It works. I use the data logger code as below. thanks.

[code]#include <SPI.h>
#include <SD.h>

const int chipSelect = 4;

void setup() {
// Open SerialUSB communications and wait for port to open:
SerialUSB.begin(9600);
while (!SerialUSB) {
; // wait for SerialUSB port to connect. Needed for native USB port only
}

SerialUSB.print(“Initializing SD card…”);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
SerialUSB.println(“Card failed, or not present”);
// don’t do anything more:
while (1);
}
SerialUSB.println(“card initialized.”);
}

void loop() {
// make a string for assembling the data to log:
String dataString = “”;

// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += “,”;
}
}

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open(“datalog.txt”, FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the SerialUSB port too:
SerialUSB.println(dataString);
}
// if the file isn’t open, pop up an error:
else {
SerialUSB.println(“error opening datalog.txt”);
}
}

[/code]


Here is the COM port output.

</s>Initializing SD card...card initialized. 744,551,543 567,372,329 743,710,752 424,216,189 693,594,551 341,149,135 489,368,350 625,636,722 382,221,198 735,714,711 323,207,269 <e>