« micro:bit MBED開発ツール(VScode+PlatformIO) | トップページ | NXP LPC1768 mbed開発ツール »

2020年1月 3日 (金)

Arduino Uno 開発ツール

2020/1/3

Arduino Uno tool (VScode+PlatformIO)

Arduino Uno tool (VScode+PlatformIO)

概要

Arduino Unoボードの開発ツールとして、VScodeの拡張としてPlatformIOを導入して、そのなかで開発ツール(コンパイラ、リンカ、アップローダー)をインストールする。 ここでは、linux環境でのインストール方法について説明する。

準備

ツールをインストール前に環境整備として以下を設定する:
(1)Python 2.7またはPython 3.5+のインストール

sudo apt-get install python3

(2)udevのruleの設定

curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules sudo service udev restart sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER

開発ツールのインストール

上の準備が終わったら、プロセッサとボードの種類は異なるが、インストール方法が分かりやすいので、以下を参考にインストールする。:
https://www.media.lab.uec.ac.jp/?page_id=1414
ESP32をVSCodeとPlatformIO IDEで動かす方法

新しいプロジェクトを作り、その際、今回の場合、Boardとして、
「Arduino Uno」を選択し、Frameworkとして
「Arduino」を選択して Nameに任意の名前を入力して[Finish]をクリックする。
(このNameはプロジェクト名かつフォルダ名になる)

ここでは、汎用的なボード名として「Arduino Uno」にしたが、使用したいボード名がボードリストに存在しているようなら、そのボード名を選択する。

その後、必要なツールのインストールが開始するが、完了後、platform.iniの内容に以下が含まれることを確認する。

platform = atmelavr board = uno framework = arduino

IDE設定

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:uno] platform = atmelavr board = uno framework = arduino upload_protocol = arduino

ビルドテストのためのサンプルプログラム

arduinoのスケッチに「#include <Arduino.h>」を追加しただけで、大抵は動作するようだ。
2つのスケッチを#defineで切り替えるようにしたサンプル:

#include <Arduino.h> #define BLINKY //#define ASCII_TABLE #ifdef BLINKY /* Blink Turns an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to the correct LED pin independent of which board is used. If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at: https://www.arduino.cc/en/Main/Products modified 8 May 2014 by Scott Fitzgerald modified 2 Sep 2016 by Arturo Guadalupi modified 8 Sep 2016 by Colby Newman This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Blink */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } #endif //========================================================================= #ifdef ASCII_TABLE /* ASCII table Prints out byte values in all possible formats: - as raw binary values - as ASCII-encoded decimal, hex, octal, and binary values For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII The circuit: No external hardware needed. created 2006 by Nicholas Zambetti <http://www.zambetti.com> modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ASCIITable */ void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); } // first visible ASCIIcharacter '!' is number 33: int thisByte = 33; // you can also write ASCII characters in single quotes. // for example, '!' is the same as 33, so you could also use this: // int thisByte = '!'; void loop() { // prints value unaltered, i.e. the raw binary version of the byte. // The Serial Monitor interprets all bytes as ASCII, so 33, the first number, // will show up as '!' Serial.write(thisByte); Serial.print(", dec: "); // prints value as string as an ASCII-encoded decimal (base 10). // Decimal is the default format for Serial.print() and Serial.println(), // so no modifier is needed: Serial.print(thisByte); // But you can declare the modifier for decimal if you want to. // this also works if you uncomment it: // Serial.print(thisByte, DEC); Serial.print(", hex: "); // prints value as string in hexadecimal (base 16): Serial.print(thisByte, HEX); Serial.print(", oct: "); // prints value as string in octal (base 8); Serial.print(thisByte, OCT); Serial.print(", bin: "); // prints value as string in binary (base 2) also prints ending line break: Serial.println(thisByte, BIN); // if printed last visible character '~' or 126, stop: if (thisByte == 126) { // you could also use if (thisByte == '~') { // This loop loops forever and does nothing while (true) { continue; } } // go on to the next character thisByte++; } //================================================ #endif

build/upload

(1)ボードとホストPCをUSBケーブルで接続する。
(2)VScode画面の最下行にあるアイコンからBuidのアイコンをクリックしてビルド実行する。
(3)VScode画面の最下行にあるアイコンからUploadのアイコンをクリックしてアップロード(ボードへのプログラム書込)を実行する。
注意:SerialMoniter画面に切り替えている場合、その画面で、Ctrl+Cを押して、事前に閉じる必要がある。
(4)書き込み終了後、必要があればボードの[reset]ボタンを押して書き込んだプログラムを起動する。

build出力ログ例:

> Executing task in folder ArduinoUno_Blinky: platformio run < Processing uno (platform: atmelavr; board: uno; framework: arduino) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html PLATFORM: Atmel AVR 2.0.0 > Arduino Uno HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash PACKAGES: framework-arduino-avr 5.0.0, toolchain-atmelavr 1.50400.190710 (5.4.0) LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Found 5 compatible libraries Scanning dependencies... No dependencies Building in release mode Checking size .pio/build/uno/firmware.elf Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" DATA: [ ] 0.4% (used 9 bytes from 2048 bytes) PROGRAM: [ ] 2.9% (used 930 bytes from 32256 bytes) ===== [SUCCESS] Took 0.58 seconds ===== Terminal will be reused by tasks, press any key to close it.

upload出力ログ例:

> Executing task in folder ArduinoUno_Blinky: platformio run --target upload < Processing uno (platform: atmelavr; board: uno; framework: arduino) ------------------------------------------------------------------- Verbose mode can be enabled via `-v, --verbose` option CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html PLATFORM: Atmel AVR 2.0.0 > Arduino Uno HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash PACKAGES: framework-arduino-avr 5.0.0, toolchain-atmelavr 1.50400.190710 (5.4.0), tool-avrdude 1.60300.190424 (6.3.0) LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf LDF Modes: Finder ~ chain, Compatibility ~ soft Found 5 compatible libraries Scanning dependencies... No dependencies Building in release mode Checking size .pio/build/uno/firmware.elf Advanced Memory Usage is available via "PlatformIO Home > Project Inspect" DATA: [ ] 0.4% (used 9 bytes from 2048 bytes) PROGRAM: [ ] 2.9% (used 930 bytes from 32256 bytes) Configuring upload protocol... AVAILABLE: arduino CURRENT: upload_protocol = arduino Looking for upload port... Auto-detected: /dev/ttyACM0 Uploading .pio/build/uno/firmware.hex avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.00s avrdude: Device signature = 0x1e950f (probably m328p) avrdude: reading input file ".pio/build/uno/firmware.hex" avrdude: writing flash (930 bytes): Writing | ################################################## | 100% 0.16s avrdude: 930 bytes of flash written avrdude: verifying flash memory against .pio/build/uno/firmware.hex: avrdude: load data flash data from input file .pio/build/uno/firmware.hex: avrdude: input file .pio/build/uno/firmware.hex contains 930 bytes avrdude: reading on-chip flash data: Reading | ################################################## | 100% 0.13s avrdude: verifying ... avrdude: 930 bytes of flash verified avrdude: safemode: Fuses OK (E:00, H:00, L:00) avrdude done. Thank you. ===== [SUCCESS] Took 2.18 seconds ===== Terminal will be reused by tasks, press any key to close it.

フォルダ構成

デフォルトの設定では、home/Documents/PlatformIO/Projectsのなかにプロジェクト名のフォルダが生成される。

参考URL

A new generation ecosystem for embedded development
Arduino Uno Rev3

以上

|

« micro:bit MBED開発ツール(VScode+PlatformIO) | トップページ | NXP LPC1768 mbed開発ツール »

linux」カテゴリの記事

PlatformIO」カテゴリの記事

コメント

コメントを書く



(ウェブ上には掲載しません)




« micro:bit MBED開発ツール(VScode+PlatformIO) | トップページ | NXP LPC1768 mbed開発ツール »