ATtiny85にブートローダーを書き込む


digisparkという製品が有ります。
この製品はATtiny85にmicronucleusブートローダを書き込んで、周辺回路を追加しUSB経由でスケッチが書き込める製品です。
1年ほど前に写真の様な製品(Programmer Board)を入手し、ずっと放置していましたが、DipパッケージのATtiny85にブートローダを書き込んで
USB経由でスケッチの書き込みができるようになりました。


最初にdigisparkの開発環境を揃えます。
digisparkの開発環境については色々なところで紹介されていますので、詳細はそちらに譲りますが、
ざっくり書くと以下の手順です。

ボードマネージャを使って、Digistump AVR Boardを追加する。
Windows用のUSBドライバーをインストールする。
この部分は余り情報が有りませんでしたので、以下の手順でインストールしました。
こ ち らからDigistump.Drivers.zipをダウンロードして展開する。
・展開先にある「DPinst64.exe」を管理者として実行してインストールする。
・インストール後にdigisparkをUSBポートに刺すと、以下のデバイスが出現します。


digisparkへの書き込みについても色々なところで紹介されていますが、スケッチ書き込み時にUSBは抜いておいて、
> Please plug in the device ...
> Press CTRL+C to terminate the program.
のメッセージが表示されてから、USBを入れるのがポイントです。



本題のブートローダ書き込みですが、まずはこちらから一式ダウン ロードして適当な場所に展開します。
次に、開発環境のパスを確認します。
Arduinio-IDEの
ファイル→環境設定→より詳細な情報を表示する
で「書き込み」にチェックを入れます。


次に、適当なスケッチをArduinoISP経由でATtiny85に書き込みます。
以下のメッセージが表示されます。
C:\Users\user\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\user\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -pattiny85 -cstk500v1 -PCOM5 -b19200 -Uflash:w:C:\Users\user\AppData\Local\Temp\arduino_build_224837/blink.ino.hex:i

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\user\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATtiny85
         Chip Erase delay              : 400000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    12     4    0 no        512    4      0  4000  4500 0xff 0xff
           flash         65     6    32    0 yes      8192   64    128 30000 30000 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e930b (probably t85)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "C:\Users\user\AppData\Local\Temp\arduino_build_224837/blink.ino.hex"
avrdude: writing flash (1970 bytes):

Writing | ################################################## | 100% 2.77s

avrdude: 1970 bytes of flash written
avrdude: verifying flash memory against C:\Users\user\AppData\Local\Temp\arduino_build_224837/blink.ino.hex:
avrdude: load data flash data from input file C:\Users\user\AppData\Local\Temp\arduino_build_224837/blink.ino.hex:
avrdude: input file C:\Users\user\AppData\Local\Temp\arduino_build_224837/blink.ino.hex contains 1970 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.34s

avrdude: verifying ...
avrdude: 1970 bytes of flash verified

avrdude done.  Thank you.


赤字の部分はArduinoの導入環境により変わります。
赤字の部分をコピーして、Windowsのコマンドプロンプトから実行すると、再度同じスケッチを書き込むことができます。
C:\Users\user\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\user\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -pattiny85 -cstk500v1 -PCOM5 -b19200 -Uflash:w:C:\Users\user\AppData\Local\Temp\arduino_build_224837/blink.ino.hex:i

上の赤字の部分をブートローダのフルパスに変更します。
また青字の部分を追加します。
C:\Users\user\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\user\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -pattiny85 -cstk500v1 -PCOM5 -b19200 -Uflash:w:C:\micronucleus-master\firmware\releases\t85_default.hex:i -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m

このコマンドをWindowsのコマンドプロンプトから実行するとブートローダが書き込まれます。



ブートローダが書き込まれたATtiny85をProgrammer Boardにセットします。
矢印の場所が1番ピンになります。


ATtiny85のピンは8ピンヘッダーの以下の位置に出ています。
P3
P4
Gnd
P5
P0
P2
5V
P1

これで、DipパッケージのATtiny85がdigisparkと同じになります。
digisparkと同じ手順で以下のスケッチを書き込むと、P0からP4に接続したLEDがLチカします。
/*
digisparkのPin Map

All pins can be used as Digital I/O
Pin 0 → I2C SDA, PWM (LED on Model B)
Pin 1 → PWM (LED on Model A)
Pin 2 → I2C SCK, Analog In
Pin 3 → Analog In (also used for USB+ when USB is in use)
Pin 4 → PWM, Analog (also used for USB- when USB is in use)
Pin 5 → Analog In
*/

int numpin = 5;

void setup() {
    //All pins are capable of Digital output, though P5 is 3 V at HIGH instead of 5 V
    for(int i=0;i<numpin;i++)
    pinMode(i, OUTPUT); //0 is P0, 1 is P1, 2 is P2, etc. - unlike the analog inputs, for digital outputs the pin number matches.
}

void loop() {
  for(int i=0;i<numpin;i++) {
    digitalWrite(i,HIGH); //Turn the pin HIGH (5 V)
    delay(1000);
    digitalWrite(i,LOW); //Turn the pin LOW (GND)
    delay(1000);
  }
}

こ ちらにATtiny84へのブートローダーの書き込みが紹介されています。
ATtiny84用のProgrammer Boardを探していますが、見つけることができません。