PlatformIOとArduino(本家)ツールの差分
2020/10/18
初版
PlatformIO Arduino Diff
PlatformIO Arduino Diff
概要
PlatformIOとArduino(本家)ツールの差分
PlatformIOでplatformをArduinoにしてArduinoの開発ができるが、
これとArduino(本家)ツールの実際に使ってみての差分について、現状(2020/10現在)をまとめた。
開発ツールplatformioのインストールについては以下を参照のこと:
・開発ツールPlatformIOをcliで使う(Seeeduino-XIAO版)
・M5Atomを開発ツールPlatformIOで使う(M5Atom/Arduino版)
・M5Atomを開発ツールPlatformIOで使う(Windows10版)
・開発ツールPlatformIOをcli(comand line interface)で使う(v2:Seeeduino-Wio-Terminal/Arduino版)
気がついた差分
(1)関数定義エラー
Arduinoにおいて関数を後方参照しても問題なくコンパイルできるが、PlatformIOでは
関数定義エラーになる。
解決方法としては、関数のプロトタイプ宣言を加えるか、関数の定義を前方に移動して
前方参照になるようにソースを変更する。
また、PlatformIO間でも動いているバージョンの違いで、プロトタイプ宣言が不要だったりするようだ:
以下は、RaspberryPiのplatformioでプロトタイプ宣言が必要だった例:
(PC(x86)では不要だった)
// Mandlebrot
// This will run quite slowly due to the large number of floating point calculations per pixel
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
// prototype
unsigned int rainbow(int value);
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define TFT_GREY 0x7BEF
unsigned long runTime = 0;
float sx = 0, sy = 0;
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
void setup() {
Serial.begin(250000);
//randomSeed(analogRead(A0));
Serial.println();
// Setup the LCD
tft.init();
tft.setRotation(3);
}
void loop() {
runTime = millis();
tft.fillScreen(TFT_BLACK);
tft.startWrite();
for (int px = 1; px < 320; px++) {
for (int py = 0; py < 240; py++) {
float x0 = (map(px, 0, 320, -250000 / 2,
-242500 / 2)) / 100000.0; //scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1))
float yy0 = (map(py, 0, 240, -75000 / 4,
-61000 / 4)) / 100000.0; //scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1))
float xx = 0.0;
float yy = 0.0;
int iteration = 0;
int max_iteration = 128;
while (((xx * xx + yy * yy) < 4) && (iteration < max_iteration)) {
float xtemp = xx * xx - yy * yy + x0;
yy = 2 * xx * yy + yy0;
xx = xtemp;
iteration++;
}
int color = rainbow((3 * iteration + 64) % 128);
yield(); tft.drawPixel(px, py, color);
}
}
tft.endWrite();
Serial.println(millis() - runTime);
while (1) {
yield();
}
}
unsigned int rainbow(int value) {
// Value is expected to be in range 0-127
// The value is converted to a spectrum colour from 0 = blue through to red = blue
byte red = 0; // Red is the top 5 bits of a 16 bit colour value
byte green = 0;// Green is the middle 6 bits
byte blue = 0; // Blue is the bottom 5 bits
byte quadrant = value / 32;
if (quadrant == 0) {
blue = 31;
green = 2 * (value % 32);
red = 0;
}
if (quadrant == 1) {
blue = 31 - (value % 32);
green = 63;
red = 0;
}
if (quadrant == 2) {
blue = 0;
green = 63;
red = value % 32;
}
if (quadrant == 3) {
blue = 0;
green = 63 - 2 * (value % 32);
red = 31;
}
return (red << 11) + (green << 5) + blue;
}
(2)Arduinoで問題ないスケッチがPlatformIOではビルドエラーになる
ターゲット(または、参照しているライブラリ?)に依存するのか
例えば、以下のスケッチはPlatformIOではビルドエラーになる:
#include"seeed_line_chart.h" //include the library
TFT_eSPI tft;
#define max_size 50 //maximum size of data
doubles data; //Initilising a doubles type to store data
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite
void setup() {
tft.begin();
tft.setRotation(3);
spr.createSprite(TFT_HEIGHT,TFT_WIDTH);
}
void loop() {
spr.fillSprite(TFT_WHITE);
if (data.size() == max_size) {
data.pop();//this is used to remove the first read variable
}
data.push(0.01 * random(1, 10)); //read variables and store in data
//Settings for the line graph title
auto header = text(0, 0)
.value("test")
.align(center)
.valign(vcenter)
.width(tft.width())
.thickness(3);
header.height(header.font_height() * 2);
header.draw(); //Header height is the twice the height of the font
//Settings for the line graph
auto content = line_chart(20, header.height()); //(x,y) where the line graph begins
content
.height(tft.height() - header.height() * 1.5) //actual height of the line chart
.width(tft.width() - content.x() * 2) //actual width of the line chart
.based_on(0.0) //Starting point of y-axis, must be a float
.show_circle(false) //drawing a cirle at each point, default is on.
.value(data) //passing through the data to line graph
.color(TFT_PURPLE) //Setting the color for the line
.draw();
spr.pushSprite(0, 0);
delay(50);
}
今のところ、Wio-Terminalで、この問題を経験したのみなので、もしかしたら、ターゲット特有のものかもしれない。
platformio.iniの実例
XIAO用:
; 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:seeed_xiao]
platform = atmelsam
board = seeed_xiao
framework = arduino
build_flags = -DXIAO
upload_protocol = sam-ba
monitor_speed = 115200
lib_ldf_mode = deep+
M5Atom用:
; 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:m5stick-c]
platform = espressif32
board = m5stick-c
framework = arduino
build_flags = -DM5ATOM
monitor_speed = 115200
lib_deps =
# use M5Atom lib
3113
# use "FastLED"
126
lib_ldf_mode = deep+
Wio-Terminal用:
; 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:seeed_wio_terminal]
platform = atmelsam
board = seeed_wio_terminal
framework = arduino
build_flags = -DWIO_TERMINAL
lib_deps =
adafruit/Adafruit Zero DMA Library@^1.0.8
https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_USBDISP/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_atWiFi/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_atUnified/archive/master.zip
https://github.com/Seeed-Studio/esp-at-lib/archive/develop.zip
https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_atWiFiClientSecure/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_atHTTPClient/archive/master.zip
https://github.com/Seeed-Studio/Seeed_Arduino_atWebServer/archive/master.zip
arduino-libraries/NTPClient@^3.1.0
lib_ldf_mode = deep+
Wio-Terminalの例は、実際に外部ライブラリを登録したもの。
(ビルドエラーが出たので以下のライブラリは登録から外してある)
https://github.com/Seeed-Studio/Seeed_Arduino_Linechart/archive /master.zip
追加(Arduinoのインストール方法)
cd ~/Downloads
# 以下のどちらかでダウンロードページに行って自分の環境にあったものをダウンロードする
firefox https://www.arduino.cc/en/Main/software
chromium https://www.arduino.cc/en/Main/software
# ここでは「Linux 64bits」を選択して。(自分の環境に合ったものを選択する)
tar -Jxvf arduino-1.8.13-linux64.tar.xz
# ここで解凍が終了する。
# 以下で起動用にaliasを設定する
alias ard=~/Downloads/arduino-1.8.13/arduino
# 以下でArduinoを起動する
ard
参考情報
https://wiki.seeedstudio.com/Wio-Terminal-LCD-Linecharts/
・XIAO/M5Atom/Wio-TerminlでCardKB(I2C)を使用する(Arduino版)
・XIAO/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版)
・XIAO/M5Atomで気圧センサー(HP206C)を動かす(XIAO/Arduino版、M5Atom/Arduino版)
・XIAO/M5AtomでLCD240x240(SPI)を制御する((XIAO/Arduino版、M5Atom/Arduino版)
・M5AtomでOLED128x128(SPI)を制御する(Arduino版)
・XIAOでOLED128x128(SPI)を制御する(Arduino版)
・XIAOでLCD160x80(SPI)を制御する(Arduino版)
以上
| 固定リンク
「XIAO」カテゴリの記事
- PlatformIOとArduino(本家)ツールの差分(2020.10.18)
- XIAO/M5Atom/Wio-TerminlでCardKB(I2C)を使用する(Arduino版)(2020.10.17)
- XIAO/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版)(2020.10.16)
- XIAO/M5AtomでOLED128x128(I2C)を制御する((XIAO/Arduino版、M5Atom/Arduino版)(2020.10.15)
- XIAO/M5AtomでLCD240x240(SPI)を制御する((XIAO/Arduino版、M5Atom/Arduino版)(2020.10.14)
「Wio Terminal」カテゴリの記事
- Wio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする(2022.02.03)
- Wio-TerminalでMQTTを動かす(2022.01.20)
- wio-terminalでGROVEを使う(2022.01.17)
- nixieクロックにNTPクライアントの機能を追加する(V2)(2021.02.18)
- Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)(2020.12.28)
コメント