Skip to content

Instantly share code, notes, and snippets.

@dudeitssm
Forked from Ircama/Digispark.md
Created April 11, 2022 03:44
Show Gist options
  • Save dudeitssm/ac5a5817cbb3872bf973f350d90fde0c to your computer and use it in GitHub Desktop.
Save dudeitssm/ac5a5817cbb3872bf973f350d90fde0c to your computer and use it in GitHub Desktop.

Revisions

  1. @Ircama Ircama revised this gist Jun 2, 2021. 1 changed file with 14 additions and 6 deletions.
    20 changes: 14 additions & 6 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,15 @@
    # Configuring the Digispark ATTINY85 board for Arduino IDE and upgrading the bootloader

    Warning: this document has to be updated by pointing to https://github.com/SpenceKonde/ATTinyCore

    This note describes the configuration of an [ATtiny85](http://www.microchip.com/wwwproducts/en/ATtiny85) based microcontroller development board named [Digispark](http://digistump.com/products/1) and similar to the [Arduino](https://www.arduino.cc/) line. It is available in many online marketplaces for roughly 1 dollar (e.g., Ebay, Amazon,
    AliExpress) and is shipped fully assembled, including a [V-USB](https://www.obdev.at/products/vusb/index.html) interface (a software-only implementation of a low-speed [USB](https://en.wikipedia.org/wiki/USB) device for [Atmel]( http://www.atmel.com/)'s [AVR](http://www.atmel.com/products/microcontrollers/avr/) microcontrollers). Coding is similar to Arduino: it uses the familiar [Arduino IDE](https://www.arduino.cc/en/main/software) and is already provided with a ready-to-use bootloader (fully integrated with Arduino), also allowing to be upgraded. Comparing it with the [ATmega328P](http://www.microchip.com/wwwproducts/en/ATmega328P) microcontroller, it is cheaper, smaller, and a bit less powerful. Digispark is [copyrighted](http://digistump.com/wiki/digispark/policy) by [Digistump LLC](http://digistump.com/) under the [Creative Commons Attribution-ShareAlike 3.0](https://creativecommons.org/licenses/by-sa/3.0/).

    ## Adding Digispark support to Arduino
    The Arduino IDE needs to be installed first. Check [Basic Arduino Installation]( https://www.arduino.cc/en/Main/Software) and [Install the Arduino Software (IDE) on Windows PCs](https://www.arduino.cc/en/guide/windows) for guided installation procedures.

    Warning: instead of http://digistump.com/package_digistump_index.json, use https://github.com/SpenceKonde/ATTinyCore

    A [tutorial](http://digistump.com/wiki/digispark/tutorials/connecting) published at the [Digispark wiki](http://digistump.com/wiki/digispark) describes how to add the Digispark support to Arduino 1.6.X (1.6.4+) via the Arduino Boards Manager. This tutorial refers to the standard Digistump URL to be added to the Additional Boards Manager URLs: http://digistump.com/package_digistump_index.json. Anyway, at the moment of writing the easiest and most updated repository for the Digispark appears [DigistumpArduino](https://github.com/ArminJo/DigistumpArduino) by [ArminJo](https://github.com/ArminJo). Follow the [installation](https://github.com/ArminJo/DigistumpArduino#installation) section and replace https://raw.githubusercontent.com/ArminJo/DigistumpArduino/master/package_digistump_index.json instead of the previously mentioned URL http://digistump.com/package_digistump_index.json. This offers a ready-to-use environment and most of the configurations in the following sections, like editing *boards.txt* to set the upload maximum size, are automatically done by this set-up.

    If an URL is already available in "Additional Boards Manager URLs" line (e.g., for esp8266 boards), more URLs can be added, separating them by a comma.
    @@ -325,20 +329,24 @@ The following setting will allow reading the *avrdude* command line, subsequentl

    File > Preferences. Select "Show verbose output during" "upload"

    [Install the ATtiny boards](https://github.com/damellis/attiny) from the IDE boards manager.
    Install [ATTinyCore](https://github.com/SpenceKonde/ATTinyCore) from the IDE boards manager.

    ~~[Install the ATtiny boards](https://github.com/damellis/attiny) from the IDE boards manager.~~

    - File > Preferences > Additional Boards Manager URLs
    - Add https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
    - Add http://drazzy.com/package_drazzy.com_index.json ~~https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json~~
    to the configuration. If additional urls are available, use a comma to separate the new URL from the existing ones.
    - Click the OK button to save your updated preferences.
    - Open the boards manager: Tools > Board > Boards Manager...
    - Search *attiny* and load "attiny by David A. Mellis".
    - Search *attinycore* by [Spence Konde](https://github.com/SpenceKonde) ~~*attiny* and load "attiny by David A. Mellis"~~.

    Set up the IDE configuration to use ArduinoISP:

    - Tools > Board > ATtiny Microcontrollers > Attiny25/45/85
    - Tools > Processor > ATtiny85
    - Tools > Clock > Set to the correct CPU clock (e.g., Internal 16 Mhz, or Internal 8 MHz, or Internal 1 MHz)
    - Tools > Chip: ATTiny85
    - Tools > Clock > Set to the correct CPU clock (e.g., Internal 16.5 Mhz, or Internal 8 MHz, or Internal 1 MHz)
    ~~- Tools > Board > ATtiny Microcontrollers > Attiny25/45/85~~
    ~~- Tools > Processor > ATtiny85~~
    ~~- Tools > Clock > Set to the correct CPU clock (e.g., Internal 16 Mhz, or Internal 8 MHz, or Internal 1 MHz)~~
    - Tools > Port > Select the appropriate Arduino Port
    - Tools > Programmer > Arduino as ISP

  2. @Ircama Ircama revised this gist May 31, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -338,7 +338,7 @@ Set up the IDE configuration to use ArduinoISP:

    - Tools > Board > ATtiny Microcontrollers > Attiny25/45/85
    - Tools > Processor > ATtiny85
    - Tools > Clock > Internal 1 MHz
    - Tools > Clock > Set to the correct CPU clock (e.g., Internal 16 Mhz, or Internal 8 MHz, or Internal 1 MHz)
    - Tools > Port > Select the appropriate Arduino Port
    - Tools > Programmer > Arduino as ISP

  3. @Ircama Ircama revised this gist May 30, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -318,7 +318,7 @@ Notes:
    Start the Arduino IDE and upload the ArduinoISP sketch to the Arduino Uno (or Nano).

    - Verify that the IDE configuration is appropriate to upload sketches to the Arduino board
    - Open the ArduinoISP example sketch: Files > Examples > ArduinoISP > ArduinoISP
    - Open the ArduinoISP example sketch (check the IDE menu): File > Examples > ArduinoISP > ArduinoISP
    - Upload the sketch to Arduino.

    The following setting will allow reading the *avrdude* command line, subsequently used to upload the micronucleus hex code.
  4. @Ircama Ircama revised this gist Dec 15, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -371,7 +371,7 @@ To download the micronucleus firmware, select *releases* (and not *upgrades*): h
    Flash micronucleus and update fuses (example of `<com port>`: COM6):

    ```cmd
    <path>/avrdude -C<path>/avrdude.conf -v -pattiny85 -cstk500v1 -P<com port> -b19200 -Uflash:w:<path>\t85_default.hex -U lfuse:w:0xf1:m -U hfuse:w:0xdf:m -U efuse:w:0xfe:m
    <path>/avrdude -C<path>/avrdude.conf -v -pattiny85 -cstk500v1 -P<com port> -b19200 -Uflash:w:<path>\t85_default.hex:i -U lfuse:w:0xf1:m -U hfuse:w:0xdf:m -U efuse:w:0xfe:m
    ```

    Now, if needed, micronucleus can be upgraded (example):
  5. @Ircama Ircama revised this gist Oct 19, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -262,7 +262,7 @@ Pinout:

    - https://neonaut.neocities.org/images/digispark-pinout.png
    - https://camo.githubusercontent.com/776b358cb7412939e03a65990fb36d0aa39e890f/687474703a2f2f6472617a7a792e636f6d2f652f696d672f50696e6f75745438352e706e67
    - https://github.com/SpenceKonde/ATTinyCore
    - https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/extras/ATtiny_x5.md
    - https://github.com/ArminJo/DigistumpArduino#attiny85-on-digispark

    Digispark pin numbering from 0 to 5:
  6. @Ircama Ircama revised this gist Oct 19, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ Then run:
    Check also the [Driver installation in DigistumpArduino](https://github.com/ArminJo/DigistumpArduino#driver-installation) for updated information.

    ### Upload the latest version of the bootloader
    [Micronucleus](https://github.com/micronucleus/micronucleus) is a bootloader designed for AVR ATtiny microcontrollers; its latest version offers significant improvements over V1.x; upgrading the bootloader allows taking advantage of the benefits described in the [Micronucleus README](https://github.com/micronucleus/micronucleus/blob/master/Readme.txt): mainly a significantly compact size.
    [Micronucleus](https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/extras/UsingMicronucleus.md) is a bootloader designed for AVR ATtiny microcontrollers; its latest version offers significant improvements over V1.x; upgrading the bootloader allows taking advantage of the benefits described in the [Micronucleus README](https://github.com/micronucleus/micronucleus/blob/master/Readme.txt): mainly a significantly compact size.

    Download https://github.com/micronucleus/micronucleus and expand it to a local Windows directory.

  7. @Ircama Ircama revised this gist Oct 19, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -382,7 +382,9 @@ micronucleus.exe /run upgrade-t85_entry_on_power_on_no_pullup_fast_exit_on_no_US

    # Notes
    ## Changing internal clock
    Changing the CKSEL fuses from 16,5 MHz (`-U lfuse:w:0xf1:m`) to 8 MHz internal clock (`-U lfuse:w:0xE2:m`) and viceversa can be done at any time with *avrdude* and SPI hw configuration, but the micronucelus will not work at 8 MHz: you first need to revert the clock speed to 16,5 MHz to restore using the micronucelus.
    Changing the CKSEL fuses from 16,5 MHz (`-U lfuse:w:0xf1:m`) to 8 MHz internal clock (`-U lfuse:w:0xE2:m`) and viceversa can be done at any time with *avrdude* and SPI hw configuration, but the micronucelus will not work at 8 MHz ([minimum clock for V-USB](https://www.obdev.at/products/vusb/index.html) is [12 MHz](https://github.com/micronucleus/micronucleus/tree/master/firmware/usbdrv)): you first need to revert the clock speed to 16,5 MHz to restore using the micronucelus.

    The ATtiny85 is only specified to run at 16 MHz when powered at 5V, however you may be able to overclock it at 16 MHz with 3V (8 MHz is recommended for 3V and 8 or 16MHz with 5V).

    ## Notes on serial monitoring
    ATtiny85 does not provide a native serial interface, but it can be generated via software:
  8. @Ircama Ircama revised this gist Oct 19, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -381,7 +381,7 @@ micronucleus.exe /run upgrade-t85_entry_on_power_on_no_pullup_fast_exit_on_no_US
    ```

    # Notes
    ## 8 MHz internal clock
    ## Changing internal clock
    Changing the CKSEL fuses from 16,5 MHz (`-U lfuse:w:0xf1:m`) to 8 MHz internal clock (`-U lfuse:w:0xE2:m`) and viceversa can be done at any time with *avrdude* and SPI hw configuration, but the micronucelus will not work at 8 MHz: you first need to revert the clock speed to 16,5 MHz to restore using the micronucelus.

    ## Notes on serial monitoring
  9. @Ircama Ircama revised this gist Oct 19, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -381,6 +381,8 @@ micronucleus.exe /run upgrade-t85_entry_on_power_on_no_pullup_fast_exit_on_no_US
    ```

    # Notes
    ## 8 MHz internal clock
    Changing the CKSEL fuses from 16,5 MHz (`-U lfuse:w:0xf1:m`) to 8 MHz internal clock (`-U lfuse:w:0xE2:m`) and viceversa can be done at any time with *avrdude* and SPI hw configuration, but the micronucelus will not work at 8 MHz: you first need to revert the clock speed to 16,5 MHz to restore using the micronucelus.

    ## Notes on serial monitoring
    ATtiny85 does not provide a native serial interface, but it can be generated via software:
    @@ -503,6 +505,8 @@ ISR(PCINT0_vect) {
    #endif
    ```

    Consider setting the clock speed to 8 MHz internal clock (`-U lfuse:w:0xE2:m`) when waking up the device from sleep mode through an interrupt in order to speed-up the wake-up time (4 to 5 ms from Power Down sleep with 16,5 MHz; 6 clocks with 8 MHz).

    ## Note on the RESET pin
    P5 (PB5) is the reset pin. Depending on the Digispark hardware, the reset function can be enabled or disabled. [The default hardware implementation should have it disabled](https://digistump.com/wiki/digispark/tutorials/programming); in this case, bootloaders can be upgraded (the Micronucleus bootloader works and sketches can be uploaded using the bootloader), but ISP programming is disabled (as ISP connection needs the enabled RESET function; notice that ISP programming can be done via ISP device or via an appropriately confugured Arduino or Digispark).

  10. @Ircama Ircama revised this gist Oct 19, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -304,7 +304,7 @@ The following is the hardware connection between Digispark and Arduino Uno (or A
    | D10 | --> | P5 | RESET |
    | D11 | --> | P0 | SPI MOSI |
    | D12 | --> | P1 | SPI MISO |
    | D12 | --> | P2 | SPI SCK |
    | D13 | --> | P2 | SPI SCK |

    The Digispark device can be powered via USB.

  11. @Ircama Ircama revised this gist Oct 11, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -358,7 +358,7 @@ When uploading, the IDE output log shows the full AVRDUDE command used to load t

    Copy the command, open a CMD and paste the command to the command prompt. Modify it as follows.

    Reading fuses (example of <com port>: COM6):
    Reading fuses (example of `<com port>`: COM6):

    ```cmd
    <path>/avrdude -C<path>/avrdude.conf -v -pattiny85 -cstk500v1 -P<com port> -b19200 -U lfuse:r:-:i
    @@ -368,7 +368,7 @@ Note: for normal operation, fuses should be [`E:FE, H:DF, L:F1`](https://eleccel

    To download the micronucleus firmware, select *releases* (and not *upgrades*): https://github.com/ArminJo/micronucleus-firmware/tree/master/firmware/releases

    Flash micronucleus and update fuses (example of <com port>: COM6):
    Flash micronucleus and update fuses (example of `<com port>`: COM6):

    ```cmd
    <path>/avrdude -C<path>/avrdude.conf -v -pattiny85 -cstk500v1 -P<com port> -b19200 -Uflash:w:<path>\t85_default.hex -U lfuse:w:0xf1:m -U hfuse:w:0xdf:m -U efuse:w:0xfe:m
  12. @Ircama Ircama revised this gist Oct 11, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -348,9 +348,9 @@ Select any sample sketch, like Blink:

    Examples > Basics > Blink

    Compile and upload the sketch
    Compile and upload the sketch.

    The output log shows the full AVRDUDE command used to load the sketch, including command line arguments and paths:
    When uploading, the IDE output log shows the full AVRDUDE command used to load the sketch, including command line arguments and paths:

    ```cmd
    <path>/avrdude -C<path>/avrdude.conf -v -pattiny85 -cstk500v1 -P<com port> -b19200 -Uflash:w:<path>/sample.ino.hex:i
  13. @Ircama Ircama revised this gist Oct 11, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -329,7 +329,7 @@ File > Preferences. Select "Show verbose output during" "upload"

    - File > Preferences > Additional Boards Manager URLs
    - Add https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
    to the configuration. If additional urls are available, use a comma to separate the new URL from the existing ones).
    to the configuration. If additional urls are available, use a comma to separate the new URL from the existing ones.
    - Click the OK button to save your updated preferences.
    - Open the boards manager: Tools > Board > Boards Manager...
    - Search *attiny* and load "attiny by David A. Mellis".
  14. @Ircama Ircama revised this gist Oct 11, 2020. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -308,13 +308,12 @@ The following is the hardware connection between Digispark and Arduino Uno (or A

    The Digispark device can be powered via USB.

    Digispark pins P3 and P4 are not used.
    Notes:

    Usage of a capacitor (mentioned in some descriptions) is not needed.

    LEDs (controlled by the sketch) are not strictly necessary.

    5V and GND wires to power the Digispark board are not needed (as mentioned, the Digispark can be powered via USB).
    - Digispark pins P3 and P4 are not used.
    - Usage of a capacitor (mentioned in some descriptions) is not needed.
    - LEDs (controlled by the sketch) are not strictly necessary.
    - 5V and GND wires to power the Digispark board are not needed (as mentioned, the Digispark can be powered via USB).

    Start the Arduino IDE and upload the ArduinoISP sketch to the Arduino Uno (or Nano).

  15. @Ircama Ircama revised this gist Oct 11, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Digispark.md
    Original file line number Diff line number Diff line change
    @@ -299,7 +299,6 @@ This procedure shows how to flash the micronucleus with an Arduino and can also

    The following is the hardware connection between Digispark and Arduino Uno (or Arduino Nano, which has the same pins): just 4 wires.

    ```
    | Arduino | | Digispark | (ATTINY85 description) |
    |---------|-----|-----------|------------------------|
    | D10 | --> | P5 | RESET |
  16. @Ircama Ircama revised this gist Oct 11, 2020. 1 changed file with 91 additions and 0 deletions.
    91 changes: 91 additions & 0 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -291,6 +291,97 @@ The Digispark ATtiny85 device has to be modified as follows to save power:

    Notice that after the modification of the D- pull-up resistor, the Digispark bootloader has to be flashed with "#define ENTRYMODE ENTRY_EXT_RESET" in micronucleus-master/firmware/configuration/t85_default/bootloaderconfig.h; then use the Digispark reset pin to enable the firmware upload. Setting ENTRYMODE to ENTRY_EXT_RESET avoids to hang the Digispark if D- is not pulled-up. A micro-switch between D5 and ground is appropriate, also pulling up D5 to VCC with a 22kohm resistor.

    # Flashing the micronucleus

    In case the Digispark freezes with no possibility to perform any upload, the micronucleus has to be flashed again. You need an AVR USB ISP programmer to do this, or simply an [Arduino with ArduinoISP sketch](https://www.arduino.cc/en/Tutorial/BuiltInExamples/ArduinoISP) that allows emulating a STK500v1 programmer.

    This procedure shows how to flash the micronucleus with an Arduino and can also be used to install the micronucleus to a new ATTINY85 chip.

    The following is the hardware connection between Digispark and Arduino Uno (or Arduino Nano, which has the same pins): just 4 wires.

    ```
    | Arduino | | Digispark | (ATTINY85 description) |
    |---------|-----|-----------|------------------------|
    | D10 | --> | P5 | RESET |
    | D11 | --> | P0 | SPI MOSI |
    | D12 | --> | P1 | SPI MISO |
    | D12 | --> | P2 | SPI SCK |
    The Digispark device can be powered via USB.
    Digispark pins P3 and P4 are not used.
    Usage of a capacitor (mentioned in some descriptions) is not needed.
    LEDs (controlled by the sketch) are not strictly necessary.
    5V and GND wires to power the Digispark board are not needed (as mentioned, the Digispark can be powered via USB).
    Start the Arduino IDE and upload the ArduinoISP sketch to the Arduino Uno (or Nano).
    - Verify that the IDE configuration is appropriate to upload sketches to the Arduino board
    - Open the ArduinoISP example sketch: Files > Examples > ArduinoISP > ArduinoISP
    - Upload the sketch to Arduino.
    The following setting will allow reading the *avrdude* command line, subsequently used to upload the micronucleus hex code.
    File > Preferences. Select "Show verbose output during" "upload"
    [Install the ATtiny boards](https://github.com/damellis/attiny) from the IDE boards manager.
    - File > Preferences > Additional Boards Manager URLs
    - Add https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
    to the configuration. If additional urls are available, use a comma to separate the new URL from the existing ones).
    - Click the OK button to save your updated preferences.
    - Open the boards manager: Tools > Board > Boards Manager...
    - Search *attiny* and load "attiny by David A. Mellis".
    Set up the IDE configuration to use ArduinoISP:
    - Tools > Board > ATtiny Microcontrollers > Attiny25/45/85
    - Tools > Processor > ATtiny85
    - Tools > Clock > Internal 1 MHz
    - Tools > Port > Select the appropriate Arduino Port
    - Tools > Programmer > Arduino as ISP
    After installing the ArduinoISP sketch and connecting the devices, the firmware upload can be done at any time, because the ISP sketch automatically drives the Digispark device.
    Select any sample sketch, like Blink:
    Examples > Basics > Blink
    Compile and upload the sketch
    The output log shows the full AVRDUDE command used to load the sketch, including command line arguments and paths:
    ```cmd
    <path>/avrdude -C<path>/avrdude.conf -v -pattiny85 -cstk500v1 -P<com port> -b19200 -Uflash:w:<path>/sample.ino.hex:i
    ```

    Copy the command, open a CMD and paste the command to the command prompt. Modify it as follows.

    Reading fuses (example of <com port>: COM6):

    ```cmd
    <path>/avrdude -C<path>/avrdude.conf -v -pattiny85 -cstk500v1 -P<com port> -b19200 -U lfuse:r:-:i
    ```

    Note: for normal operation, fuses should be [`E:FE, H:DF, L:F1`](https://eleccelerator.com/fusecalc/fusecalc.php?chip=attiny85&LOW=F1&HIGH=DF&EXTENDED=FE&LOCKBIT=FF).

    To download the micronucleus firmware, select *releases* (and not *upgrades*): https://github.com/ArminJo/micronucleus-firmware/tree/master/firmware/releases

    Flash micronucleus and update fuses (example of <com port>: COM6):

    ```cmd
    <path>/avrdude -C<path>/avrdude.conf -v -pattiny85 -cstk500v1 -P<com port> -b19200 -Uflash:w:<path>\t85_default.hex -U lfuse:w:0xf1:m -U hfuse:w:0xdf:m -U efuse:w:0xfe:m
    ```

    Now, if needed, micronucleus can be upgraded (example):

    ```cmd
    micronucleus.exe /run upgrade-t85_entry_on_power_on_no_pullup_fast_exit_on_no_USB.hex
    ```

    # Notes

    ## Notes on serial monitoring
  17. @Ircama Ircama revised this gist Oct 11, 2020. 1 changed file with 19 additions and 21 deletions.
    40 changes: 19 additions & 21 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -376,43 +376,41 @@ void loop() {
    DKeyboard needs timer interrupt disabled. If timer interrupt is used (e.g, [IRMP](https://github.com/ukw100/IRMP) or [IRemote](https://github.com/z3t0/Arduino-IRremote), interrupts shall be temporarily disabled.

    ## Note on sleep mode
    The following sample allows calling *sleep()* to enter sleep mode to the lowest power level. It puts the processor in quiescent mode and uses Pin 0 to resume from sleep.
    The following sample explains how to enter sleep mode with the lowest power level. It puts the processor in quiescent mode and uses Pin 0 (PB0) to resume from sleep (other pins can be added: PB0=PCINT0, PB1=PCINT1, PB2=PCINT2, PB3=PCINT3, PB4=PCINT4, PB5=PCINT5). *PCINT0_vect* is a single ISR vector for Pin Change interrupts related to all pins; use `EMPTY_INTERRUPT(PCINT0_vect)` macro if no ISR vector is needed; otherwise use `ISR(PCINT0_vect) {...}`.

    ```c
    #include <avr/sleep.h>
    #include <avr/interrupt.h>

    void sleep() {
    #if defined (__AVR_ATtiny85__)
    cli(); // Disable interrupts
    GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
    PCMSK |= _BV(PCINT0); // Use Pin 0 interrupt pin to resume from sleep

    ADCSRA &= ~_BV(ADEN); // ADC off
    cli(); // Disable interrupts to set the sleep configuration
    GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts for all pins
    PCMSK |= _BV(PCINT0); // Unmask Pin Change Interrupt for pin PB0 (=PCINT0)
    ADCSRA &= ~_BV(ADEN); // ADC off (save power when sleeping)
    set_sleep_mode(SLEEP_MODE_PWR_DOWN); // set sleep to the lowest power mode

    sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
    sei(); // Enable interrupts
    sei(); // Enable interrupts before sleeping
    sleep_cpu(); // sleep

    cli(); // Disable interrupts
    PCMSK &= ~_BV(PCINT0); // Turn off interrupt on pin 0
    GIMSK &= ~_BV(PCIE); // Turn off Pin Change Interrupts

    cli(); // Disable interrupts after resuming from sleep
    PCMSK &= ~_BV(PCINT0); // Mask Pin Change Interrupt for pin PB0 (=PCINT0)
    GIMSK &= ~_BV(PCIE); // Turn off Pin Change Interrupts for all pins
    sleep_disable(); // Clear SE bit
    ADCSRA &= ~_BV(ADEN); // ADC off (if needed...)

    sei(); // Enable interrupts
    ADCSRA |= _BV(ADEN); // Restore ADC on
    sei(); // Enable interrupts again
    #endif
    } // sleep
    }

    #if defined (__AVR_ATtiny85__)

    EMPTY_INTERRUPT(PCINT0_vect) // Null Pin Change Interrupt vector for all unmasked pins

    /* Alternatively to EMPTY_INTERRUPT():
    ISR(PCINT0_vect) {
    // This is called when the interrupt occurs
    TIMER_RESET; // reset irrecv timer
    irrecv.resume(); // reset irrecv counter
    previousTime = millis(); // reset sleep timer
    // This is called when the interrupt occurs in case of Pin Change of all unmasked pins
    }
    */

    #endif
    ```

  18. @Ircama Ircama revised this gist Aug 24, 2020. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -6,22 +6,21 @@ AliExpress) and is shipped fully assembled, including a [V-USB](https://www.obde
    ## Adding Digispark support to Arduino
    The Arduino IDE needs to be installed first. Check [Basic Arduino Installation]( https://www.arduino.cc/en/Main/Software) and [Install the Arduino Software (IDE) on Windows PCs](https://www.arduino.cc/en/guide/windows) for guided installation procedures.

    A [tutorial](http://digistump.com/wiki/digispark/tutorials/connecting) published at the [Digispark wiki](http://digistump.com/wiki/digispark) describes how to add the Digispark support to Arduino 1.6.X (1.6.4+) via the Arduino Boards Manager.
    A [tutorial](http://digistump.com/wiki/digispark/tutorials/connecting) published at the [Digispark wiki](http://digistump.com/wiki/digispark) describes how to add the Digispark support to Arduino 1.6.X (1.6.4+) via the Arduino Boards Manager. This tutorial refers to the standard Digistump URL to be added to the Additional Boards Manager URLs: http://digistump.com/package_digistump_index.json. Anyway, at the moment of writing the easiest and most updated repository for the Digispark appears [DigistumpArduino](https://github.com/ArminJo/DigistumpArduino) by [ArminJo](https://github.com/ArminJo). Follow the [installation](https://github.com/ArminJo/DigistumpArduino#installation) section and replace https://raw.githubusercontent.com/ArminJo/DigistumpArduino/master/package_digistump_index.json instead of the previously mentioned URL http://digistump.com/package_digistump_index.json. This offers a ready-to-use environment and most of the configurations in the following sections, like editing *boards.txt* to set the upload maximum size, are automatically done by this set-up.

    Anyway, the most updated repository is [DigistumpArduino](https://github.com/ArminJo/DigistumpArduino) by [ArminJo](https://github.com/ArminJo). Follow the [installation](https://github.com/ArminJo/DigistumpArduino#installation) section and add https://raw.githubusercontent.com/ArminJo/DigistumpArduino/master/package_digistump_index.json instead of
    http://digistump.com/package_digistump_index.json.
    If an URL is already available in "Additional Boards Manager URLs" line (e.g., for esp8266 boards), more URLs can be added, separating them by a comma.

    Notice the last message of the *Preferences* form: “More preferences can be edited directly in the file”. If clicking the file name, the related installation directory is opened (the *digistump* root directory can be found under the *packages* subdirectory).

    To configure the Arduino IDE for the Digispark board, select your target device

    Tools -> Boards -> Digispark (Default - 16.5MHz)
    Tools -> Boards -> Digispark (Default - 16.5MHz) (in case DigistumpArduino is used: Tools --> Boards --> Digistump AVR Boards --> Digispark)

    Select your programmer

    Tools -> Programmer -> Micronucleus

    Digispark comes with an old bootloader version (generally 1.06), anyway allowing upgrade.
    Digispark comes with an old bootloader version (generally 1.06), anyway allowing upgrade (to be done via Micronucleus, as described below).

    ## Digispark Windows PC Driver installation
    Three different Windows drivers can be installed for supporting the Digispark board:
    @@ -38,6 +37,8 @@ Then run:

    Install Digistump Drivers.bat

    Check also the [Driver installation in DigistumpArduino](https://github.com/ArminJo/DigistumpArduino#driver-installation) for updated information.

    ### Upload the latest version of the bootloader
    [Micronucleus](https://github.com/micronucleus/micronucleus) is a bootloader designed for AVR ATtiny microcontrollers; its latest version offers significant improvements over V1.x; upgrading the bootloader allows taking advantage of the benefits described in the [Micronucleus README](https://github.com/micronucleus/micronucleus/blob/master/Readme.txt): mainly a significantly compact size.

    @@ -136,9 +137,9 @@ Device should have bootloader version 2.3 (or newer).

    ### Other Micronucleus implementations

    [ArminJo](https://github.com/ArminJo) implemented a [fork for the micronucleus repository of the digispark firmware](https://github.com/ArminJo/micronucleus-firmware) with detailed documentation of installation and configuration options and many [precompiled and ready-to-install firmware releases](https://github.com/ArminJo/micronucleus-firmware/tree/master/firmware/releases).
    [ArminJo](https://github.com/ArminJo) implemented a [fork for the micronucleus repository of the digispark firmware](https://github.com/ArminJo/micronucleus-firmware) with detailed documentation of installation and configuration options and many [precompiled and ready-to-install firmware releases](https://github.com/ArminJo/micronucleus-firmware/tree/master/firmware/releases). Check [Update the bootloader section in DigistumpArduino](https://github.com/ArminJo/DigistumpArduino#update-the-bootloader) for information on how to install the bootloader. You can find there most of the bootloader upgrade configurations covering almost any needs, already prepared for upgrade installation; this generally avoids the need to generate a specific bootloader hex file.

    ### How to also generate the bootloader hex file
    ### How to optionally generate the bootloader hex file

    Open cygwin to the *firmware* directory (it should include a *Makefile* and the configuration directory). Run

    @@ -194,7 +195,7 @@ Check the max size of the executable program.

    Open the directory mentioned in the last message of the *Preferences* form (*Arduino IDE*, *File*, *Preferences*): “More preferences can be edited directly in the file”. If clicking the file name, the related installation directory is opened. Move to the *packages\digistump\hardware\avr\<version>* subdirectory.

    Edit boards.txt with a UNIX editor. Set *digispark-tiny.upload.maximum_size* to the value returned by *micronucleus /?*. Example:
    Edit *boards.txt* with a UNIX editor. Set *digispark-tiny.upload.maximum_size* to the value returned by *micronucleus /?*. Example:

    digispark-tiny.upload.maximum_size=6520

    @@ -262,6 +263,7 @@ Pinout:
    - https://neonaut.neocities.org/images/digispark-pinout.png
    - https://camo.githubusercontent.com/776b358cb7412939e03a65990fb36d0aa39e890f/687474703a2f2f6472617a7a792e636f6d2f652f696d672f50696e6f75745438352e706e67
    - https://github.com/SpenceKonde/ATTinyCore
    - https://github.com/ArminJo/DigistumpArduino#attiny85-on-digispark

    Digispark pin numbering from 0 to 5:

  19. @Ircama Ircama revised this gist Aug 23, 2020. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,9 @@ The Arduino IDE needs to be installed first. Check [Basic Arduino Installation](

    A [tutorial](http://digistump.com/wiki/digispark/tutorials/connecting) published at the [Digispark wiki](http://digistump.com/wiki/digispark) describes how to add the Digispark support to Arduino 1.6.X (1.6.4+) via the Arduino Boards Manager.

    Anyway, the most updated repository is [DigistumpArduino](https://github.com/ArminJo/DigistumpArduino) by [ArminJo](https://github.com/ArminJo). Follow the [installation](https://github.com/ArminJo/DigistumpArduino#installation) section and add https://raw.githubusercontent.com/ArminJo/DigistumpArduino/master/package_digistump_index.json instead of
    http://digistump.com/package_digistump_index.json.

    Notice the last message of the *Preferences* form: “More preferences can be edited directly in the file”. If clicking the file name, the related installation directory is opened (the *digistump* root directory can be found under the *packages* subdirectory).

    To configure the Arduino IDE for the Digispark board, select your target device
  20. @Ircama Ircama revised this gist Aug 16, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -263,8 +263,8 @@ Pinout:
    Digispark pin numbering from 0 to 5:

    - Digispark Pin 1 is generally the internal LED (ATTINY85 pin 6, PB1)
    - Digispark Pin 3 is USB D+ with pullup on Digispark board (ATTINY85 pin 2, PB3)
    - Digispark Pin 4 is USB D- (ATTINY85 pin 3, PB4)
    - Digispark Pin 3 is USB D- with pullup on Digispark board (ATTINY85 pin 2, PB3)
    - Digispark Pin 4 is USB D+ (ATTINY85 pin 3, PB4)
    - Digispark Pin 5 is the RESET (ATTINY85 pin 1, PB5)
    - Digispark Pins 0 and 2 are just wired to ATTINY85 pins 5 (PB0) and 7 (PB2).

  21. @Ircama Ircama revised this gist Aug 16, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -368,6 +368,8 @@ void loop() {
    }
    ```

    DKeyboard needs timer interrupt disabled. If timer interrupt is used (e.g, [IRMP](https://github.com/ukw100/IRMP) or [IRemote](https://github.com/z3t0/Arduino-IRremote), interrupts shall be temporarily disabled.

    ## Note on sleep mode
    The following sample allows calling *sleep()* to enter sleep mode to the lowest power level. It puts the processor in quiescent mode and uses Pin 0 to resume from sleep.

  22. @Ircama Ircama revised this gist Aug 16, 2020. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -260,6 +260,13 @@ Pinout:
    - https://camo.githubusercontent.com/776b358cb7412939e03a65990fb36d0aa39e890f/687474703a2f2f6472617a7a792e636f6d2f652f696d672f50696e6f75745438352e706e67
    - https://github.com/SpenceKonde/ATTinyCore

    Digispark pin numbering from 0 to 5:

    - Digispark Pin 1 is generally the internal LED (ATTINY85 pin 6, PB1)
    - Digispark Pin 3 is USB D+ with pullup on Digispark board (ATTINY85 pin 2, PB3)
    - Digispark Pin 4 is USB D- (ATTINY85 pin 3, PB4)
    - Digispark Pin 5 is the RESET (ATTINY85 pin 1, PB5)
    - Digispark Pins 0 and 2 are just wired to ATTINY85 pins 5 (PB0) and 7 (PB2).

    # Digispark board power consumption

  23. @Ircama Ircama revised this gist Aug 16, 2020. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -341,6 +341,26 @@ Steps to use DKeyboard for debug log monitoring:

    False errors of missing USB driver messages can occur with Windows (should be ignored). If no data is shown, increase KEYBOARD_DELAY timer.

    The following DKeyboard *Hello World* code takes 2784 bytes (42% of the available rooms):

    ```c
    #define KEYBOARD_DELAY 1500

    #include "DKeyboard.h"
    DKeyboardDevice Db = DKeyboardDevice();

    void setup() {
    Db.sendKeyStroke(0);
    Db.delay(KEYBOARD_DELAY);
    Db.sendKeyStroke(0);
    }

    void loop() {
    Db.println("Hello World");
    Db.delay(300);
    }
    ```

    ## Note on sleep mode
    The following sample allows calling *sleep()* to enter sleep mode to the lowest power level. It puts the processor in quiescent mode and uses Pin 0 to resume from sleep.

  24. @Ircama Ircama revised this gist Aug 16, 2020. 1 changed file with 12 additions and 8 deletions.
    20 changes: 12 additions & 8 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -285,15 +285,18 @@ Notice that after the modification of the D- pull-up resistor, the Digispark boo
    ATtiny85 does not provide a native serial interface, but it can be generated via software:
    - [bit-bang two-way serial half-duplex (two pins)](https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkSoftSerial)
    - [bit-bang serial-out (one pin)](https://github.com/ArminJo/ATtinySerialOut)

    Both provide a TTL UART hardware interface (using one or two pins different from P3 and P4, used for USB). If the PC has a physical serial port, an external TTL-to-RS232 hardware interface is needed. If USB is required to connect a PC, an external UART-USB hardware converter is needed.

    The above described options are the only ways to monitor a Digispark via Arduino "serial monitor".
    The above described options are ways to monitor a Digispark via Arduino "serial monitor".

    Similarly to the UART serial port, USB monitoring can be emulated via a bit-bang software implementation of the provided USB interface, emulating a serial port. DigiCDC, based on the [V-USB project](https://www.obdev.at/products/vusb), needs appropriate driver; it uses a software interrupt and needs no other timers or interrupts to be enabled in parallel to correctly work. Besides, to avoid USB problems, DigiCDC shall be started just after the microcontroller boot and shall be kept always active. It is slow and if you don't call a DigiCDC function (write, print, read, available, etc) every 10ms or less then you must throw in some *DigiCDC.refresh();* for the USB to keep alive - also replace your delays - ie. *delay(100);* with *DigiCDC.delays* ie. *DigiCDC.delay(100);*
    Similarly to the UART serial port, USB monitoring can be emulated via a bit-bang software implementation of the Digispark USB interface, emulating a serial port. All these options do not allow monitoring via Arduino "serial monitor".

    In order to to limit the code size, the suggested method for debugging and monitoring is [emulating an USB keyboard](https://digistump.com/wiki/digispark/tutorials/digikeyboard) through the [DKeyboard library](https://github.com/Ircama/AtTinyTestIR/tree/master/libraries/DKeyboard). No software driver is needed for the PC. It is suggested to include all monitoring code within related *#define*, so that it can be disabled for normal operation, when not needed. Avoid using punctuation and symbols in text strings (use just letters and numbers).
    - [DigiCDC](https://digistump.com/wiki/digispark/tutorials/digicdc), based on the [V-USB project](https://www.obdev.at/products/vusb), needs appropriate Windows PC driver; it uses a software interrupt and needs no other timers or interrupts to be enabled in parallel to correctly work. Besides, to avoid USB problems, DigiCDC shall be started just after the microcontroller boot and shall be kept always active. It is slow and if you don't call a DigiCDC function (write, print, read, available, etc) every 10ms or less then you must throw in some *DigiCDC.refresh();* for the USB to be kept alive - also replace your delays (i.e., "*delay(100);*") with *DigiCDC.delays* (i.e., "*DigiCDC.delay(100);*").

    Example:
    - In order to to limit the code size, the suggested method for debugging and monitoring is [emulating an USB keyboard](https://digistump.com/wiki/digispark/tutorials/digikeyboard) through the [DKeyboard library](https://github.com/Ircama/AtTinyTestIR/tree/master/libraries/DKeyboard). No software driver is needed for the PC. It is suggested to include all monitoring code within related *#define*, so that it can be disabled for normal operation, when not needed. Avoid using punctuation and symbols in text strings (use just letters and numbers).

    DKeyboard example:

    ```c
    #define USE_KEYBOARD
    @@ -327,12 +330,13 @@ void loop() {
    }
    ```

    Steps to use DKeyboard for debug log monitoring:

    - Create a new folder called [DKeyboard](https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkKeyboard) under the folder named "libraries" in your Arduino sketchbook folder. Create the folder "libraries" in case it does not exist yet. Copy all the files under libraries/DKeyboard to the target "DKeyboard" subfolder. This is a modified version of DKeyboard that slightly reduces its size so that it can be loaded to the Digispark ATTINY85 device. ATtiny85 presents itself to the PC as a keyboard USB HID.
    - Connect the Digispark to the PC via USB
    - Compile and load
    - if getting ["operator '*' has no left operand" in "usbdrv.h:662:33"](https://digistump.com/board/index.php?topic=2942.0), with an editor open *usbdrv.h* in the Arduino *libraries* directory (e.g., *Arduino\libraries\DKeyboard\usbdrv.h*) and replace `define USB_INTR_PENDING GIFR` with any value above 0x40, like `define USB_INTR_PENDING 0x41`.
    - Immediately after the code is successfully uploaded, remove the Digispark USB from the PC
    - Open a Notepad and put the Windows focus there (maximizing the Notepad window is also suggested)
    - Compile and load. If getting ["operator '*' has no left operand" in "usbdrv.h:662:33"](https://digistump.com/board/index.php?topic=2942.0), with an editor open *usbdrv.h* in the Arduino *libraries* directory (e.g., *Arduino\libraries\DKeyboard\usbdrv.h*) and replace `define USB_INTR_PENDING GIFR` with any value above 0x40, like `define USB_INTR_PENDING 0x41`.
    - Immediately after the code is successfully uploaded, remove the Digispark USB from the PC (to prevent interference of the emulated keyboard)
    - Open a Notepad and put the Windows focus there (maximizing the Notepad window is also suggested to prevent accidentally losing the focus)
    - Insert the USB to the PC (do not move the focus out of the Notepad window until the USB is connected)

    False errors of missing USB driver messages can occur with Windows (should be ignored). If no data is shown, increase KEYBOARD_DELAY timer.
  25. @Ircama Ircama revised this gist Aug 15, 2020. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -285,13 +285,13 @@ Notice that after the modification of the D- pull-up resistor, the Digispark boo
    ATtiny85 does not provide a native serial interface, but it can be generated via software:
    - [bit-bang two-way serial half-duplex (two pins)](https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkSoftSerial)
    - [bit-bang serial-out (one pin)](https://github.com/ArminJo/ATtinySerialOut)
    Both provide a TTL UART hardware interface (with one or two pins). If USB is required, they need a UART-USB converter.
    Both provide a TTL UART hardware interface (using one or two pins different from P3 and P4, used for USB). If the PC has a physical serial port, an external TTL-to-RS232 hardware interface is needed. If USB is required to connect a PC, an external UART-USB hardware converter is needed.

    Similarly to the UART serial port, USB monitoring can be emulated via a bit-bang software implementation of the USB serial port. DigiCDC, based on the [V-USB project](https://www.obdev.at/products/vusb), needs appropriate driver; it uses a software interrupt and needs no other timers or interrupts to be enabled in parallel to correctly work. Besides, to avoid USB problems, DigiCDC shall be started just after the microcontroller boot and shall be kept always active. It is slow and if you don't call a DigiCDC function (write, print, read, available, etc) every 10ms or less then you must throw in some *DigiCDC.refresh();* for the USB to keep alive - also replace your delays - ie. *delay(100);* with *DigiCDC.delays* ie. *DigiCDC.delay(100);*
    The above described options are the only ways to monitor a Digispark via Arduino "serial monitor".

    The only way to monitor an ATtiny85 via Arduino serial monitor is through an hardware TTL UART interface, or TTL UART to USB interface.
    Similarly to the UART serial port, USB monitoring can be emulated via a bit-bang software implementation of the provided USB interface, emulating a serial port. DigiCDC, based on the [V-USB project](https://www.obdev.at/products/vusb), needs appropriate driver; it uses a software interrupt and needs no other timers or interrupts to be enabled in parallel to correctly work. Besides, to avoid USB problems, DigiCDC shall be started just after the microcontroller boot and shall be kept always active. It is slow and if you don't call a DigiCDC function (write, print, read, available, etc) every 10ms or less then you must throw in some *DigiCDC.refresh();* for the USB to keep alive - also replace your delays - ie. *delay(100);* with *DigiCDC.delays* ie. *DigiCDC.delay(100);*

    In order to to limit the code size, the suggested method for debugging and monitoring is [emulating an USB keyboard](https://digistump.com/wiki/digispark/tutorials/digikeyboard) through the [DKeyboard library](https://github.com/Ircama/AtTinyTestIR/tree/master/libraries/DKeyboard), including all monitoring code within related *#define* so that it can be disabled when not needed. Avoid using punctuation and symbols in text strings (use just letters and numbers).
    In order to to limit the code size, the suggested method for debugging and monitoring is [emulating an USB keyboard](https://digistump.com/wiki/digispark/tutorials/digikeyboard) through the [DKeyboard library](https://github.com/Ircama/AtTinyTestIR/tree/master/libraries/DKeyboard). No software driver is needed for the PC. It is suggested to include all monitoring code within related *#define*, so that it can be disabled for normal operation, when not needed. Avoid using punctuation and symbols in text strings (use just letters and numbers).

    Example:

    @@ -332,8 +332,8 @@ void loop() {
    - Compile and load
    - if getting ["operator '*' has no left operand" in "usbdrv.h:662:33"](https://digistump.com/board/index.php?topic=2942.0), with an editor open *usbdrv.h* in the Arduino *libraries* directory (e.g., *Arduino\libraries\DKeyboard\usbdrv.h*) and replace `define USB_INTR_PENDING GIFR` with any value above 0x40, like `define USB_INTR_PENDING 0x41`.
    - Immediately after the code is successfully uploaded, remove the Digispark USB from the PC
    - Open a Notepad and put the Windows focus there
    - Insert the USB to the PC
    - Open a Notepad and put the Windows focus there (maximizing the Notepad window is also suggested)
    - Insert the USB to the PC (do not move the focus out of the Notepad window until the USB is connected)

    False errors of missing USB driver messages can occur with Windows (should be ignored). If no data is shown, increase KEYBOARD_DELAY timer.

    @@ -383,9 +383,9 @@ P5 (PB5) is the reset pin. Depending on the Digispark hardware, the reset functi

    Disabling the reset-function can be done through the RSTDISBL fuse via either ISP or HVSP programming (without High-voltage Serial Programmer), but cannot be done via Micronucleus bootloader. Enabling the reset needs an [High-voltage Serial Programmer](https://www.instructables.com/id/How-to-unlock-Digispark-ATtiny85-and-convert-it-to/) and cannot be done via ISP device (or Micronucleus bootloader).

    When reset is disabled, you get a full application pin. If reset is enabled, pin 5 resets the microcontroller if the voltage is lower than around 2.5V. Anyway [this pin can still be used as input](https://electronics.stackexchange.com/questions/195146/use-the-reset-pin-on-attiny85-as-input-with-voltage-divider) with *analogRead(0)* when staying over 3V. *analogRead(0)* values between 700 and 1023 are generaaly stable enough to be used for applications without generating unwanted resets. Notice that *0* is the pin number to read the reset pin via *analogRead*.
    When reset is disabled, you get a full application pin. If reset is enabled, pin 5 resets the microcontroller if the voltage is lower than around 2.5V. Anyway [this pin can still be used as input](https://electronics.stackexchange.com/questions/195146/use-the-reset-pin-on-attiny85-as-input-with-voltage-divider) with *analogRead(0)* when staying over 3V. *analogRead(0)* values between 620 and 1023 are generally safe to be used for applications without generating unwanted resets. Notice that *0* is the pin number to read the reset pin via *analogRead*.

    The reset pin has a 30 to 60 kOhm [internal pull-up resistor](https://electronics.stackexchange.com/questions/422895/does-attiny-reset-pin-need-a-resistor) and the default value read by *analogRead(0)* is a bit lower than 1023. Reading 1023 can be done through an external pull-up.
    The reset pin has a 30 to 60 kOhm [internal pull-up resistor](https://electronics.stackexchange.com/questions/422895/does-attiny-reset-pin-need-a-resistor) and the default value read by *analogRead(0)* is a bit lower than 1023 (empirically, 984 to 986, meaning about 96%). Reading 1023 can be done through an external pull-up.

    ## Note on analogRead
    The analog pins are referenced by their [analog port number](https://digistump.com/wiki/digispark/tutorials/basics), not the Digispark pins:
  26. @Ircama Ircama revised this gist Aug 15, 2020. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -388,13 +388,13 @@ When reset is disabled, you get a full application pin. If reset is enabled, pin
    The reset pin has a 30 to 60 kOhm [internal pull-up resistor](https://electronics.stackexchange.com/questions/422895/does-attiny-reset-pin-need-a-resistor) and the default value read by *analogRead(0)* is a bit lower than 1023. Reading 1023 can be done through an external pull-up.

    ## Note on analogRead
    The analog pins are referenced by their [analog port number](https://digistump.com/wiki/digispark/tutorials/basics), not their pin:
    The analog pins are referenced by their [analog port number](https://digistump.com/wiki/digispark/tutorials/basics), not the Digispark pins:

    ```c
    analogRead(1); //Read P2
    analogRead(2); //Read P4
    analogRead(3); //Read P3
    analogRead(0); //Read P5
    analogRead(1); // Read Digispark pin P2
    analogRead(2); // Read Digispark pin P4
    analogRead(3); // Read Digispark pin P3
    analogRead(0); // Read Digispark pin P5
    ```
    ## Note on LED
  27. @Ircama Ircama revised this gist Aug 15, 2020. 1 changed file with 36 additions and 21 deletions.
    57 changes: 36 additions & 21 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -101,19 +101,23 @@ Keep all directory tree.

    Then open a CMD to *micronucleus-master*:

    cd upgrade
    gem install libusb
    ruby generate-data.rb t85_default.hex
    ```bash
    cd upgrade
    gem install libusb
    ruby generate-data.rb t85_default.hex
    ```

    It generates *bootloader_data.c* in the *upgrade* directory.

    To compile it, the AVR compiler needs to be set in the path; it generally can be found at *C:\Program Files\Arduino\hardware\tools\avr\bin*.

    Open a Cygwin Bash to the *upgrade* directory

    export PATH=$PATH:/cygdrive/c/Program\ Files/Arduino/hardware/tools/avr/bin
    make clean
    make
    ```bash
    export PATH=$PATH:/cygdrive/c/Program\ Files/Arduino/hardware/tools/avr/bin
    make clean
    make
    ```

    Return to the CMD; run the following:

    @@ -144,8 +148,10 @@ This file includes comment notes describing the allowed configuration settings.

    Then run the following:

    make clean
    make CONFIG=t85_default
    ```bash
    make clean
    make CONFIG=t85_default
    ```

    A file named *main.hex* is generated

    @@ -157,9 +163,11 @@ You can then run *ruby generate-data.rb main.hex*; this can be also achieved wit

    Return to the cygwin shell; run the following:

    cd ../upgrade
    make clean
    make
    ```bash
    cd ../upgrade
    make clean
    make
    ```

    return to the CMD; run the following:

    @@ -203,25 +211,31 @@ For instance, set:

    Open a cygwin bash to the *micronucleus/firmware* directory (it should include a *Makefile*)

    export PATH=$PATH:/cygdrive/c/Program\ Files/Arduino/hardware/tools/avr/bin
    make clean
    make
    ```bash
    export PATH=$PATH:/cygdrive/c/Program\ Files/Arduino/hardware/tools/avr/bin
    make clean
    make
    ```

    A file named *main.hex* is generated

    Move *main.hex* to the *upgrade* directory

    You can then run *ruby generate-data.rb main.hex*; this can be also achieved with Windows: with a Windows CMD run the following:

    cd upgrade
    gem install libusb
    ruby generate-data.rb main.hex
    ```bash
    cd upgrade
    gem install libusb
    ruby generate-data.rb main.hex
    ```

    Return to the cygwin shell; run the following:

    cd ../upgrade
    make clean
    make
    ```bash
    cd ../upgrade
    make clean
    make
    ```

    return to the CMD; run the following:

    @@ -266,6 +280,7 @@ The Digispark ATtiny85 device has to be modified as follows to save power:
    Notice that after the modification of the D- pull-up resistor, the Digispark bootloader has to be flashed with "#define ENTRYMODE ENTRY_EXT_RESET" in micronucleus-master/firmware/configuration/t85_default/bootloaderconfig.h; then use the Digispark reset pin to enable the firmware upload. Setting ENTRYMODE to ENTRY_EXT_RESET avoids to hang the Digispark if D- is not pulled-up. A micro-switch between D5 and ground is appropriate, also pulling up D5 to VCC with a 22kohm resistor.

    # Notes

    ## Notes on serial monitoring
    ATtiny85 does not provide a native serial interface, but it can be generated via software:
    - [bit-bang two-way serial half-duplex (two pins)](https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkSoftSerial)
    @@ -280,7 +295,7 @@ In order to to limit the code size, the suggested method for debugging and monit

    Example:

    ```
    ```c
    #define USE_KEYBOARD
    #define KEYBOARD_DELAY 1500 // Time to wait for the PC keyboard driver to become ready

  28. @Ircama Ircama revised this gist Aug 15, 2020. 2 changed files with 3 additions and 5 deletions.
    7 changes: 3 additions & 4 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -238,10 +238,11 @@ The bootloader is flashed.
    A valid schematic diagram for the Digispark module is at this url:
    http://www.electroschematics.com/wp-content/uploads/2015/08/Circuit-Diagram-of-the-ATtiny85-USB-Mini-Development-Board.png

    The LED between the USB and 5V shall have the cathode (LED +) connected to +5V and the anode (LED –) connected with USB V+. The Digispark [schematic diagram](https://s3.amazonaws.com/digispark/DigisparkSchematicFinal.pdf) incorrectly inverts this LED.
    The diode between the USB and 5V shall have the cathode (+) connected to +5V and the anode (–) connected with USB V+. The Digispark [schematic diagram](https://s3.amazonaws.com/digispark/DigisparkSchematicFinal.pdf) incorrectly inverts this diode.

    Pinout:

    - https://neonaut.neocities.org/images/digispark-pinout.png
    - https://camo.githubusercontent.com/776b358cb7412939e03a65990fb36d0aa39e890f/687474703a2f2f6472617a7a792e636f6d2f652f696d672f50696e6f75745438352e706e67
    - https://github.com/SpenceKonde/ATTinyCore

    @@ -264,6 +265,7 @@ The Digispark ATtiny85 device has to be modified as follows to save power:

    Notice that after the modification of the D- pull-up resistor, the Digispark bootloader has to be flashed with "#define ENTRYMODE ENTRY_EXT_RESET" in micronucleus-master/firmware/configuration/t85_default/bootloaderconfig.h; then use the Digispark reset pin to enable the firmware upload. Setting ENTRYMODE to ENTRY_EXT_RESET avoids to hang the Digispark if D- is not pulled-up. A micro-switch between D5 and ground is appropriate, also pulling up D5 to VCC with a 22kohm resistor.

    # Notes
    ## Notes on serial monitoring
    ATtiny85 does not provide a native serial interface, but it can be generated via software:
    - [bit-bang two-way serial half-duplex (two pins)](https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkSoftSerial)
    @@ -362,7 +364,6 @@ ISR(PCINT0_vect) {
    ```

    ## Note on the RESET pin

    P5 (PB5) is the reset pin. Depending on the Digispark hardware, the reset function can be enabled or disabled. [The default hardware implementation should have it disabled](https://digistump.com/wiki/digispark/tutorials/programming); in this case, bootloaders can be upgraded (the Micronucleus bootloader works and sketches can be uploaded using the bootloader), but ISP programming is disabled (as ISP connection needs the enabled RESET function; notice that ISP programming can be done via ISP device or via an appropriately confugured Arduino or Digispark).

    Disabling the reset-function can be done through the RSTDISBL fuse via either ISP or HVSP programming (without High-voltage Serial Programmer), but cannot be done via Micronucleus bootloader. Enabling the reset needs an [High-voltage Serial Programmer](https://www.instructables.com/id/How-to-unlock-Digispark-ATtiny85-and-convert-it-to/) and cannot be done via ISP device (or Micronucleus bootloader).
    @@ -372,7 +373,6 @@ When reset is disabled, you get a full application pin. If reset is enabled, pin
    The reset pin has a 30 to 60 kOhm [internal pull-up resistor](https://electronics.stackexchange.com/questions/422895/does-attiny-reset-pin-need-a-resistor) and the default value read by *analogRead(0)* is a bit lower than 1023. Reading 1023 can be done through an external pull-up.

    ## Note on analogRead

    The analog pins are referenced by their [analog port number](https://digistump.com/wiki/digispark/tutorials/basics), not their pin:

    ```c
    @@ -383,5 +383,4 @@ analogRead(0); //Read P5
    ```
    ## Note on LED
    Depending on the hardware, the internal Digispark LED is connected to P1 in model A (most used), or on P0 in model B.
    1 change: 0 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    https://neonaut.neocities.org/images/digispark-pinout.png
  29. @Ircama Ircama revised this gist Aug 15, 2020. 2 changed files with 4 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -323,7 +323,7 @@ False errors of missing USB driver messages can occur with Windows (should be ig
    ## Note on sleep mode
    The following sample allows calling *sleep()* to enter sleep mode to the lowest power level. It puts the processor in quiescent mode and uses Pin 0 to resume from sleep.

    ```
    ```c
    #include <avr/sleep.h>
    #include <avr/interrupt.h>

    @@ -375,7 +375,7 @@ The reset pin has a 30 to 60 kOhm [internal pull-up resistor](https://electronic

    The analog pins are referenced by their [analog port number](https://digistump.com/wiki/digispark/tutorials/basics), not their pin:

    ```
    ```c
    analogRead(1); //Read P2
    analogRead(2); //Read P4
    analogRead(3); //Read P3
    @@ -384,4 +384,4 @@ analogRead(0); //Read P5
    ## Note on LED
    The internal Digispark LED is connected to PB1.
    Depending on the hardware, the internal Digispark LED is connected to P1 in model A (most used), or on P0 in model B.
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    https://neonaut.neocities.org/images/digispark-pinout.png
  30. @Ircama Ircama revised this gist Aug 14, 2020. 1 changed file with 75 additions and 2 deletions.
    77 changes: 75 additions & 2 deletions Digispark.md
    Original file line number Diff line number Diff line change
    @@ -264,14 +264,62 @@ The Digispark ATtiny85 device has to be modified as follows to save power:

    Notice that after the modification of the D- pull-up resistor, the Digispark bootloader has to be flashed with "#define ENTRYMODE ENTRY_EXT_RESET" in micronucleus-master/firmware/configuration/t85_default/bootloaderconfig.h; then use the Digispark reset pin to enable the firmware upload. Setting ENTRYMODE to ENTRY_EXT_RESET avoids to hang the Digispark if D- is not pulled-up. A micro-switch between D5 and ground is appropriate, also pulling up D5 to VCC with a 22kohm resistor.

    ## Notes on DigiCDC
    ## Notes on serial monitoring
    ATtiny85 does not provide a native serial interface, but it can be generated via software:
    - [bit-bang two-way serial half-duplex (two pins)](https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkSoftSerial)
    - [bit-bang serial-out (one pin)](https://github.com/ArminJo/ATtinySerialOut)
    Both provide a TTL UART interface (with one or two pins). If USB is required, they need a UART-USB converter.
    Both provide a TTL UART hardware interface (with one or two pins). If USB is required, they need a UART-USB converter.

    Similarly to the UART serial port, USB monitoring can be emulated via a bit-bang software implementation of the USB serial port. DigiCDC, based on the [V-USB project](https://www.obdev.at/products/vusb), needs appropriate driver; it uses a software interrupt and needs no other timers or interrupts to be enabled in parallel to correctly work. Besides, to avoid USB problems, DigiCDC shall be started just after the microcontroller boot and shall be kept always active. It is slow and if you don't call a DigiCDC function (write, print, read, available, etc) every 10ms or less then you must throw in some *DigiCDC.refresh();* for the USB to keep alive - also replace your delays - ie. *delay(100);* with *DigiCDC.delays* ie. *DigiCDC.delay(100);*

    The only way to monitor an ATtiny85 via Arduino serial monitor is through an hardware TTL UART interface, or TTL UART to USB interface.

    In order to to limit the code size, the suggested method for debugging and monitoring is [emulating an USB keyboard](https://digistump.com/wiki/digispark/tutorials/digikeyboard) through the [DKeyboard library](https://github.com/Ircama/AtTinyTestIR/tree/master/libraries/DKeyboard), including all monitoring code within related *#define* so that it can be disabled when not needed. Avoid using punctuation and symbols in text strings (use just letters and numbers).

    Example:

    ```
    #define USE_KEYBOARD
    #define KEYBOARD_DELAY 1500 // Time to wait for the PC keyboard driver to become ready
    #ifdef USE_KEYBOARD
    #include "DKeyboard.h" // Use a modified tiny DigisparkKeyboard library
    DKeyboardDevice Db = DKeyboardDevice(); // instantiate the Keyboard driver
    #endif
    void setup() {
    ...
    #ifdef USE_KEYBOARD
    Db.sendKeyStroke(0);
    Db.delay(KEYBOARD_DELAY); // This is needed to wait for the PC keyboard driver to become ready
    Db.sendKeyStroke(0); // This will ensure no character will be lost
    #endif
    ...
    }
    void loop() {
    ...
    #ifdef USE_KEYBOARD
    Db.print("Value result is ");
    Db.println(value);
    Db.print("Hex value is ");
    Db.println(hexvalue, HEX);
    Db.delay(300); // ensure that the transmission is performed before the interrupt is turned off
    #endif
    ...
    }
    ```

    - Create a new folder called [DKeyboard](https://github.com/digistump/DigistumpArduino/tree/master/digistump-avr/libraries/DigisparkKeyboard) under the folder named "libraries" in your Arduino sketchbook folder. Create the folder "libraries" in case it does not exist yet. Copy all the files under libraries/DKeyboard to the target "DKeyboard" subfolder. This is a modified version of DKeyboard that slightly reduces its size so that it can be loaded to the Digispark ATTINY85 device. ATtiny85 presents itself to the PC as a keyboard USB HID.
    - Connect the Digispark to the PC via USB
    - Compile and load
    - if getting ["operator '*' has no left operand" in "usbdrv.h:662:33"](https://digistump.com/board/index.php?topic=2942.0), with an editor open *usbdrv.h* in the Arduino *libraries* directory (e.g., *Arduino\libraries\DKeyboard\usbdrv.h*) and replace `define USB_INTR_PENDING GIFR` with any value above 0x40, like `define USB_INTR_PENDING 0x41`.
    - Immediately after the code is successfully uploaded, remove the Digispark USB from the PC
    - Open a Notepad and put the Windows focus there
    - Insert the USB to the PC

    False errors of missing USB driver messages can occur with Windows (should be ignored). If no data is shown, increase KEYBOARD_DELAY timer.

    ## Note on sleep mode
    The following sample allows calling *sleep()* to enter sleep mode to the lowest power level. It puts the processor in quiescent mode and uses Pin 0 to resume from sleep.

    @@ -312,3 +360,28 @@ ISR(PCINT0_vect) {
    }
    #endif
    ```

    ## Note on the RESET pin

    P5 (PB5) is the reset pin. Depending on the Digispark hardware, the reset function can be enabled or disabled. [The default hardware implementation should have it disabled](https://digistump.com/wiki/digispark/tutorials/programming); in this case, bootloaders can be upgraded (the Micronucleus bootloader works and sketches can be uploaded using the bootloader), but ISP programming is disabled (as ISP connection needs the enabled RESET function; notice that ISP programming can be done via ISP device or via an appropriately confugured Arduino or Digispark).

    Disabling the reset-function can be done through the RSTDISBL fuse via either ISP or HVSP programming (without High-voltage Serial Programmer), but cannot be done via Micronucleus bootloader. Enabling the reset needs an [High-voltage Serial Programmer](https://www.instructables.com/id/How-to-unlock-Digispark-ATtiny85-and-convert-it-to/) and cannot be done via ISP device (or Micronucleus bootloader).

    When reset is disabled, you get a full application pin. If reset is enabled, pin 5 resets the microcontroller if the voltage is lower than around 2.5V. Anyway [this pin can still be used as input](https://electronics.stackexchange.com/questions/195146/use-the-reset-pin-on-attiny85-as-input-with-voltage-divider) with *analogRead(0)* when staying over 3V. *analogRead(0)* values between 700 and 1023 are generaaly stable enough to be used for applications without generating unwanted resets. Notice that *0* is the pin number to read the reset pin via *analogRead*.

    The reset pin has a 30 to 60 kOhm [internal pull-up resistor](https://electronics.stackexchange.com/questions/422895/does-attiny-reset-pin-need-a-resistor) and the default value read by *analogRead(0)* is a bit lower than 1023. Reading 1023 can be done through an external pull-up.

    ## Note on analogRead

    The analog pins are referenced by their [analog port number](https://digistump.com/wiki/digispark/tutorials/basics), not their pin:

    ```
    analogRead(1); //Read P2
    analogRead(2); //Read P4
    analogRead(3); //Read P3
    analogRead(0); //Read P5
    ```

    ## Note on LED

    The internal Digispark LED is connected to PB1.