Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.
Adafruit Data Logging: SD Cards, RTC & Adalogger Guide
Building a reliable data logger is one of those projects that sounds simple until you actually try it. You need persistent storage that survives power cycles, accurate timestamps that don’t drift, and hardware that works together without fighting over bus conflicts. After designing dozens of environmental monitoring systems and field data collection units, I’ve settled on Adafruit’s ecosystem as my go-to for data logger projects. Their Adalogger boards and RTC modules solve the hard problems so you can focus on what you’re actually trying to measure.
This guide covers everything you need to build robust logging systems using SD card storage, real-time clocks like the DS3231 and PCF8523, and various Adafruit logger hardware options.
Why Timestamps Matter for Data Logging
The Arduino IDE has a built-in function called millis() that counts milliseconds since power-on. CircuitPython has time.monotonic(). Both are fine for timing events within a single session, but they reset to zero every time you power cycle the board. If your data logger loses power at 2 AM and restarts, all your morning readings will have timestamps starting from zero instead of actual clock time.
That’s where a dedicated RTC (Real Time Clock) comes in. These chips have their own crystal oscillator, their own timekeeping circuit, and a coin cell battery backup. They keep ticking even when your microcontroller is completely powered off. When your data logger wakes up, it asks the RTC “what time is it?” and gets an accurate answer.
RTC vs millis() Comparison
Feature
millis()/time.monotonic()
External RTC Module
Resets on power loss
Yes
No (battery backup)
Knows calendar date
No
Yes
Accuracy over time
Depends on MCU crystal
±2 ppm to ±20 ppm
Cost
Free (built-in)
$5-15
Complexity
None
I2C wiring + library
Best for
Short-term timing
Long-term logging
Adafruit RTC Module Options: DS3231 vs PCF8523
Adafruit offers two main RTC chips across their product line. Understanding the differences helps you pick the right one for your application.
DS3231 Precision RTC
The DS3231 is Maxim’s flagship real-time clock, and it earns the “precision” label. Unlike cheaper RTCs that use external crystals, the DS3231 has a temperature-compensated crystal oscillator (TCXO) built directly into the chip. This matters because crystal frequency drifts with temperature—a regular 32.768kHz crystal might gain or lose several seconds per day as room temperature changes.
The DS3231 constantly measures its own temperature and adjusts its clock ticks to compensate. The result is accuracy within ±2 ppm from 0°C to 40°C, which translates to about ±1 minute per year. For scientific data collection or anything requiring precise correlation between readings, this accuracy is essential.
DS3231 Specifications
Parameter
Value
Accuracy
±2 ppm (0°C to +40°C)
Annual Drift
~1 minute/year
Interface
I2C (address 0x68)
Operating Voltage
2.3V – 5.5V
Backup Battery
CR1220 coin cell
Temperature Sensor
Built-in (±3°C accuracy)
Alarms
2 programmable alarms
Square Wave Output
1Hz, 4kHz, 8kHz, 32kHz
EEPROM
32KB (AT24C32 on module)
PCF8523 Real Time Clock
The PCF8523 takes a different approach—it’s simple, inexpensive, and good enough for most applications. Adafruit uses the PCF8523 on the Adalogger FeatherWing because it keeps costs down while still providing reliable timekeeping.
The tradeoff is accuracy. The PCF8523 may lose or gain up to 2 seconds per day, which adds up to about 12 minutes per month in the worst case. For many logging applications—environmental monitoring, plant watering systems, home automation—this level of drift is perfectly acceptable. You’re not launching satellites; you just need to know roughly when your basement flooded.
PCF8523 Specifications
Parameter
Value
Accuracy
±20 ppm typical
Daily Drift
Up to ±2 seconds/day
Interface
I2C (address 0x68)
Operating Voltage
1.8V – 5.5V
Backup Battery
CR1220 coin cell
Alarms
1 programmable alarm
Timer
Countdown timer available
Low Power
Excellent for battery projects
DS3231 vs PCF8523 Quick Reference
Feature
DS3231
PCF8523
Price
~$13
~$5
Accuracy
±2 ppm
±20 ppm
Temperature Compensation
Yes (TCXO)
No
Annual Drift
~1 minute
~12 minutes
Temperature Sensor
Yes
No
Alarms
2
1
Best Use Case
Scientific logging
General logging
Power Consumption
Higher
Lower
Adafruit Adalogger Hardware Options
The term “Adalogger” covers several products in Adafruit’s lineup, all designed around data logging applications.
Adalogger FeatherWing
The Adalogger FeatherWing is a stackable add-on board that works with any Feather-format microcontroller. It combines a PCF8523 RTC with a micro SD card socket, giving you timestamps and storage in one compact package. The FeatherWing connects via I2C for the clock and SPI for the SD card, leaving most of your Feather’s GPIO pins free for sensors.
Adalogger FeatherWing Specifications
Feature
Specification
RTC Chip
PCF8523
Storage
MicroSD socket (SPI)
Interface
I2C (RTC) + SPI (SD)
SD CS Pin
GPIO 10 (M0/M4/32u4), GPIO 15 (ESP8266)
Battery Backup
CR1220 holder
Compatible Feathers
All (32u4, M0, M4, ESP8266, ESP32, nRF52, RP2040)
Dimensions
22.8mm x 50.8mm
Feather M0 Adalogger
For projects where you want everything on one board, the Feather M0 Adalogger integrates a SAMD21 Cortex M0+ processor with a micro SD card socket. There’s no onboard RTC, so you’ll add an external module if you need timestamps. The advantage is simplicity—one board, one USB connection, built-in LiPo charging.
Feather RP2040 Adalogger
The newest member of the Adalogger family uses the RP2040 chip (same as Raspberry Pi Pico) with 8MB flash, 264KB RAM, and a micro SD card socket wired for both SPI and optional 4-bit SDIO. The STEMMA QT connector makes adding I2C sensors and RTC modules plug-and-play.
Adalogger Board Comparison
Board
Processor
Flash
RAM
SD Card
Built-in RTC
Price
Adalogger FeatherWing
N/A (add-on)
N/A
N/A
MicroSD
PCF8523
~$9
Feather 32u4 Adalogger
ATmega32u4
32KB
2.5KB
MicroSD
No
~$20
Feather M0 Adalogger
SAMD21
256KB
32KB
MicroSD
No
~$20
Feather RP2040 Adalogger
RP2040
8MB
264KB
MicroSD
No
~$14
SD Card Setup and Formatting
The SD card is where your logged data actually lives. Getting the card properly formatted prevents frustrating debugging sessions later.
Filesystem Requirements
Arduino’s SD library supports FAT16 and FAT32 filesystems. FAT12 (found on very old, small cards) and exFAT (used on 64GB+ cards) are not supported by most embedded libraries. Stick with cards between 2GB and 32GB formatted as FAT32 for best compatibility.
SD Card Formatting Guide
Card Size
Recommended Format
Notes
< 2GB
FAT16
Rarely found new
2GB – 32GB
FAT32
Best compatibility
32GB – 64GB
FAT32 (force format)
May ship as exFAT
> 64GB
Not recommended
exFAT not supported
Always use the official SD Card Formatter from sdcard.org rather than your operating system’s built-in formatter. The official tool follows the SD specification exactly, avoiding subtle issues that cause initialization failures.
SD Card Filename Limitations
The Arduino SD library uses the 8.3 filename format inherited from MS-DOS. Filenames must be 8 characters or fewer, with a 3-character extension. Valid examples include DATA0001.TXT, LOG.CSV, and TEMP.DAT. Invalid names like MyLongFileName.data or 2024-01-15.log will fail silently or cause corruption.
Wiring the Adalogger FeatherWing
The Adalogger FeatherWing stacks directly onto any Feather board using standard headers. The critical connections happen automatically through the header pins:
Adalogger FeatherWing Pin Connections
Function
Pin (Most Feathers)
Pin (ESP8266)
Pin (ESP32)
SD Card CS
GPIO 10
GPIO 15
GPIO 33
SD Card MOSI
MOSI
MOSI
MOSI
SD Card MISO
MISO
MISO
MISO
SD Card SCK
SCK
SCK
SCK
RTC SDA
SDA
SDA
SDA
RTC SCL
SCL
SCL
SCL
If your project requires a different CS pin, you can cut the trace on the back of the FeatherWing and solder a jumper to your preferred GPIO.
Arduino Code for Data Logging
Here’s a complete example that reads an analog sensor, timestamps the reading with the RTC, and logs everything to the SD card:
cpp
#include <SPI.h>#include <SD.h>#include <Wire.h>#include “RTClib.h”// Pin definitions – adjust for your Feather#define SD_CS 10#define SENSOR_PIN A0#define LED_PIN 13RTC_PCF8523 rtc;File logFile;void setup() { Serial.begin(115200); pinMode(LED_PIN, OUTPUT); // Initialize RTC if (!rtc.begin()) { Serial.println(“RTC not found!”); while (1) { digitalWrite(LED_PIN, !digitalRead(LED_PIN)); delay(100); } } // Set RTC time if needed (only runs once after battery change) if (!rtc.initialized() || rtc.lostPower()) { rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); } // Initialize SD card if (!SD.begin(SD_CS)) { Serial.println(“SD card failed!”); while (1) { digitalWrite(LED_PIN, !digitalRead(LED_PIN)); delay(200); } } Serial.println(“Data logger ready”);}void loop() { DateTime now = rtc.now(); int sensorValue = analogRead(SENSOR_PIN); // Open file for appending logFile = SD.open(“DATALOG.CSV”, FILE_WRITE); if (logFile) { // Write timestamp logFile.print(now.year()); logFile.print(“-“); logFile.print(now.month()); logFile.print(“-“); logFile.print(now.day()); logFile.print(“,”); logFile.print(now.hour()); logFile.print(“:”); logFile.print(now.minute()); logFile.print(“:”); logFile.print(now.second()); logFile.print(“,”); // Write sensor data logFile.println(sensorValue); logFile.close(); digitalWrite(LED_PIN, HIGH); delay(50); digitalWrite(LED_PIN, LOW); } delay(1000); // Log every second}
Power Consumption and Battery Life
For portable data logger deployments, power consumption determines how long your batteries last. The SD card is actually the biggest power hog—it draws 30-100mA during writes and 200µA+ even when idle. The RTC modules draw microamps.
Power Optimization Tips
Component
Active Current
Sleep Current
Optimization
SD Card Write
30-100mA
200µA
Buffer data, write in batches
PCF8523 RTC
1.5µA
0.4µA
Already very low
DS3231 RTC
200µA
3µA
Use battery backup mode
Feather M0
10mA
6µA
Use deep sleep between logs
To extend battery life, avoid calling logFile.flush() after every write. The library automatically flushes data every 512 bytes. Forcing immediate flushes triples power consumption (from ~10mA average to ~30mA) for no real benefit in most applications.
Troubleshooting Common Issues
SD Card Not Detected
Check these items in order: (1) Card is FAT16 or FAT32 formatted, (2) CS pin matches your code, (3) Card is fully inserted, (4) Try a different card (some are incompatible). Cheap cards from unknown brands fail more often than name-brand cards.
RTC Shows Wrong Time
If the RTC loses time after power cycling, the backup battery is dead or missing. Both the DS3231 and PCF8523 require a CR1220 coin cell for backup. A missing battery doesn’t just lose time—it can cause the chip to hang or return garbage data.
Data Corruption
Never remove the SD card while the logger is running. Always close files after writing (logFile.close()) to ensure data is flushed from buffers. If you need to remove the card, add a button that triggers a safe shutdown sequence.
What size SD card works best with Arduino data loggers?
For most data logger projects, an 8GB or 16GB FAT32-formatted micro SD card offers the best balance. Larger cards (32GB+) work but may require force-formatting to FAT32 since they often ship as exFAT. Cards under 2GB are increasingly rare and may be formatted FAT12, which isn’t supported. Quality matters more than size—stick with name-brand cards from SanDisk, Samsung, or Kingston to avoid fake or unreliable media.
Can I use the DS3231 and PCF8523 interchangeably in my code?
Yes, Adafruit’s RTClib library supports both chips with nearly identical code. Just change RTC_PCF8523 rtc; to RTC_DS3231 rtc; in your declarations. Both use I2C address 0x68, so you cannot use both simultaneously on the same I2C bus. The main code differences involve the DS3231‘s extra features like temperature reading (rtc.getTemperature()) and dual alarms, which the PCF8523 doesn’t support.
How long will the RTC backup battery last?
A CR1220 coin cell typically powers an RTC backup for 3-5 years, depending on the chip. The PCF8523 draws about 0.4µA in backup mode, while the DS3231 draws around 3µA. At these currents, even a small 40mAh coin cell lasts years. Replace the battery proactively during annual maintenance rather than waiting for the clock to lose time.
Why does my data logger skip timestamps or show gaps?
Gaps usually indicate the SD card write took longer than expected, causing your logging loop to miss cycles. SD card write times are unpredictable—usually fast, but occasionally the card performs internal housekeeping that blocks for hundreds of milliseconds. Solutions include using interrupt-driven timing instead of delay(), buffering multiple readings before writing, or accepting occasional timing jitter as normal behavior.
Can I read and write to the SD card simultaneously from different files?
The standard Arduino SD library supports only one open file at a time. Opening a second file automatically closes the first. If your application needs to read configuration from one file while logging to another, read the configuration completely and close it before opening the log file. For more advanced file handling, consider the SdFat library, which supports multiple simultaneous file handles.
Building Your Data Logger
The combination of Adafruit’s Adalogger hardware, a precision DS3231 or cost-effective PCF8523 RTC, and a properly formatted SD card creates a data logger that just works. The ecosystem is well-documented, the libraries are mature, and the community has solved most problems you’ll encounter.
Start with the Adalogger FeatherWing stacked on whatever Feather matches your connectivity needs—ESP32 for WiFi, nRF52840 for Bluetooth, or M0/RP2040 for pure logging. Add sensors via I2C or analog inputs, deploy with a LiPo battery, and let it collect data. When you’re ready, pop out the SD card and your timestamped CSV files are ready for analysis in Excel, Python, or whatever tool you prefer.
The best data logger is one that runs unattended for months without intervention. Adafruit’s hardware, combined with careful attention to power management and SD card handling, delivers exactly that reliability.
Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.