Digispark as an input device

Hello everyone

many of you will remember the post: screenshots with Digispark at the touch of a button. However, since we regularly receive requests for the use of the Digispark in support, a newer version of the Digispark definitions is available and the code used is beginner-friendly, but for practice I would like to introduce you today to the improved rework of a blogger:


Hardware used:

The 1 Euro digispark board, which can be programmed under the Arduino IDE, and a button to trigger the screenshot are used.

The Digispark board consists essentially of an attiny85 MCU from its 6 digital outputs 2 digital pins simulate a USB port via the bootloader software. The USB protocol is completely mapped in the software.

The digital ports therefore require 2 ports (ports 4 and 3) for the USB interface for programming and when using the USB interface in the user program.

Thus, only 4 ports remain usable for your own application. In our project, we use port 0 for the button.

Figure: Complete setup, no external power supply is necessary anymore.


The button is switched as a contact between the labeled connections of the Digispark GND and port 0. The normally necessary pull-up reticle can be omitted, as we use an internal switchable pullup stand of the attiny. This will be activated later in the software.

IDE Preparations:

In order to be able to program our Digispark using the Arduino IDE, some preparatory work has to be done, as the board is not natively supported by the DIE or can be programmed.

First of all, the ArduinoIDE itself must be installed in the latest version.

In the started IDE under File > Preferences > Additional Board Administrator URLS please carry the URL:


A. The location is marked in yellow.

With this step, the Digistump resources in the board manager will be selectable later.

Now starts the board manager via Tools > Board > Boar Manager and selects "Contributed" as the type.

Select the entry "Digistump AVR Boards by Digistump" with the mouse from the list and click on the "Install" button.

The tools and tools are downloaded and installed.

Now checks whether the package has been installed correctly. This can be seen in the turquoise lettering "INSTALLED". Make sure that at least version 1.6.7 has been installed.

Installing the USB drivers for the Digispark:

Load on the page: https://github.com/digistump/digiStumparduino/releases the file Digistump.Drivers.zip and unpacks it in the folder "Digistump Drivers" Runs the file DPinst64.exe (Windows 64 Bit) or DPinst.exe (Windows 32 Bit).

During installation, please confirm the query.

During installation, please confirm the query.

Only now is the Digispark connected to the computer for the first time. To do this, open the device manager, connect the Digispark to a free USB interface and check whether the Digispark is correctly recognized as a Digispark bootloader under "libusb-win32 devices".

After restarting the Arduino IDE under Tools > Board > Board Select Digispark Default 16.5 mhz.

Here is the code:


Digispark code to take a screenshot by pushbutton to P0.
Tested on Windows 10 Version 1803

#include "DigiKeyboard.h"
#define KEY_Print 0x46 

Const Byte SwitchPin = 0;             Pinnumber (P0) is defined as a constant to optimize disk space.
Const Byte BuildInLed = 1;            Buildin LED
Byte SwitchBufferState = High;           Declaration MemoryVariable for key status

Void Setup() 
{   pinMode(SwitchPin, INPUT_PULLUP);   Pin 0 of the DigiSpark is defined on digital input with internal pullup.   digitalWrite (BuildInLed,Low);      Turn off internal LED

Void Loop() 
{   If (digitalRead(SwitchPin)== Low  &&  SwitchBufferState == High)    {     digitalWrite (BuildInLed,High);  Turn on internal LED, screenshot is created     Delay(80);                       Debounce button 80 ms     SwitchBufferState = Low;     DigiKeyboard.sendKeyStroke(KEY_Print,MOD_GUI_LEFT);  Simulation of the key press to take the screenshot                                                                                                               (windows logo key + pushbutton)     DigiKeyboard.Delay(50);     }    If (digitalRead(SwitchPin)== High &&  SwitchBufferState == Low)    {     digitalWrite (BuildInLed,Low);   Turn off internal LED     Delay(80);                       Debounce button 80 ms     SwitchBufferState = High;    }   Delay(100);


Port 0 is activated as an input with internal pullup restilland and is therefore logically LOW active. (HIGH inactive) A button connects this port against GND when pressed. In the main loop loop, the logical state of port 0 is queried every 100 ms. If this switches to logical LOW through the button and was previously in the HIGH state then after a waiting time of 80 ms for key rent bruise via the USB interface the key combination Windows Logo and Print is sent to the PC. This causes the operating system to take a screenshot and place it in the screenshot order.

To prevent endless screenshots from being taken as long as the button is pressed, the marker variable "Switchbufferstate" is set to LOW to detect that the button is still pressed and has not been pressed again at the next loop pass. As long as the button is pressed, the internal LED of the Digispark lights up. As soon as the button is released, the internal LED goes off and the marker variable is reset.

After that, the system is back in its original state and a screenshot can be taken again by pressing the button.


Until the next post :) 


Projects for advanced




Bei mir hat das auch nicht funktioniert, es fehlt eine zusätzliche Kommandozeile um das Problem zu lösen. Als allererste Zeile in der Void Loop, vor dem ersten if, muss noch folgendes rein, dann läuft es:


Savas kuzu

Savas kuzu

Leider werden an meinem Laptop keines der 5 Digisparks erkannt. Habe alles genau so ausgeführt wie es hier drinnen steht. Sind die MC vielleicht alle defekt? Bitte um Hilfe.



Nun möchte ich mal einen Kommentar schreiben.
Und zwar habe ich eine Bitte. Ich finde eure Bastelarbeiten wirklich spannend und anregend, weiter so ! Aber beginnt bei euren Artikeln immer damit, was das Ziel ist und welche Funktionen (grob) damit möglich sind. Das gilt für alle Artikel von euch. Ich kann verstehen , dass ihr sofort mit der Anleitung zum Bauen anfangen wollt, aber für mich (als Semi-Bastler) ist nicht immer ersichtlich, was ihr bauen wollt.
Schöne Grüße

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN