Blinking a DigiSpark without Arduino IDE

Arduino IDE is great, however, some times I enjoy a simple C program and a simple Makefile. Here is a simple application skeleton allowing to blink a LED of course.

All information and files below are freely inspired from the following readings :

Requirements :

  • AVR gcc (Already installed if you have installed Arduino IDE from packages)
    sudo apt-get install gcc-avr

Source code :

#include <avr/io.h>
#include <util/delay.h>

// Digispark Internal LED
#define PIN_LED     PB1
#define DELAY_MS    500

int main(void) {
  // Init LED pin as output
  DDRB |= (1 << PIN_LED);
  // Light up LED
  PORTB |= (1 << PIN_LED);
  // Blink !
  for (;;) {
    PORTB ^= (1 << PIN_LED);

  return 0;


DEVICE     = attiny85           # See avr-help for all possible devices
CLOCK      = 16000000           # 16Mhz
OBJECTS    = main.o             # Add more objects for each .c file here

UPLOAD = micronucleus --run
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:	main.hex

	$(COMPILE) -c $< -o $@

flash:	all
	$(UPLOAD) main.hex

	rm -f main.hex main.elf $(OBJECTS)

main.elf: $(OBJECTS)
	$(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
	rm -f main.hex
	avr-objcopy -j .text -j .data -O ihex main.elf main.hex
	avr-size --format=avr --mcu=$(DEVICE) main.elf


One Reply to “Blinking a DigiSpark without Arduino IDE”

  1. Awesome, thanks 🙂
    One thing to add: your dependency install should read “sudo apt-get install gcc-avr avr-libc” for the example to compile successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *