Gopher Arcadeの改良とプログラムの書き込み
はじめに
Gopher ArcadeはCONEJOさんが作成したTinyGoで簡単なゲームが動く基板です。

CONEJOさんによるGopher Arcadeを紹介する記事は以下です。
TinyGo ConfにもCONEJOさんが持ってきてくれてはんだづけをしました。
レポジトリはこちらです。
CONEJOさんが参考にしたオリジナルの基板はおそらくこちらです。
今回はこの基板をちょっと改良したVersionを紹介します。
改良
CONEJOさんが作成されたオリジナルのVersionでは音を鳴らすブザーに CPT-1203-78-SMT-TR という部品が使われていました。
またこのブザーのために SN7LVC2G04DBVR というICも必要でした。
この部品は秋月電子などで売っておらずDigikeyから購入する必要があり、ちょっと入手が大変なので秋月で売っていていつも使っているブザーに変更しました。
またオリジナルはKailh chocのキースイッチを使っていましたが、交換できるようにCherry MXにしました。
なお交換できる必要性があるかは不明です。


ガーバーデータができたらJLCPCBに発注しました。
プログラムの書き込み
JLCPCBから基板が届いたら部品をはんだづけします。はんだづけをしたらプログラムの書き込みます。
USBASPのAVRライターを持っていなかったので、使っていなかったArduino nanoを書き込み機にすることにしました。
ArduinoIDEを開いてPCに接続したArduinoに、exampleフォルダにあるArduinoISPのスケッチを書き込みます。

スケッチを書き込んだら、ArduinoとGopher Arcadeを接続します。
接続は以下の通りにする必要があります。
| Arduino | ATtiny85 |
|---|---|
| 5V | 8(VCC) |
| GND | 4(GND) |
| D11 | 5(MOSI) |
| D12 | 6(MISO) |
| D13 | 7(SCK) |
| D10 | 1(RESET) |
Gopher Arcadeの左上の6Pinは左からAttinyの5V, 5, 6, 7, 1, GNDと接続されるので、ArduinoのピンをGopher Arcadeと接続します。

ピンを接続したら、ArduinoIDEでブートローダーを書き込みます。
以下の設定でBurn Bootloaderをクリックします。

配線に問題がなければ正常にブートローダーがが着込まれます。

この時ArduinoIDEで書き込みのログに以下のような書き込みコマンドが出力されるので、コピーして控えておきます。
/home/satoken/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/bin/avrdude -C/home/satoken/.arduino15/packages/ATTinyCore/hardware/avr/1.5.2/avrdude.conf -v -pattiny85 -cstk500v1 -P/dev/ttyUSB0 -b19200 -e -Uefuse:w:0xFF:m -Uhfuse:w:0b11010111:m -Ulfuse:w:0xE2:m -Uflash:w:/home/satoken/.arduino15/packages/ATTinyCore/hardware/avr/1.5.2/bootloaders/empty/empty_all.hex:i
次にTinyGoプログラムをビルドするためにまずCONEJOさんのレポジトリをgit cloneします。
$ git clone https://github.com/conejoninja/arcade.git
ディレクトリを移動します。
$ cd arcade
以下のcommitのtargets/gopher-arcade.jsonの内容をコピーして、gopher-arcade.jsonとして保存します。
次に同じcommitのsrc/machine/board_gopher-arcade.goの内容をコピーします。
tinygo envコマンドを実行して出力された、TINYGOROOTのディレクトリ/src/machine以下にsrc/machine/board_gopher-arcade.goのファイルを作成して内容を保存します。
私の場合は、/usr/local/lib/tinygo/src/machine/board_gopher-arcade.go ファイルを作成してコピーした内容を保存しました。
プログラムをビルドします。
$ tinygo build --target ./gopher-arcade.json --size short -o snake.hex .
プログラムがビルドできたら、先程メモしておいたArduinoの書き込みコマンドの書き込むプログラムをtinygo buildでビルドしたHEXファイルにして書き込みます。
$ /home/satoken/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/bin/avrdude -C/home/satoken/.arduino15/packages/ATTinyCore/hardware/avr/1.5.2/avrdude.conf -v -pattiny85 -cstk500v1 -P/dev/ttyUSB0 -b19200 -Uflash:w:./snake.hex:i
avrdude: Version 6.3-20201216
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/home/satoken/.arduino15/packages/ATTinyCore/hardware/avr/1.5.2/avrdude.conf"
User configuration file is "/home/satoken/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : /dev/ttyUSB0
Using Programmer : stk500v1
Overriding Baud Rate : 19200
Setting bit clk period : 5.0
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 12 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 2 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: safemode: lfuse reads as E2
avrdude: safemode: hfuse reads as D7
avrdude: safemode: efuse reads as FF
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 "./snake.hex"
avrdude: writing flash (5776 bytes):
Writing | ################################################## | 100% 8.01s
avrdude: 5776 bytes of flash written
avrdude: verifying flash memory against ./snake.hex:
avrdude: load data flash data from input file ./snake.hex:
avrdude: input file ./snake.hex contains 5776 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 3.82s
avrdude: verifying ...
avrdude: 5776 bytes of flash verified
avrdude: safemode: lfuse reads as E2
avrdude: safemode: hfuse reads as D7
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:D7, L:E2)
avrdude done. Thank you.
プログラムが正常に書き込まれるとスネークゲームが開始されます。

おわりに
ということでCONEJOさんが作成された、Gopher Arcadeをちょっと変えてプログラムを書き込む方法を紹介しました。
ぜひイベントなどで見かけた際は手にとって遊んでみてください。
Discussion