1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pioarduino IDE (PlatformIO)でpymcuprogを使ってATtiny202に書き込む方法

Last updated at Posted at 2025-08-15

概要

Visual Studio CodeでPlatformIOを使用して、pymcuprogを介してATtiny202に書き込む手順を説明します。

ATtiny202以外のtinyAVR® 0系統は同様の手順で書き込みが可能です。おそらく1系統と2系統も可能だと思います。

UPDI (Unified Program and Debug Interface) は、MicrochipのtinyAVR®マイコン向けに設計されたプログラミングおよびデバッグインターフェースです。
UPDI Friendなどを購入するか、USBシリアル変換モジュールを使って自作することも可能です。

ネット上には同様の記事がありますが、pythonの仮想環境を使っているところが相違点です。

環境

プロジェクト作成

Copilotを使いたいので、Visual Studio Code上で開発することを前提としています。拡張機能でpioarduinoをインストールしておきます。(PlatformIOでもよいですが、ESP32方面でいろいろ困るので変えました。)

Arduino IDEは2.x系では未対応なので1.x系を使用することになります。私は古いバージョンを使い続けることに抵抗を感じます。Copilotも使いたいのでVScodeを選びました。

プロジェクトを作成します。

article022_img1.png

UPDI書き込み作成

秋月電子通商 ATtiny202 DIP化キットに合わせて、6ピンで繋げられるように作成しました。

動作確認用にLチカしたいので、適当なLEDと抵抗も追加しました。

安定しない場合は、電源に10μF〜程度のコンデンサを追加するとよいでしょう。

article022_img2.png

pymcuprog インストール

Pythonの仮想環境にvenvを使ってpymcuprogをインストールします。

$ python3.13 -m venv .venv
$ source .venv/bin/activate
$ pip install pymcuprog

ATTiny202をUPDIで接続します。pymcuprogを使ってpingコマンドで接続確認を行います。

$ pymcuprog ping -t uart -u /dev/tty.usbserial-110 -d attiny202 -c 57600
Connecting to SerialUPDI
Pinging device...
Ping response: 1E9123
Done.

platformio.ini 編集

platformio.iniを編集して、pymcuprogを使うように設定します。こちらに書き方のサンプルがあります。このまですとpython仮想環境を使わないので、以下のように書き換えます。

upload_portはマシン環境に合わせます。

--verify--eraseはオプションです。フラッシュメモリの状態によってはベリファイが失敗することがあります。対策として、フラッシュメモリを消去してから書き込みを行ってます。

upload_commandでは、source ./.venv/bin/activateで仮想環境を有効化してから、pymcuprogを実行します。

platformio.ini
[env:ATtiny202]
platform = atmelmegaavr
board = ATtiny202
framework = arduino
board_build.f_cpu=20000000L
upload_protocol = custom
upload_port = /dev/tty.usbserial-110
upload_speed = 57600
upload_flags =
    --tool
    uart
    --device
    attiny202
    --uart
    $UPLOAD_PORT
    --clk
    $UPLOAD_SPEED
    --verify
    --erase
upload_command = source ./.venv/bin/activate && pymcuprog write $UPLOAD_FLAGS --filename $SOURCE

Lチカ

テストプログラムです。delayの代わりに_delay_msを使うと、ビルド後のコードサイズが小さくなります。ATtiny202はFlashが2KBしかないので、できるだけ小さくしたいところです。

#include <Arduino.h>
#include <util/delay.h>

const uint8_t check_led = PIN_PA3;

void setup() {
  pinMode(check_led, OUTPUT);
  digitalWrite(check_led, LOW);
}

void loop() {
  digitalWrite(check_led, LOW);
  _delay_ms(1000);
  digitalWrite(check_led, HIGH);
  _delay_ms(1000);
}

まとめ

書き込みしLチカしたら成功です。お疲れ様でした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?