Skip to main content

How to Get Digispark ATtiny85 Working

Digispark Attiny85 runs at 16.5MHz (with no external crystal) and has 5 I/O pins and connects to a USB port using a micro USB connector.
The breakout board comes with an ATtiny85 chip pre-programmed with the micronucleus bootloader.

The great thing about this bootloader is that it makes a software compatible USB interface inside the ATtiny85 - even when that chip has no USB interface. By adding support libraries into the Arduino IDE you can program this chip using the Ardino IDE system in a similar way to other Arduino microcontrollers.

The rest of this page shows you a Digispark tutorial for installing the Digispark drivers, checking that they are working correctly and programming the device.


Digispark ATtiny85 Bootloader Timeout

The way that the Digispark Attiny85 works is to use the Window Driver to identify the Digispark but this can only be done for 5 seconds. After the 5 seconds the bootloader becomes a dumb device and the program control is transferred to the program just loaded.

Arduino IDE 1.8.8 (Windows Store 1.8.19.0)

It has been successfully programmed using Arduino 1.8.8 (Windows Store 1.8.19.0). So a bug has been corrected since 1.8.7 (I think) did not work in that IDE.

Warning on digistump operation

The interface can be finicky - I had this system working, then worked on another project and came back to the Digispark ATtiny85. The window 10 machine that had worked perfectly came up with the dreaded popup:

Warning "USB Device not recognised."
I tried the following:

  • Re-installing Digistump drivers (clicking on DPinst64 - for a 64 bit machine).
  • In device manager Deleting USB entries that correspond to the ATtiny85 by Clicking the 'View' menu entry, then show hidden devices and uninstalling the driver for those labelled "Unknown USB Device (Device Descriptor Request Failed)".
  • Using zadig to install lib32-winusb on the unknown USB Device - no effect.
  • Uninstall Arduino IDE 1.8.5 and install a custom version of it (DigistumpArduinoInstall1.5.8C.exe) - no effect. Went back to IDE 1.8.5.
Note: What actually worked was putting the USB cable into a different socket on my USB HUB with 7 extra USB ports.
Note2: On my second notebook (Windows 10). Two direct USB ports, built into the machine, came up with the "USB Device not recognised" message. Plugging a powered Hub (the same one from the other machine) allowed the Digispark to connect correctly!
In the Digispark Attiny documentation it is recommend that a powered USB hub is used so that you don't accidentally blowup the USB port in the PC. It could be that the development of the software has made a dependency on using a USB hub (Its a good idea for the stated safety reason anyway). So I would recommend you get one for Digispark development.

Device Manager - Digispark Not Found

If you have a problem you'll see a message ("Unknown USB Device.") in the Windows Device Manager like this:

Device manager USB device not recognised

Device Manager - Digispark Attiny85 Driver Is Found

For successful Digispark ATtiny85 detection you will see this (message is libusb-win32 Devices, digispark bootloader) this appears after you plug in the Digispark to a USB port:

Successful ATtiny85 installation

ATtiny85 Arduino install Steps

1. Install the Arduino IDE

An easy way is to search the Microsoft Apps store in windows 8.1 or 10 and search for Arduino. Install the app. Alternatively download the executable installer here. The latest one is 1.8.8 and it does work with Digispark.

2. Install Digispark Attiny85 Windows Drivers

Download the Digispark Attiny85 windows drivers here.
(This is the 1.67 Feb 13 2016 release found here.)
Download Digistump.Drivers.zip unzip on your hard disc. Then double click on DPinst (32 bit PC) or DPinst64 (64 bit PC) depending on your system.

Digistump Digispark Driver installation You should now check that windows can see the Digispark - Just plug in the Digispark usb (micro usb connector) and you will hear the USB connection sound. If windows complains saying "USB Device not recognised." then you will need to fix this before going further - the IDE has nothing to do with this part.

The problem is that you have to install drivers in order for windows to correctly identify and communicate with the micronucleus device. If you have problems have a look here.

3. Set up Digistump for the IDE

To allow Digistump boards to be seen by the Arduino IDE you need to insert a line of code in the Menu > File > preferences window as shown below:
The line to insert in the "Additionan Boards manager URLs" box is:
http://digistump.com/package_digistump_index.json
If you have more than one of these lines click the double-box symbol to the right of that entry box and add each entry one per line.

Arduino IDE board seupt in preferences pane

4. Select a Digispark Board or Mode

You won't see any examples for Digistump in the Menu > File > Examples until you select the Digispark board in Menu > Tools > Boards.

From that menu select the board labelled:

Digispark (Default - 16.5MHz)

Note: The Digispark Pro is a different board that uses a bigger chip: an ATtiny167 20 pin chip (and is slightly easier to use). However once you have got the drivers going the Digispark is fairly easy to program.

Selecting the Digispark Board

Select Digispark 16.5MHz board

5. Select a Digispark Attiny85 Example

The examples will now be available from the Examples Menu: File > Examples > Digispark_Examples.
It does not matter which example is used, but one that does not do too much is the Infrared one - you don't need to attach an infrared receiver - you are only going to go through the process of programming it - to get used to the process. You can if you want to though - just use a standard IR receiver.
Go back to the Arduino IDE Menu > File > Examples > Digispark_Examples
And choose the Infrared example.

ATtiny85 Digispark Test with IR code example

Now you will see the following code in the Arduino IDE.

This is simple code that does not attempt to decode the IR signal it just reacts if any signal is received by flashing the built in LED. If it does not flash the LED is on pin 1 - newer boards use this as the LED pin.
int irPin=2;

void setup()
{
 pinMode(irPin,INPUT);
 pinMode(0,OUTPUT);
 //Serial.begin(9600);
 digitalWrite(0,HIGH);
     //Serial.println("You pressed a button");
     delay(1000);
     digitalWrite(0,LOW);
}

void loop()
{

  if(pulseIn(irPin,LOW))
  {
     //button pressed
     delay(100);
     digitalWrite(0,HIGH);
     //Serial.println("You pressed a button");
     delay(1000);
     digitalWrite(0,LOW);
  }

}

6. Compile and Upload a program

There are two parts to programming the board

  1. Start the compile and upload process as you usually do for the Arduino.
  2. Plug in the Digispark ATtiny85 to initialise USB detection.

1. Normal Arduino Compilation

To start digispark attiny85 programming hit the compile and upload button or press Ctrl-u.

Once uploading starts you will see the following information in the status box at the bottom of the Arduino IDE:

Sketch uses 700 bytes (11%) of program storage space. Maximum is 6012 bytes.
Global variables use 9 bytes of dynamic memory.
Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)
> Please plug in the device ...
> Press CTRL+C to terminate the program.

2. Micronucleus USB Detection and Upload


At this point you need to plug in (or unplug and re-plug in the Digispark Attiny85). Then you will see the following status output:

Sketch uses 700 bytes (11%) of program storage space. Maximum is 6012 bytes.
Global variables use 9 bytes of dynamic memory.
Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)
> Please plug in the device ...
> Press CTRL+C to terminate the program.
> Device is found!
connecting: 16% complete
connecting: 22% complete
connecting: 28% complete
connecting: 33% complete
> Device has firmware version 1.6
> Available space for user applications: 6012 bytes
> Suggested sleep time between sending pages: 8ms
> Whole page count: 94  page size: 64
> Erase function sleep duration: 752ms
parsing: 50% complete
> Erasing the memory ...
erasing: 55% complete
erasing: 60% complete
erasing: 65% complete
> Starting to upload ...
writing: 70% complete
writing: 75% complete
writing: 80% complete
> Starting the user app ...
running: 100% complete
>> Micronucleus done. Thank you!

Notice that the version of micronucleus firmware is 1.6. This can be upgraded to get more space by reprogramming the bootloader.

7. Digispark LED Flash Test program

Here is a program to just flash the on-board LED. Re-program the Digispark and check the led flashes (New Digisparks have the LED on pin 1, older ones have the LED on pin 0).

Now you should be familiar with the Digispark ATtiny programming process.

#define LEDPIN 1
void setup()
{
   pinMode(LEDPIN,OUTPUT);
}

void loop()
{
   delay(200);
   digitalWrite(LEDPIN,HIGH);
     
   delay(200);
   digitalWrite(LEDPIN,LOW);
}


Comments

Popular posts from this blog

What is the ESP32 VSPI / HSPI

 The ESP32 integrates four SPI peripherals. SPI0 and SPI1 are used to access the ESP32’s attached flash memory and thus are currently not open to users to be used . They share one signal bus via an arbiter. SPI2 and SPI3 are general purpose SPI controllers, sometimes referred to as HSPI and VSPI, respectively. They are open for use. SPI2 and SPI3 have independent signal buses with the same respective names. Each bus has three CS lines to drive up to three SPI slaves.  

Most common baud rates table

  The following table shows the most used baud rates. The left side part of the table shows speed and bit duration. The right part shows real transmission speed assuming there is no parity, 8 data bits and one stop bit.   Bauds Bits/s Bit duration Speed Actual speed Actual byte duration 50 bauds 50 bits/s 20.000 ms 6.25 bytes/s 5 bytes/s 200.000 ms 75 bauds 75 bits/s 13.333 ms 9.375 bytes/s 7.5 bytes/s 133.333 ms 110 bauds 110 bits/s 9.091 ms 13.75 bytes/s 11 bytes/s 90.909 ms 134 bauds 134 bits/s 7.463 ms 16.75 bytes/s 13.4 bytes/s 74.627 ms 150 bauds 150 bits/s 6.667 ms 18.75 bytes/s 15 bytes/s 66.667 ms 200 bauds 200 bits/s 5.000 ms 25 bytes/s 20 bytes/s 50.000 ms 300 bauds 300 bits/s 3.333 ms 37.5 bytes/s 30 bytes/s 33.333 ms 600 bauds 600 bits/s 1.667 ms 75 bytes/s 60 bytes/s 16.667 ms 1200 bauds 1200 bits/s 833.333 µs 150 bytes/s 120 bytes/s 8.333 ms 1800 bauds 1800 bits/s 555.556 µs 225 bytes/s

How to program 8051 based MCU using Ptroteous Schematic capture and Source code editor to use timers using AT892051 + project files

 This tutorial is dedicated to use a 8051 based Microcontroller core and program it using keil's C51 tools on the Proteus Source code editor.  1- Brief History of 8051 one of the first microprocessors 4004 was invented by Intel Corporation as well as  8085 and 8086 microprocessors back in 1981,shortly after Intel introduced an 8-bit microcontroller called the 8051 . It was referred to as system on a chip because it had 128 bytes of RAM, 4K byte of on-chip ROM, two timers, one serial port, and 4 ports (8-bit wide), all on a single chip. When it became so widespread, Intel allowed other manufacturers to make and market different flavors of 8051 with its code compatible with 8051. It means that if you write your program for one flavor of 8051, it will run on other flavors too, regardless of the manufacturer. This has led to several versions with different speeds and amounts of on-chip RAM. 2- Features of AT892051 Microcontroller Compatible with MCS®-51Products 2K Bytes of R