Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

arduino_sketches

> 编程语言
Open source

Publicly-released sketches for the Arduino microprocessor

684 stars0 likes0 views
WebsiteGitHub

About

Publicly-released sketches for the Arduino microprocessor

arduino_sketches

Publicly-released sketches for the Arduino microprocessor.

Update

As from 19th January 2015, the various sketches below "time out" if they don't enter programming mode after 50 attempts.

The code displays a dot for every attempt, so if it fails you will see something like this:

Attempting to enter programming mode ......................................................
Failed to enter programming mode. Double-check wiring!

(There are 53 dots because the initial message is "Attempting to enter programming mode ...").

Wiring

For all sketches except for:

  • Atmega_Hex_Uploader
  • Atmega_Self_Read_Signature
  • Atmega_Hex_Uploader_Fixed_Filename

... connect hardware SPI pins together as below:

  • MISO to MISO
  • MOSI to MOSI
  • SCK to SCK
  • Vcc to Vcc
  • Gnd to Gnd
  • Reset on target board to D10 on programming board

These pins are generally exposed on the ICSP header of most boards (except "breadboard" boards).

For "breadboard" boards you will need to read the datasheet for the appropriate chip to find which pins to use.

Atmega_Board_Detector

See forum post: http://www.gammon.com.au/forum/?id=11633

This uses one Arduino to detect the signature, fuses, and bootloader of another one.

Only some Arduinos are supported to run the sketch. It has been tested on a Uno, Mega2560 and Leonardo.

It sumchecks the bootloader so you can quickly see if a particular one is installed. Some bootloader sumchecks are known and the bootloader "name" reported if found.

Example of use:

…

Atmega_Fuse_Calculator

See forum post: http://www.gammon.com.au/forum/?id=11653

Only some Arduinos are supported to run the sketch. It has been tested on a Uno, Mega2560 and Leonardo.

Similar to the Atmega_Board_Detector sketch, this reads a target board's fuses, and displays which fuses are set in a nicer interface, for example:

External Reset Disable.................. [ ]
Debug Wire Enable....................... [ ]
Enable Serial (ICSP) Programming........ [X]
Watchdog Timer Always On................ [ ]
Preserve EEPROM through chip erase...... [ ]
Boot into bootloader.................... [X]
Divide clock by 8....................... [ ]
Clock output............................ [ ]

Atmega_Self_Read_Signature

See forum post: http://www.gammon.com.au/forum/?id=11633&reply=2#reply2

Similar to the Atmega_Board_Detector sketch this "self-detects" a signature, so an Arduino can report back its own fuses, and bootloader MD5 sum.

Example of use:


Signature detector.
Written by Nick Gammon.
Signature = 1E  95  0F
Fuses
Low = FF High = D6 Ext = FD Lock = CF

Processor = ATmega328P
Flash memory size = 32768
Bootloader in use: Yes
EEPROM preserved through erase: Yes
Watchdog timer always on: No
Bootloader is 512 bytes starting at 7E00

Note: Depending on the fuse settings, it may not be able to read the bootloader.

The Atmega_Self_Read_Signature sketch does not require any additional wiring.

Atmega_Board_Programmer

See forum post: http://www.gammon.com.au/forum/?id=11635

This will re-flash the bootloader in selected chips.

Only some Arduinos are supported to run the sketch. It has been tested on a Uno, Mega2560 and Leonardo.

Supported target chips are:

  • Atmega8 (1024 bytes)
  • Atmega168 Optiboot (512 bytes)
  • Atmega328 Optiboot (for Uno etc. at 16 MHz) (512 bytes)
  • Atmega328 (8 MHz) for Lilypad etc. (2048 bytes)
  • Atmega32U4 for Leonardo (4096 bytes)
  • Atmega1280 Optiboot (1024 bytes)
  • Atmega1284 Optiboot (1024 bytes)
  • Atmega2560 with fixes for watchdog timer problem (8192 bytes)
  • Atmega16U2 - the bootloader on the USB interface chip of the Uno

You can use that to install or update bootloaders on the above chips (using another Arduino as the programmer).

The bootloader code is built into the sketch, so it is self-contained (it does not require an SD card, PC or anything like that).

Example of use:

Atmega chip programmer.
Written by Nick Gammon.
Version 1.25
Compiled on Nov  4 2014 at 07:33:18
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xFF
HFuse = 0xDE
EFuse = 0xFD
Lock byte = 0xCF
Clock calibration = 0x8D
Bootloader address = 0x7E00
Bootloader length = 512 bytes.
Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ...

Atmega_Hex_Uploader

See forum post: http://www.gammon.com.au/forum/?id=11638

This lets you:

  • Verify flash memory
  • Read from flash and save to disk
  • Read from disk and flash a chip
  • Check fuses
  • Update fuses
  • Erase flash memory

Most operations (except changing fuses) require an external SD card, described in the forum post. You can easily connect one by obtaining a Micro SD "breakout" board for around $US 15.

The SD card uses the hardware SPI pins, and thus the programming of the target chip uses bit-banged SPI, which means that the connections to the board to be programmed differs from the above sketches.

Example of use:

Attempting to enter programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xFF
HFuse = 0xDE
EFuse = 0xFD
Lock byte = 0xCF
Clock calibration = 0x8D
Actions:
 [E] erase flash
 [F] modify fuses
 [L] list directory
 [R] read from flash (save to disk)
 [V] verify flash (compare to disk)
 [W] write to flash (read from disk)
Enter action:
Programming mode off.

Wiring for the Atmega_Hex_Uploader sketch:

Arduino    SD Card
--------------------------------
SS         CS (chip select)
MOSI       DI (data in)
MISO       DO (data out)
SCK        CLK (clock)
+5V        5V
Gnd        Gnd

Arduino    Target chip/board
-------------------------------------
D6         MISO
D7         MOSI
D4         SCK
D5         Reset
D9         Clock of target (if required)
+5V        5V
Gnd        Gnd

This sketch uses "bit banged" SPI for programming the target chip, which is why it uses pins D4, D5, D6, D7 instead of the hardware SPI pins.

Atmega_Hex_Uploader_Fixed_Filename

See forum post: http://www.gammon.com.au/forum/?id=11638&reply=5#reply5

This lets you read from disk and flash a chip, with a "fixed" filename (firmware.hex) and no serial port interface. Instead, three LEDs are used to display status, and flash to show errors.

It requires an external SD card, described in the forum post. You can easily connect one by obtaining a Micro SD "breakout" board for around $US 15.

The SD card uses the hardware SPI pins, and thus the programming of the target chip uses bit-banged SPI, which means that the connections to the board to be programmed differs from the above sketches (apart from Atmega_Hex_Uploader, which uses the same wiring).

Wiring for the Atmega_Hex_Uploader_Fixed_Filename sketch:

…

This sketch uses "bit banged" SPI for programming the target chip, which is why it uses pins D4, D5, D6, D7 instead of the hardware SPI pins.

See the source code (and above forum post) for details about the meanings of the different numbers of LED flashes.

High-voltage serial and parallel programming

As from 27th May 2015 the sketches Atmega_Hex_Uploader, Atmega_Board_Detector and Atmega_Board_Programmer also optionally support the high-voltage programming mode of various chips.

This is documented in some detail at http://www.gammon.com.au/forum/?id=12898

For connecting your Arduino Uno to an Atmega328 (or similar) chip this is the wiring:

…

###Reset circuitry###

For connecting your Arduino Uno to an ATtiny85 (or similar) chip this is the wiring:

Arduino    Target chip
-------------------------------------
  D3         8 (VCC)
  D4         5 (PB0)
  D5         6 (PB1)
  D6         7 (PB2)
  D7         2 (PB3)

 /RESET (pin 1) on target connected to 12V via a transistor and MOSFET as shown in the schematic.
 Also connect the ground. GND to pin 4.
 Decoupling capacitor: 0.1 µF (100 nF) between VCC (pin 8) and Gnd.
 Not connected on target: pin 3.

convertHexToByteArray.py

The convertHexToByteArray.py tool allows you to easily convert .hex files into a C array that you can use inside the Atmega_Board_Programmer code. It's an alternative to the Lua script and easier to setup in most cases.

To run the script you need python2 and the intelhex python library which can be downloaded here or via pip.

Example of use:

bash
python convertHexToByteArray.py ATmegaBOOT_168_atmega328_pro_8MHz.hex > bootloader_lilypad328.h

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言