UNO
概要
Windows10 + Windows Subsystem for Linuxの環境に、Arduino Unoで動作する、TinyGoをインストールしました。
Windows用のGetting Startedによると、Windowsでは、Windows Subsystem for Linux (WSL)上で、Linuxのインストールに従うよう指示がありました。このため、基本的にはLinux(Ubuntu)での動作確認と同じだと思います。
環境
上記のページによると、
You must have Go v1.11+ already installed on your machine in order to install TinyGo. We recommend Go v1.12+
とのことでした。また、AVR関連のツールも必要とのことなので、以下の環境で試しました。
ソフトウェア |
バージョン |
OS |
Windows10 + Windows Subsystem for Linux(Ubuntu 18.04.3 LTS) |
GoLang |
go version go1.12.9 linux/amd64 |
gcc-avr |
5.4.0+Atmel3.6.0-1build1 amd64 |
avr-libc |
2.0.0+Atmel3.6.0-1 all |
avrdude |
6.3-4 all |
インストール
TinyGo
TinyGo の通りですが、以下の通りインストールしました。
1
2
|
$ wget https://github.com/tinygo-org/tinygo/releases/download/v0.7.1/tinygo_0.7.1_amd64.deb
$ sudo dpkg -i tinygo_0.7.1_amd64.deb
|
TinyGoの実行ファイルは、/usr/local/tinygo/bin にインストールされるので、PATHを修正します。例えば、~/.bashrc に、以下を追加します。
1
|
PATH=$PATH:/usr/local/tinygo/bin
|
インストール後、バージョンを確認したら、当たり前ですが、以下の通りでした。
1
2
|
$ tinygo version
tinygo version 0.7.1 linux/amd64
|
ttyへのアクセス
PCからArduinoにスケッチを転送するavrdudeを正しく実行するためには、Arduinoを接続しているttyに対して、アクセス権が必要です。
WindowsでCOMnに対応するポートは、WSLでは、/dev/ttySn に対応します。私のArduino Unoは、COM3に接続されているので、/dev/ttyS3に対するアクセス権が必要でした。/dev/ttyS3のアクセス権を見てみると、以下のようになっていました。
1
2
|
$ ls -l /dev/ttyS3
crw-rw---- 1 root dialout 4, 67 Aug 30 21:09 /dev/ttyS3
|
このデバイスへのアクセス権を獲得するには、(1)デバイスのオーナーもしくはグループを変更する、(2)dialoutグループにユーザを登録する、(3)othersに対してアクセス権を与える、のどれかが必要ですが、(2)のdialoutグループにユーザを登録する方法をとりました。USERNAMEは自分のユーザ名に変更してください。
1
|
$ sudo usermod -aG dialout USERNAME
|
サンプルプログラムの書き込み
TinyGoには、いくつかのサンプルプログラムが付属しています。いわゆる、「Lチカ」を実行する、blinky1 というプログラムをArduino Unoで実行してみます。
実行結果は以下の通りです。デフォルトのポートは、/dev/ttyACM0 なので、今回利用するポート(/dev/ttyS3)を、-port で指定しています。
失敗編
最初、プログラムを書き込もうとしたら、以下のようにエラーとなってしまいました。
ArduinoのRXランプは一瞬光るのですが、TXランプは光らず、タイムアウトしているようです。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
$ tinygo flash -port /dev/ttyS3 -target arduino examples/blinky1
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
avrdude done. Thank you.
error: failed to flash /tmp/tinygo711125498/main.hex: exit status 1
$
|
avrdudeについて、調べてみましたが、よくわかりませんでした。
成功編
通常のArduino IDEから書き込めるかを試してみたところ、問題なく書き込むことができました。その後、再度、tinygoを実行してみると、今度は書き込みに成功しました。
ただし、ArduinoをPCから抜いてしまうと、再度書き込みができなくなってしまいました。
このあたりの原因はよくわかっていないので、ご存知の方がいらっしゃれば、ぜひ教えて下さい。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
$ tinygo flash -port /dev/ttyS3 -target arduino examples/blinky1
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e950f (probably m328p)
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 "/tmp/tinygo241702212/main.hex"
avrdude: input file /tmp/tinygo241702212/main.hex auto detected as Intel Hex
avrdude: writing flash (690 bytes):
Writing | ################################################## | 100% 0.13s
avrdude: 690 bytes of flash written
avrdude: verifying flash memory against /tmp/tinygo241702212/main.hex:
avrdude: load data flash data from input file /tmp/tinygo241702212/main.hex:
avrdude: input file /tmp/tinygo241702212/main.hex auto detected as Intel Hex
avrdude: input file /tmp/tinygo241702212/main.hex contains 690 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.10s
avrdude: verifying ...
avrdude: 690 bytes of flash verified
avrdude done. Thank you.
$
|
これにより、Arduino内蔵LEDが、0.5秒ごとに点滅しました。
バージョン
Hardware: | Arduino Uno |
Software: | TinyGo 0.7.1 |
最終更新日
January 23, 2021