กลับไปหน้ารวมไฟล์
sd-sketch-update-259592-en.md

Standardizing Updates: The SDU Library

In many real-world scenarios, a finished project is enclosed in a chassis or deployed in a remote location where connecting a USB cable for a code update is impossible. The SD Sketch Update project introduces the SDU (Secure Digital Update) library, a powerful feature for SAMD-based boards (like the MKRZero and MKR1000). By including this library, your board can automatically detect and self-flash new firmware simply by having a file on an SD card.

The Self-Updating Mechanism

The SDU library adds a small "Pre-Boot" routine to your code. Here is how the logic works:

  1. Boot Detection: When the board is reset or powered on, the SDU routine executes before your main setup() function.
  2. The File Check: The board searches the root directory of the inserted SD card for a file named exactly UPDATE.bin.
  3. Automatic Overwrite: If a valid binary is found, the current image in the board's internal flash memory is overwritten with the new data. Once complete, the board reboots and starts running the new version of the code.

The "Export Binary" Workflow

To create an update file, you don't just upload the code like usual:

  • Binary Generation: Within the Arduino IDE, you must select Sketch -> Export compiled Binary. This generates a .bin file in your project folder.
  • Renaming for recognition: The generated file (which usually has a long name like Blink.ino.mkrzero.bin) must be renamed to UPDATE.bin for the SDU bootloader to recognize it.
  • Deployment: Simply drop this file onto a FAT32-formatted SD card, insert it into the MKRZero’s onboard slot, and press the Reset button.

Ideal Applications for SDU

This feature is a game-changer for several types of projects:

  • Field Sensors: Update environmental monitoring devices in the forest or field without carrying a laptop.
  • Enclosed Gadgets: Update the software on a handheld gaming device or smart lamp whose USB port is inaccessible.
  • Diagnostic Testing: Quickly swap between "Diagnostic Mode" and "Production Mode" sketches by changing the SD card.

This project represents a professional-tier development workflow, proving that Arduino is a capable platform for Scalable Firmware Management.

Note: This tutorial provides a seamless path to updating your SAMD boards. By simply including <SDU.h> in your sketch, you gain the ability to overwrite the firmware via SD card—turning your SD slot into a powerful deployment tool.

ข้อมูล Frontmatter ดั้งเดิม

title: "SD Sketch Update"
description: "A professional guide to enabling 'Over-the-Air Style' firmware updates via SD card for SAMD-based Arduino boards."
author: "Arduino_Genuino"
category: "Lab Stuff"
tags:
  - "bootloader"
  - "firmware-update"
  - "samd"
  - "mkr-series"
  - "sdu"
views: 10091
likes: 8
price: 1499
difficulty: "Easy"
components:
  - "1x Arduino MKRZero (or MKR1000)"
  - "1x MicroSD Card (formatted to FAT16/FAT32)"
  - "1x MKR SD Proto Shield (if using MKR1000/Fox1200)"
tools: []
apps:
  - "1x Arduino IDE"
  - "1x Arduino Web Editor"
downloadableFiles: []
documentationLinks:
  - "https://docs.arduino.cc/tutorials/projects/sd-sketch-update"
passwordHash: "eaff2e05db0df0fce7860a088c34a11d66ca3640fc06420c32de159b376c8914"
encryptedPayload: "U2FsdGVkX1/J79CQEij/zog3vX2CoESnrkyStmy5oITK6BfqPpHxY+X2qmNBsYfp46JcuICWmisFeBZz12jE5gRvk6rNW1lPnwF4hFp+MXkoM8UEkKdxzDytkB9aenzc"
seoDescription: "Enable SD-based firmware updates for Arduino SAMD boards. Learn how to use the SDU library to overwrite sketches automatically with an UPDATE.bin file."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/sd-sketch-update-259592_cover.jpg"
lang: "en"