Digispark Programming

Estimated difficulty: πŸ’œπŸ’œπŸ’œπŸ€πŸ€

Welcome to the Beginners guide to Digispark programming! Hardware can be a bit of a mystery, so in terms of understanding it, it is best to start small and complete some fun projects along the way. This article will answer some basic questions, like how to set up your programming environment; where to get a Digispark and some coding examples to start you off.

What is a Digispark?

The Digispark is a USB Development board using an ATtiny85 microcontroller. Developed as Open Source hardware for you to make changes to and utilise for a range of projects limited by your imagination!

Image 1
  • High Performance, Low power
  • RISC Architecture
  • Up to 8kb Flash memory
  • Includes debugWIRE for on-chip debugging (easy to resolve issues when flashing your code)
  • See Datasheet for more info.

Why use a Digispark

The Digispark is a cheaper option compared to the Arduino range of USB Development boards. Although it has smaller memory and is less powerful in comparison, you can buy these boards in bulk and they are great to practice or use for a home project!

There is plenty of documentation and resources available for new users to reference when working on a beginner project.

An alternative to this device is the Arduino Uno.

Where do I get a Digispark?

Personally I bought my first Digispark off of Amazon. Upon purchase, I made sure to use the ATtiny85 based microcontroller development board. However, it is worth investing in the board from the intended website: digistump.com.

As a disclaimer, from experience when investing in these boards not all of them will be programmable, these products can arrive faulty. Occasionally this can be amended by flashing empty code and re-programming the board, or searching for the error code shown on the IDE, but sometimes nothing can be done. If this is the case then it is best to speak to the vendor you purchased the device from.

How to set up your programming environment

There is already a lot of documentation on how to do this, however this is how I have set it up following these guides and some problems I have encountered and had to tackle.

Installation and Setup

Go to the Arduino site and install the appropriate software download for you. If you are running this on a Windows machine then installation should be as east as that! Open up the Arduino IDE for configuration and follow these steps:

  • We need to configure the preferences file. Go to file then preferences and a Window should pop up. Change the settings to look like the below screenshot.
  • Paste the following URL into Additional Boards Manager URLs, so the IDE can identify the Digispark in the boards manager: http://digistump.com/package_digistump_index.json​
  • Navigate to the Boards Manager through Tools > Board > Boards Manager and in the search bar type Digispark
  • Click install on the Digistump AVR Boards option. This will allow you to search for the correct Digispark board to program.
  • Go to boards and select – DigiSpark Default (16.5mhz)
  • Navigate to Tools and for the programmer you are going to want to select – Micronuncleus. The microcontroller for the Digispark uses the micronucleus programmer, as it uses the ATtiny85 bootloader.
  • Your Arduino IDE should now be set-up

Drivers

If you are running a Windows machine and running the latest version of the Arduino IDE you will need to update or install the drivers for the Digispark where necessary.

The Digispark may not appear under the name of Digispark in the Device Manager.

  • Go to device manager
  • Show hidden devices
  • Look for other/ unknown or libusb devices.
  • Update or install where necessary

If these steps do not work you can manually install the drivers following this guide.

Installation for Kali/ Linux

These installation steps were tested for Kali Linux machines, however may change for other Linux distributions.

  • Go to the downloads (wherever the Arduino IDE software downloaded) and extract the files
  • Navigate into the extracted folder and run the following commands:
sudo ./install.sh
sudo touch /etc/udev/rules.d/49-micronucleus.rules
  • Open the newly created file “49-micronucleus.rules” with your preferred text editor (I use nano!)
  • Paste in the following:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="0753", MODE:="0666"              


KERNEL=="ttyACM*", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="0753", MODE:="0666", ENV{ID_MM_DEVICE_IGNORE}="1" β€‹
  • Press Ctrl + O and press enter to write to the file (Save your work) then Ctrl + X to exit.
  • Finally to reload the udev rules run the below:
sudo udevadm control --reload-rules
  • Follow the steps in How to Program your Digispark and test.
  • If any issues occur then attempt to remove the changes made to the udev rules. If the problem persists then follow the steps in the documentation here.

The udev rules identify devices and assign a name to any events/ interactions that may occur with that device. For example, once a Digispark is connected to the machine it should be identified with a specific Product (idProduct) and Vendor (idVendor) id. If you are interested in learning more about how this works please drop a comment and I can work on a blog post for you! πŸ™‚

Programming your DigiSpark

When programming my Digispark, I wanted to create a low cost Bad USB. For this I only ever intended for my device to send Keystrokes to a mobile device to brute force a mobiles pin code. Most mobile devices accept input from a keyboard as the device accepts this as an accessibility feature. There are many different types of mobile devices: Android, IOS and Windows. Sending keystrokes to them may not work for all of them. When testing trying to unlock iPhone’s the results were inconclusive as to whether it would work as it sometimes did and sometimes didn’t. However on Android devices tested it did work to unlock phones. An improvement on this would be to use a board containing more memory to attempt to store password lists and pins for brute forcing other passwords.

There are many other reasons why you might want your Digispark to send keystrokes:

  • Save complex passwords (e.g. your master password for LastPass)
  • Play pranks on your friends by turning the screen upside down
  • Use as a bad USB by executing commands through CMD or PowerShell (Big up PowerShell!)

Other projects not relevant to sending keystrokes may include:

  • Try converting Rubber Ducky Scripts to code compatible to use for the Digispark.
  • Steal Wi-Fi passwords and get them emailed to you… Example code here. More projects along those lines here. Credit to CedArctic.
  • Do something cool with the LED functionality!

How to program your Digispark

There is a USB on your Digispark. To program this all you need to plug it into your computer like you would any other USB stick / flash drive when prompted by the Arduino IDE.

Troubleshooting

Issues may arise where the board is not detected by your computer. If this happens then ensure you have completed the below steps to debug the issue:

  • Use a USB hub. This will also reduce any damage that the Digispark might get when plugging it in and removing it from the USB ports.
  • Plug the Digispark into the PC/ laptop. By default most Digispark’s are pre-programmed to flash with a red light. If it is not flashing try to program that code (under the Blink Light code example of the Arduino IDE). If the light still does not flash this could be a faulty board.
  • Try a different port.
  • Ensure you have downloaded the correct drivers for the Digispark board. Check to make sure the drivers are compatible with your Operating System (e.g. Windows).
  • If all else fails follow the original documentation on how to connect your Digispark here.

Programming Example

For this example we are going to get the Digispark to write “Hello World!” to a notepad, to execute once the Digispark has been plugged into your device.

  • Run the Arduino IDE
  • Navigate to your File tab
  • Select Example
  • Click DigiSparkKeyboard and Keyboard. This will bring up some example code as shown below:
include "DigiKeyboard.h"

void setup() {
// don't need to set anything up to use DigiKeyboard
}

void loop() {
// this is generally not necessary but with some older systems it seems to
// prevent missing the first character after a delay:
DigiKeyboard.sendKeyStroke(0);
// Type out this string letter by letter on the computer (assumes US-style
// keyboard)

DigiKeyboard.println("Hello Digispark!");

// It's better to use DigiKeyboard.delay() over the regular Arduino delay()
// if doing keyboard stuff because it keeps talking to the computer to make
// sure the computer knows the keyboard is alive and connected

DigiKeyboard.delay(5000);
}
  • Change the text to say “Hello World!”, like the below:
include "DigiKeyboard.h"

void setup() {
// don't need to set anything up to use DigiKeyboard
}

void loop() {
// this is generally not necessary but with some older systems it seems to
// prevent missing the first character after a delay:

DigiKeyboard.sendKeyStroke(0);
// Type out this string letter by letter on the computer (assumes US-style
// keyboard)
DigiKeyboard.println("Hello World!");

// It's better to use DigiKeyboard.delay() over the regular Arduino delay()
// if doing keyboard stuff because it keeps talking to the computer to make
// sure the computer knows the keyboard is alive and connected

DigiKeyboard.delay(5000);
}
  • Verify the code by pressing the highlighted button.
  • Upload the code by pressing the highlighted button.
  • Connect the Digispark to a port or through the hub when prompted. The prompt will look like the below:
  • Remove the Digispark when it has successfully flashed.
  • Open a notebook on your PC/ Laptop and click inside the notepad.
  • Plugin the Digispark and watch it print out your text repeatedly.

Note: The code will repeat unless you include a break. We use a delay at the beginning to delay the code being executed too quickly as some letters may be missed.

Code Cheat Sheet

If you would like to find out more I have created a Repository in GitHub to contain all the codes for each keystroke on the keyboard. This code is subject to change and may not work for your devices as it did for mine.

I would like to continue to add any code I have created and use this repository as a live working example:

https://github.com/G1nGe98/DigisparkProgramming

DISCLAIMER: This post is intended for educational purposes only. Any information learnt here should not be put to use for illegal activities.

5 Comments

  1. Dan Conn

    Amazing! Thanks for sharing the knowledge!

  2. W-recker

    This is great, Very interested in hardware etc recently as just bought a mega 2560 R3. Thanks.

  3. Thanks for this, I was inspired to get a DigiSpark (or three) and put them to good use.
    https://github.com/CedArctic/DigiSpark-Scripts/tree/master/RickRoll_Update

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.