5
By Nevio Lombardi Collaudo SD Card Module con Arduino Uno http://arduino.cc/en/Tutorial/ReadWrite /* 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 ** SCK - pin 13 ** CS - pin 4 created Nov 2010 by David A. Mellis modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. */ #include <SD.h> File myFile; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }

Collaudo SD Card Module con Arduino Uno - Altervistagiardinoitt.altervista.org/wp-content/uploads/2015/01/Collaudo-SD-Card... · By Nevio Lombardi Collaudo SD Card Module con Arduino

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

By Nevio Lombardi

Collaudo SD Card Module con Arduino Uno http://arduino.cc/en/Tutorial/ReadWrite /* 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 ** SCK - pin 13 ** CS - pin 4 created Nov 2010 by David A. Mellis modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. */ #include <SD.h> File myFile; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }

By Nevio Lombardi

Serial.print("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. pinMode(10, OUTPUT); if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open("test.txt", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); myFile.println("Prove di scrittura su file di testo"); // close the file: myFile.close(); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } // re-open the file for reading: myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:"); // read from the file until there's nothing else in it: while (myFile.available()) { Serial.write(myFile.read()); } // close the file: myFile.close(); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } } void loop() { // nothing happens after setup }

By Nevio Lombardi

Prove (al volo) GPS Data Logger utilizzando i sorgenti presi dai rispettivi link http://arduino.cc/en/Tutorial/ReadWrite https://www.sparkfun.com/tutorials/173 /* SD card 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 ** SCK - pin 13 ** CS - pin 4 */ #include <SoftwareSerial.h> #include <TinyGPS.h> #include <SD.h> File myFile; TinyGPS gps; SoftwareSerial serialgps(2,3); int year;

By Nevio Lombardi

byte month, day, hour, minute, second, hundredths; unsigned long chars; unsigned short sentences, failed_checksum; void setup() { Serial.begin(9600); serialgps.begin(4800); Serial.println(""); Serial.println("GPS Shield QuickStart Example Sketch v12"); Serial.println(" ...waiting for lock... "); Serial.println(""); Serial.print("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. pinMode(10, OUTPUT); if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); } void loop() { while(serialgps.available()) { int c = serialgps.read(); if(gps.encode(c)) { // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open("test.txt", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); myFile.println("Prove di scrittura su file di testo"); float latitude, longitude;

By Nevio Lombardi

gps.f_get_position(&latitude, &longitude); Serial.print("Lat/Long: "); myFile.print("Lat/Long: "); Serial.print(latitude,5); myFile.print(latitude,5); Serial.print(", "); myFile.print(", "); Serial.println(longitude,5); myFile.println(longitude,5); gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths); Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/"); myFile.print("Date: "); myFile.print(month, DEC); myFile.print("/"); Serial.print(day, DEC); Serial.print("/"); Serial.print(year); myFile.print(day, DEC); myFile.print("/"); myFile.print(year); Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":"); myFile.print(" Time: "); myFile.print(hour, DEC); myFile.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); myFile.print(minute, DEC); myFile.print(":"); myFile.print(second, DEC); Serial.print("."); Serial.println(hundredths, DEC); myFile.print("."); myFile.println(hundredths, DEC); Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude()); myFile.print("Altitude (meters): "); myFile.println(gps.f_altitude()); Serial.print("Course (degrees): "); Serial.println(gps.f_course()); myFile.print("Course (degrees): "); myFile.println(gps.f_course()); Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph()); myFile.print("Speed(kmph): "); myFile.println(gps.f_speed_kmph()); Serial.print("Satellites: "); Serial.println(gps.satellites()); myFile.print("Satellites: "); myFile.println(gps.satellites()); Serial.println(); myFile.println(); gps.stats(&chars, &sentences, &failed_checksum); // close the file: myFile.close(); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } } } }