はじめに
amazonで購入したArduino Nano 互換ボードをplatform ioで動かしてみました.
PC&ソフトウェア 環境
ubuntu20.04
PlatformIO Core, version 6.1.5
内容
- install
sudo apt install python3-pip
sudo pip3 install -U platformio
下記内容を実施することで使用できます.
- ワークスペースの作成
mkdir ws
platformio init --board=uno
- プログラムの作成
vim ./src/main.cpp
main.cpp
/*
ピンリスト
0 TX
1 RX
2
3 pwm
4
5 pwm
6 pwm
7
8
9 pwm
10 pwm
11 pwm
12
13
14 A0
15 A1
16 A2
17 A3
18 A4
19 A5
*/
#include <Arduino.h>
#define LED_PIN 13
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.println("Hello Arduino");
digitalWrite(LED_PIN, HIGH); delay(1000);
digitalWrite(LED_PIN, LOW); delay(1000);
}
- build & upload
pio run -t upload
動いた!
参考
追記
こちらのarduino nano互換ボードだとboard名の指定がunoだと失敗.
ワークスペース作成時
pio init --board nanoatmega328
build設定ファイルは以下のようにきさい
platformio.ini
[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
CH340
type cのarduinoはCH340 usb serialデバイス基板があり,ubuntu22.04で認識するためには,下記コマンドを実行する必要があった.
sudo apt remove brltty
sudo udevadm control --reload
参考: https://qiita.com/74th/items/f46bccd67b2ed6fc867f
serialデバッグ
pio device monitor -b 115200
pio device monitor -b 9600
エラー & 修正方法
デバイスが認識しない or upload時にrulesのインストールを求められる.
- rulesインストールの警告
Warning! Please install `99-platformio-udev.rules`.
More details: https://docs.platformio.org/en/latest/core/installation/udev-rules.html
- 対策
警告のurlにある説明を実行.
rulesのインストール
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をrestart
sudo service udev restart
デバイスは認識するが,書き込みに失敗する
下記警告が出て、書き込めない
Uploading .pio/build/uno/firmware.hex
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
boardにuno
を指定した場合,追記で記載しているnanoatmega328
をboardに指定して試す.