0Pricing
Arduino & IoT Academy · درس

كتابة CSV على بطاقة SD

أضف القراءات إلى ملف لتحليلها لاحقًا.

كتابة CSV على بطاقة SD درس مجاني في Arduino & IoT Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Arduino & IoT Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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,55

The 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,humidity

Don'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. ✅

الأسئلة الشائعة

هل درس «كتابة CSV على بطاقة SD» مجاني؟

نعم — نص درس «كتابة CSV على بطاقة SD» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Arduino & IoT Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Arduino & IoT Academy 4 دروس في المجموع.

ماذا ستتعلم في «كتابة CSV على بطاقة SD»؟

أضف القراءات إلى ملف لتحليلها لاحقًا. تتمرن على Arduino & IoT Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Arduino & IoT Academy؟

لا تُشترط خبرة سابقة. Arduino & IoT Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «كتابة CSV على بطاقة SD»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Arduino & IoT Academy هذا؟

نعم. كل درس في Arduino & IoT Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. الحصول على الوقت الحقيقي باستخدام NTP/RTC
  2. كتابة CSV على بطاقة SD
  3. تخزين الرفعات وتجميعها
  4. تصوير البيانات المسجّلة
← العودة إلى Arduino & IoT Academy