Scrivere CSV su una scheda SD
Aggiunga le letture a un file per analizzarle in seguito.
Scrivere CSV su una scheda SD è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Arduino & IoT Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Why an SD Card?
An SD card gives your device cheap, roomy storage that survives power loss. It is perfect for keeping a long history of logged readings. 💾
Why CSV?
CSV means comma-separated values: plain text where each line is a record and commas split the fields. Spreadsheets open it instantly.
What a Row Looks Like
One log entry per line keeps things tidy. A row might pair a timestamp with a reading so each value has clear meaning later.
2026-06-25 14:03,24.7,55The SD Module
An SD card module connects over the SPI bus. You wire its MOSI, MISO, SCK, and CS pins to the matching pins on your board.
Starting the Card
Before reading or writing you must initialize the card and tell the library which pin is chip select. If it fails, the card or wiring is off.
if (!SD.begin(10)) { return; }Opening a File
You open a file by name, choosing a mode. Use FILE_WRITE to add data; it creates the file if it does not exist yet.
File f = SD.open("log.csv", FILE_WRITE);Appending, Not Overwriting
FILE_WRITE seeks to the end, so each new line is appended. Your old entries stay safe and the history keeps growing.
Writing a Line
You print fields and commas just like Serial output. End the row with println so the next entry starts on a fresh line.
f.print(temp);
f.print(",");
f.println(humidity);Always Close the File
Calling close() flushes your data and frees the file. Skip it and your last writes may never reach the card.
f.close();A Header Row
Write a header line once when the file is new, naming each column. Spreadsheets then label your charts automatically.
time,temp,humidityDon't Write Too Often
Each write costs power and time. For battery nodes, log every few seconds or minutes rather than every loop to keep the card happy.
Quick Check
What happens if you forget to close the file after writing?
Recap
Wire an SD module over SPI, open a CSV file in append mode, print comma-separated rows, and always close it. Now your readings are saved for good. ✅
Domande Frequenti
La lezione «Scrivere CSV su una scheda SD» è gratuita?
Sì — il testo completo di «Scrivere CSV su una scheda SD» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Arduino & IoT Academy, passa a CoddyKit PRO. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Cosa imparerò in «Scrivere CSV su una scheda SD»?
Aggiunga le letture a un file per analizzarle in seguito. Eserciti Arduino & IoT Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Arduino & IoT Academy?
Non è richiesta alcuna esperienza precedente. Arduino & IoT Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Scrivere CSV su una scheda SD»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Arduino & IoT Academy?
Sì. Ogni lezione Arduino & IoT Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Ottenere l'ora reale con NTP/RTC
- Scrivere CSV su una scheda SD
- Memorizzare e raggruppare i caricamenti
- Visualizzare i dati registrati