Arduino Nano ピン配置
ハードウェアの基本動作確認用にArduino Nano使用
中華版Arduino Nano
原因は以下のbrlttyデーモン
BRLTTY
https://brltty.app/
BRLTTYは点字に関わるバックグラウンドデーモンのため必要なければ削除して対応。
$ sudo apt remove btltty
アップロード時のエラーメッセージ
注) Tx,Rx端子が他のデバイスに接続されてる場合にも表示されます。
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
...
下記のループバックテストは廉価版のCH340 USB to serial chipが実装されている場合は無効。
ブートローダをArduino UNO経由でArduino Nanoに書き込む作業が必要。
接続図
上記Arduino UNOをUSBでPCに接続して以下のプロセスを実行(書き込みのプロセスが表示されるよう Preference > Show verbose output during にはチェックを入れた方が良いでしょう)。
ボードの選択
Tools > Board, for example Tools > Board > Arduino AVR Boards > Arduino Uno.
ポートの選択
Tools > Port
ブートローダ用スケッチの読み込み
File > Examples > 11.ArduinoISP > ArduinoISP
スケッチのアップロード
これでArduino UNOがブートローダのプログラマーになるので、この状態で書き込み先のArduino Nanoを Tools > Boardから選択します。
プログラマーを指定
Tools > Programmer > Arduino as ISP
書き込み
Tools > Burn Bootloader
終了すると以下のメッセージが表示されます。
......
......
avrdude done. Thank you.
マイコンボードのUSB-Serialチップデバイスの登録が必要です。
99-platformio-udev.rules — PlatformIO latest documentation
マイコンボードのUSB-Serialチップデバイスの VID(Vender ID) と PID(Product ID) は、VSCodeのPlatformIOのターミナル(新規ターミナル)から以下のコマンドで確認できます。
pio device list — PlatformIO latest documentation
$ pio device list
/dev/cu.SLAB_USBtoUART
----------
Hardware ID: USB VID:PID=10c4:ea60 SNR=0001
Description: CP2102 USB to UART Bridge Controller
/dev/cu.uart-1CFF4676258F4543
----------
Hardware ID: USB VID:PID=451:f432 SNR=1CFF4676258F4543
Description: Texas Instruments MSP-FET430UIF
デバイスルールのダウンロードとコピー
$ curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
udev(userspace dev)サービスの再起動
$ sudo service udev restart
現ユーザをグループdialout, plugdevへ追加 (再ログインが必要)
$ sudo usermod -a -G dialout $USER
$ sudo usermod -a -G plugdev $USER
Arduino Nanoでプロジェクトを作成する場合のボードの選択は、新規にブートローダをアップロードしたため下記のデバイスとします。
Arduino Nano ATmega328 (New Bootloader) — PlatformIO latest documentation
platformio.ini
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:nanoatmega328new]
platform = atmelavr
board = nanoatmega328new
framework = arduino