Escribir CSV en una tarjeta SD
Añada lecturas a un archivo para analizarlas después.
Escribir CSV en una tarjeta SD es una lección gratuita de Arduino & IoT Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Arduino & IoT Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Arduino & IoT Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. ✅
Preguntas frecuentes
¿La lección «Escribir CSV en una tarjeta SD» es gratis?
Sí — el texto completo de «Escribir CSV en una tarjeta SD» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Arduino & IoT Academy, actualiza a CoddyKit PRO. El curso de Arduino & IoT Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Escribir CSV en una tarjeta SD»?
Añada lecturas a un archivo para analizarlas después. Practicas Arduino & IoT Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Arduino & IoT Academy?
No se requiere experiencia previa. Arduino & IoT Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.
¿Cuánto tiempo toma la lección «Escribir CSV en una tarjeta SD»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Arduino & IoT Academy?
Sí. Cada lección de Arduino & IoT Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Obtener la hora real con NTP/RTC
- Escribir CSV en una tarjeta SD
- Almacenar y agrupar cargas
- Visualizar datos registrados