XIAO

2020年10月18日 (日)

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版)

以上

続きを読む "PlatformIOとArduino(本家)ツールの差分"

| | コメント (0)

2020年10月17日 (土)

XIAO/M5Atom/Wio-TerminlでCardKB(I2C)を使用する(Arduino版)

2020/10/17
初版

PlatformIO XAIO M5ATOM WIOT CardKB(I2C)

PlatformIO XAIO M5ATOM WIOT CardKB(I2C)

概要

XIAO/M5Atom/Wio-Terminlで以下のCardKB(I2C)を使用する(Arduino版)。
3つのボードのplatformがArduinoなのでソースを共通化して動かしてみる。

CardKB(M5Stack用カード型キーボードユニット)

開発ツールplatformioのインストールについては以下を参照のこと:
開発ツールPlatformIOをcliで使う(Seeeduino-XIAO版)
M5Atomを開発ツールPlatformIOで使う(M5Atom/Arduino版)
M5Atomを開発ツールPlatformIOで使う(Windows10版)
開発ツールPlatformIOをcli(comand line interface)で使う(v2:Seeeduino-Wio-Terminal/Arduino版)

接続

本モジュールはI2Cタイプなので(I2C用の)Grove-Conectorに接続する。
(XIAOは専用のshield経由で接続する)

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 upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+

デモ・スケッチ

以下のようなファイルを作成する:
src/main.ino

#ifdef M5ATOM #include "M5Atom.h" #endif //#include <Arduino.h> #include <Wire.h> #define CARDKB_ADDR 0x5F void setup(void) { Serial.begin(115200); #ifdef M5ATOM M5.begin(); // Wire.begin() must be after M5.begin() Wire.begin(26, 32); // Grove Connector of Atom Matrix (I2C GPIO Pin: G26,G32) #endif #ifdef XIAO Wire.begin(); #endif #ifdef WIO_TERMINAL Wire.begin(); #endif } void loop() { Wire.requestFrom(CARDKB_ADDR, 1); while(Wire.available()) { char c = Wire.read(); // receive a byte as characterif if (c != 0) { Serial.print(c); Serial.print("("); Serial.print(c, HEX); Serial.println(")"); } } // delay(10); }

ビルド・実行

以下の手順でビルド・実行する:
(platformio.iniは、ボードごとに切り替える)

run pio -t upload

スケッチが起動した後、
通信ソフト(「picocom /dev/ttyACM0 -b115200」または「picocom /dev/ttyUSB0 -b115200」)を起動する。
CardKBのキーを押すと、対応した文字が通信ソフトの画面に表示される。

CardKBの操作の詳細は以下を参照のこと:
CardKBドキュメント

表示例

a(61) s(73) d(64) f(66) g(67) h(68) j(6A) k(6B) l(6C) A(41) S(53) D(44) F(46) G(47) H(48) J(4A) K(4B) L(4C) ;(3B) :(3A) `(60) +(2B) -(2D) _(5F) =(3D) ?(3F)

参考情報

Seeeduino XIAO用Grove シールド バッテリー管理チップ 搭載

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/M5Atom/Wio-TerminlでCardKB(I2C)を使用する(Arduino版)"

| | コメント (0)

2020年10月16日 (金)

XIAO/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版)

2020/10/16
初版

PlatformIO XAIO M5ATOM WIOT neopixels

PlatformIO XAIO M5ATOM WIOT neopixels

概要

XIAO/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版)。
XIAO/M5Atom/Wio-TerminalはplatformがArduinoなので、それを活かして3つのボードでソースを共通化して動かしてみる。

開発ツールplatformioのインストールについては以下を参照のこと:
開発ツールPlatformIOをcliで使う(Seeeduino-XIAO版)
M5Atomを開発ツールPlatformIOで使う(M5Atom/Arduino版)
M5Atomを開発ツールPlatformIOで使う(Windows10版)
開発ツールPlatformIOをcli(comand line interface)で使う(v2:Seeeduino-Wio-Terminal/Arduino版)

接続

neopixelsはGrove_Connector(GPIO用)に接続する。
(1)XIAO
XIAOのShield経由でGrove_Connectorに接続する。
(2)M5Atom
M5AtomのGrove_Connectorに接続する。
(3)Wio-Terminal
LCD画面に向かって、下部の右のGrove_Connectorに接続する。

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_deps = # Accept new functionality in a backwards compatible manner and patches adafruit/Adafruit NeoPixel @ ^1.6.0 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 # Accept new functionality in a backwards compatible manner and patches adafruit/Adafruit NeoPixel @ ^1.6.0 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 # # Accept new functionality in a backwards compatible manner and patches adafruit/Adafruit NeoPixel @ ^1.6.0 lib_ldf_mode = deep+

Wio-Terminalにおいて「adafruit/Adafruit NeoPixel @ ^1.6.0」ライブラリ以外のライブラリは標準的なものとして登録してあるが、 実際には、今回のスケッチで使用していない。
ビルド時に毎回コンパイルされるようなので、ビルド時間短縮のために、使っていないライブラリの登録は削除してもかまわない。

デモ・スケッチ

該当スケッチをダウンロードする:

cd src wget https://raw.githubusercontent.com/adafruit/Adafruit_NeoPixel/master/examples/simple_new_operator/simple_new_operator.ino

以下のように変更して共通化する:
src/simple_new_operator.ino

#ifdef M5ATOM #include "M5Atom.h" #endif // NeoPixel Ring simple sketch (c) 2013 Shae Erisson // Released under the GPLv3 license to match the rest of the // Adafruit NeoPixel library // This sketch shows use of the "new" operator with Adafruit_NeoPixel. // It's helpful if you don't know NeoPixel settings at compile time or // just want to store this settings in EEPROM or a file on an SD card. #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> // Required for 16 MHz Adafruit Trinket #endif // Which pin on the Arduino is connected to the NeoPixels? #ifdef XIAO int pin = 2; // XIAO Sheild Connector #endif #ifdef M5ATOM int pin = 26; // Grove Connector of M5Atom #endif #ifdef WIO_TERMINAL int pin = 1; // Grove Connector(lower right) of wio-terminal #endif //int pin = 6; // On Trinket or Gemma, suggest changing this to 1 // How many NeoPixels are attached to the Arduino? int numPixels = 16; // Popular NeoPixel ring size // NeoPixel color format & data rate. See the strandtest example for // information on possible values. int pixelFormat = NEO_GRB + NEO_KHZ800; // Rather than declaring the whole NeoPixel object here, we just create // a pointer for one, which we'll then allocate later... Adafruit_NeoPixel *pixels; #define DELAYVAL 100 // Time (in milliseconds) to pause between pixels //#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels void setup() { // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. // Any other board, you can remove this part (but no harm leaving it): #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // END of Trinket-specific code. // Right about here is where we could read 'pin', 'numPixels' and/or // 'pixelFormat' from EEPROM or a file on SD or whatever. This is a simple // example and doesn't do that -- those variables are just set to fixed // values at the top of this code -- but this is where it would happen. // Then create a new NeoPixel object dynamically with these values: pixels = new Adafruit_NeoPixel(numPixels, pin, pixelFormat); // Going forward from here, code works almost identically to any other // NeoPixel example, but instead of the dot operator on function calls // (e.g. pixels.begin()), we instead use pointer indirection (->) like so: pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED) // You'll see more of this in the loop() function below. } void loop() { pixels->clear(); // Set all pixel colors to 'off' delay(500); // The first NeoPixel in a strand is #0, second is 1, all the way up // to the count of pixels minus one. for(int i=0; i<numPixels; i++) { // For each pixel... // pixels->Color() takes RGB values, from 0,0,0 up to 255,255,255 // Here we're using a moderately bright green color: pixels->setPixelColor(i, pixels->Color(0, 150, 0)); pixels->show(); // Send the updated pixel colors to the hardware. delay(DELAYVAL); // Pause before next pass through loop } }

ビルド・実行

以下の手順でビルド・実行する:
(platformio.iniは、ボードごとに切り替える)

run pio -t upload

スケッチが起動すると、neopixelsが緑色に光って伸び縮みする。

参考情報

neopixel library:
https://github.com/adafruit/Adafruit_NeoPixel

M5Stack用NeoPixel互換 LEDテープ 20 cm
HEX RGB LED Board
NeoPixel Ring - 12連フルカラーシリアルLED

Seeeduino XIAO用Grove シールド バッテリー管理チップ 搭載

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/M5Atom/Wio-Terminalでneopixelsを制御する(Arduino版)"

| | コメント (0)

2020年10月15日 (木)

XIAO/M5AtomでOLED128x128(I2C)を制御する((XIAO/Arduino版、M5Atom/Arduino版)

2020/10/16
wio-terminal用のplatformio.iniを追加した。

2020/10/15
初版

PlatformIO XAIO M5ATOM OLED128x128(I2C)

PlatformIO XAIO M5ATOM OLED128x128(I2C)

概要

XIAO/M5Atomで以下のOLED128x128(I2C)を制御する((XIAO/Arduino版、M5Atom/Arduino版)。
platformがArduinoなのでソースを共通化して動かしてみる。

・https://wiki.seeedstudio.com/Grove-OLED_Display_1.12inch/
・https://github.com/SeeedDocument/Seeed-WiKi/blob/master/docs/Grove-OLED_Display_1.12inch.md
本ボードは、ボードのバージョンによって、解像度が96x96または128x128であり、それぞれでコントローラも異なる。
入手したボードは、v1.1で解像度は128x128でコントローラはSH1107Gであった。(Vdd:3.3V/5V両用対応)

開発ツールplatformioのインストールについては以下を参照のこと:
開発ツールPlatformIOをcliで使う(Seeeduino-XIAO版)
M5Atomを開発ツールPlatformIOで使う(M5Atom/Arduino版)
M5Atomを開発ツールPlatformIOで使う(Windows10版)

接続

本モジュールはI2Cタイプなので(I2C用の)Grove-Conectorに接続する。
(XIAOは専用のshield経由で接続する)

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_deps = # Accept new functionality in a backwards compatible manner and patches olikraus/U8g2 @ ^2.28.7 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 # Accept new functionality in a backwards compatible manner and patches olikraus/U8g2 @ ^2.28.7 lib_ldf_mode = deep+

デモ・スケッチ

以下のようなファイルを作成する:
src/helloworld.ino

#ifdef M5ATOM #include "M5Atom.h" #endif #include <Arduino.h> #include <U8g2lib.h> #include <U8x8lib.h> #include <Wire.h> #ifdef M5ATOM // Grove Connector of Atom Matrix (I2C GPIO Pin: G26,G32) #define SCL 32 #define SDA 26 #endif U8G2_SH1107_SEEED_128X128_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); U8X8_SH1107_SEEED_128X128_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); void setup(void) { /* NO NEED in this sketch #ifdef M5ATOM M5.begin(); // Wire.begin() must be after M5.begin() Wire.begin(26, 32); // Grove Connector of Atom Matrix (I2C GPIO Pin: G26,G32) #endif */ u8g2.begin(); u8g2.enableUTF8Print(); u8x8.begin() ; } void loop(void) { // using u8g2 lib u8g2.firstPage(); do { u8g2.setFont(u8g2_font_ncenB10_tr); u8g2.drawStr(0,12,"Hello World! #0"); u8g2.drawStr(0,24,"Hello World! #1"); u8g2.drawStr(0,36,"Hello World! #2"); u8g2.drawStr(0,48,"Hello World! #3"); u8g2.drawStr(0,60,"Hello World! #4"); u8g2.drawStr(0,72,"Hello World! #5"); u8g2.drawStr(0,84,"Hello World! #6"); u8g2.drawStr(0,96,"Hello World! #7"); u8g2.drawStr(0,108,"Hello World! #8"); u8g2.drawStr(0,120,"Hello World! #9"); u8g2.drawStr(0,132,"Hello World! #10"); } while ( u8g2.nextPage() ); delay(1000); //---------------- // kanji display u8g2.setFont(u8g2_font_b10_t_japanese1); u8g2.setFontDirection(0); u8g2.firstPage(); do { u8g2.setCursor(0, 15); u8g2.print("Hello World!"); u8g2.setCursor(0, 40); u8g2.print("こんにちは世界"); u8g2.setCursor(0, 50); u8g2.print("今日は良い天気/晴天です。"); u8g2.setCursor(0, 60); u8g2.print("明日は台風で強風でしょう。"); u8g2.setCursor(0, 70); u8g2.print("佐藤、田中、鈴木、青木、小松、増野、茅野、松岡"); } while ( u8g2.nextPage() ); delay(1000); // using u8x8 lib u8x8.setFont(u8x8_font_artossans8_r) ; u8x8.clear(); u8x8.println("Text Test") ; u8x8.println("XIAO/M5Atom\n") ; u8x8.print("OLED") ; u8x8.print("128x128(i2c)\n"); u8x8.println(millis()); u8x8.println(123.45); delay(1000); //-------------------- }

ビルド・実行

以下の手順でビルド・実行する:
(platformio.iniは、ボードごとに切り替える)

run pio -t upload

スケッチが起動すると、LCDに文字が表示される。
u8g2ライブラリ、u8x8ライブラリを交互に使用して文字を表示する。
日本語も表示するが、すべての漢字を持っているわけでないようだ。
(このデモでは人名が一部表示されない)

追加(wio-terminal用platformio.ini)

以下のplatformio.iniに切り替えると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 = # Accept new functionality in a backwards compatible manner and patches olikraus/U8g2 @ ^2.28.7 upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+

参考情報

U8g2 Library wiki: U8g2 is a monochrome graphics library
u8g2 reference

Seeeduino XIAO用Grove シールド バッテリー管理チップ 搭載

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/M5AtomでOLED128x128(I2C)を制御する((XIAO/Arduino版、M5Atom/Arduino版)"

| | コメント (0)

2020年10月14日 (水)

XIAO/M5AtomでLCD240x240(SPI)を制御する((XIAO/Arduino版、M5Atom/Arduino版)

2020/10/14

PlatformIO XAIO M5ATOM LCD(240x240)

PlatformIO XAIO M5ATOM LCD(240x240)

概要

XIAO/M5Atomで以下のLCD240x240(SPI)を制御する((XIAO/Arduino版、M5Atom/Arduino版)。
platformがArduinoなのでソースを共通化して動かしてみる。

WAVESHARE - 240x240, General 1.3inch LCD display Module, IPS, HD
・https://www.waveshare.com/w/upload/7/70/1.3inch_LCD_Module_user_manual_en.pdf
・https://www.waveshare.com/w/upload/0/0c/1.3inch_LCD_Module_Schematic.pdf

開発ツールplatformioのインストールについては以下を参照のこと:
開発ツールPlatformIOをcliで使う(Seeeduino-XIAO版)
M5Atomを開発ツールPlatformIOで使う(M5Atom/Arduino版)
M5Atomを開発ツールPlatformIOで使う(Windows10版)

接続

(1)XIAOの場合
以下のようにXIAOボードを接続する。

LCD CS D/C DIN CLK RST VCC GND BL
XIAO D2 D3 D10(MOSI) D8(CSK) D1 3V3 GND D0

本LCDモジュールでは、BL(バックライト)はオンにしても、それほど効果がないようなので 接続しない選択肢もある。
その場合、スケッチを変更する変更する必要ある。
(ここに載せたスケッチはBLを使用しない設定にしてある)

(2)M5ATOMの場合
以下のようにM5Atomボードを接続する。

LCD CS D/C DIN CLK RST VCC GND BL
M5Atom G22 G19 G23(MOSI) G33(CSK) G25 3V3 GND G21

(背面(底面)のピン穴に接続する)
本LCDモジュールでは、BL(バックライト)はオンにしても、それほど効果がないようなので 接続しない選択肢もある。
その場合、スケッチを変更する変更する必要ある。
(ここに載せたスケッチはBLを使用しない設定にしてある)

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_deps = # Accept new functionality in a backwards compatible manner and patches adafruit/Adafruit ST7735 and ST7789 Library @ ^1.6.0 # use "Adafruit GFX Library" 13 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 # Accept new functionality in a backwards compatible manner and patches adafruit/Adafruit ST7735 and ST7789 Library @ ^1.6.0 # use "Adafruit GFX Library" 13 lib_ldf_mode = deep+

デモ・スケッチ

以下の手順でダウンロードする:

cd src wget https://raw.githubusercontent.com/adafruit/Adafruit-ST7735-Library/master/examples/graphicstest_tft_gizmo/graphicstest_tft_gizmo.ino

これを以下のように編集してXIAO/M5ATOM共通化する:
src/graphicstest_tft_gizmo.ino

/************************************************************************** This is a library for several Adafruit displays based on ST77* drivers. Works with the Adafruit TFT Gizmo ----> http://www.adafruit.com/products/4367 Check out the links above for our tutorials and wiring diagrams. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. MIT license, all text above must be included in any redistribution **************************************************************************/ #ifdef M5ATOM #include "M5Atom.h" #endif #include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789 #include <SPI.h> // Because of the limited number of pins available on the Circuit Playground Boards // Software SPI is used #ifdef XIAO // You can use any (4 or) 5 pins // for XIAO #define TFT_SCLK 8 #define TFT_MOSI 10 #define TFT_DC 3 #define TFT_CS 2 #define TFT_RST 1 //#define TFT_BACKLIGHT 0 #endif #ifdef M5ATOM // for M5Atom #define TFT_SCLK 33 #define TFT_MOSI 23 #define TFT_DC 19 #define TFT_CS 22 #define TFT_RST 25 //#define TFT_BACKLIGHT 21 #endif /* #define TFT_CS 0 #define TFT_RST -1 // Or set to -1 and connect to Arduino RESET pin #define TFT_DC 1 #define TFT_BACKLIGHT PIN_A3 // Display backlight pin */ /* // You will need to use Adafruit's CircuitPlayground Express Board Definition // for Gizmos rather than the Arduino version since there are additional SPI // ports exposed. #if (SPI_INTERFACES_COUNT == 1) SPIClass* spi = &SPI; #else SPIClass* spi = &SPI1; #endif */ /* // OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique // to each board and not reassignable. Adafruit_ST7789 tft = Adafruit_ST7789(spi, TFT_CS, TFT_DC, TFT_RST); */ // OPTION 2 lets you interface the display using ANY TWO or THREE PINS, // tradeoff being that performance is not as fast as hardware SPI above. //#define TFT_MOSI PIN_A5 // Data out //#define TFT_SCLK PIN_A4 // Clock out Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST); float p = 3.1415926; void setup(void) { Serial.begin(9600); Serial.print(F("Hello! ST77xx TFT Test")); tft.init(240, 240); // Init ST7789 240x240 #ifdef M5ATOM tft.setRotation(0); #endif #ifdef XIAO tft.setRotation(0); #endif //tft.setRotation(2); //pinMode(TFT_BACKLIGHT, OUTPUT); //digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on Serial.println(F("Initialized")); uint16_t time = millis(); tft.fillScreen(ST77XX_BLACK); time = millis() - time; Serial.println(time, DEC); delay(500); // large block of text tft.fillScreen(ST77XX_BLACK); testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE); delay(1000); // tft print function! tftPrintTest(); delay(4000); // a single pixel tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN); delay(500); // line draw test testlines(ST77XX_YELLOW); delay(500); // optimized lines testfastlines(ST77XX_RED, ST77XX_BLUE); delay(500); testdrawrects(ST77XX_GREEN); delay(500); testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA); delay(500); tft.fillScreen(ST77XX_BLACK); testfillcircles(10, ST77XX_BLUE); testdrawcircles(10, ST77XX_WHITE); delay(500); testroundrects(); delay(500); testtriangles(); delay(500); mediabuttons(); delay(500); Serial.println("done"); delay(1000); } void loop() { tft.invertDisplay(true); delay(500); tft.invertDisplay(false); delay(500); } void testlines(uint16_t color) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, 0, x, tft.height()-1, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, 0, tft.width()-1, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, 0, 0, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(0, tft.height()-1, x, 0, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(0, tft.height()-1, tft.width()-1, y, color); delay(0); } tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color); delay(0); } for (int16_t y=0; y < tft.height(); y+=6) { tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color); delay(0); } } void testdrawtext(char *text, uint16_t color) { tft.setCursor(0, 0); tft.setTextColor(color); tft.setTextWrap(true); tft.print(text); } void testfastlines(uint16_t color1, uint16_t color2) { tft.fillScreen(ST77XX_BLACK); for (int16_t y=0; y < tft.height(); y+=5) { tft.drawFastHLine(0, y, tft.width(), color1); } for (int16_t x=0; x < tft.width(); x+=5) { tft.drawFastVLine(x, 0, tft.height(), color2); } } void testdrawrects(uint16_t color) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=0; x < tft.width(); x+=6) { tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color); } } void testfillrects(uint16_t color1, uint16_t color2) { tft.fillScreen(ST77XX_BLACK); for (int16_t x=tft.width()-1; x > 6; x-=6) { tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1); tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2); } } void testfillcircles(uint8_t radius, uint16_t color) { for (int16_t x=radius; x < tft.width(); x+=radius*2) { for (int16_t y=radius; y < tft.height(); y+=radius*2) { tft.fillCircle(x, y, radius, color); } } } void testdrawcircles(uint8_t radius, uint16_t color) { for (int16_t x=0; x < tft.width()+radius; x+=radius*2) { for (int16_t y=0; y < tft.height()+radius; y+=radius*2) { tft.drawCircle(x, y, radius, color); } } } void testtriangles() { tft.fillScreen(ST77XX_BLACK); uint16_t color = 0xF800; int t; int w = tft.width()/2; int x = tft.height()-1; int y = 0; int z = tft.width(); for(t = 0 ; t <= 15; t++) { tft.drawTriangle(w, y, y, x, z, x, color); x-=4; y+=4; z-=4; color+=100; } } void testroundrects() { tft.fillScreen(ST77XX_BLACK); uint16_t color = 100; int i; int t; for(t = 0 ; t <= 4; t+=1) { int x = 0; int y = 0; int w = tft.width()-2; int h = tft.height()-2; for(i = 0 ; i <= 16; i+=1) { tft.drawRoundRect(x, y, w, h, 5, color); x+=2; y+=3; w-=4; h-=6; color+=1100; } color+=100; } } void tftPrintTest() { tft.setTextWrap(false); tft.fillScreen(ST77XX_BLACK); tft.setCursor(0, 30); tft.setTextColor(ST77XX_RED); tft.setTextSize(1); tft.println("Hello World!"); tft.setTextColor(ST77XX_YELLOW); tft.setTextSize(2); tft.println("Hello World!"); tft.setTextColor(ST77XX_GREEN); tft.setTextSize(3); tft.println("Hello World!"); tft.setTextColor(ST77XX_BLUE); tft.setTextSize(4); tft.print(1234.567); delay(1500); tft.setCursor(0, 0); tft.fillScreen(ST77XX_BLACK); tft.setTextColor(ST77XX_WHITE); tft.setTextSize(0); tft.println("Hello World!"); tft.setTextSize(1); tft.setTextColor(ST77XX_GREEN); tft.print(p, 6); tft.println(" Want pi?"); tft.println(" "); tft.print(8675309, HEX); // print 8,675,309 out in HEX! tft.println(" Print HEX!"); tft.println(" "); tft.setTextColor(ST77XX_WHITE); tft.println("Sketch has been"); tft.println("running for: "); tft.setTextColor(ST77XX_MAGENTA); tft.print(millis() / 1000); tft.setTextColor(ST77XX_WHITE); tft.print(" seconds."); } void mediabuttons() { // play tft.fillScreen(ST77XX_BLACK); tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE); tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED); delay(500); // pause tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE); tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN); tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN); delay(500); // play color tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE); delay(50); // pause color tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED); tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED); // play color tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN); }

「tft.setRotation(x);」は、LCDモジュールの設置方法により調整する必要がある。
(上のソースは、基板の印刷「1.3inch LCD module」の文字の方向に合わせた)

ビルド・実行

以下の手順でビルド・実行する:
(platformio.iniは、ボードごとに切り替える)

run pio -t upload

スケッチが起動すると、LCDに文字や図形が表示される。最後には、再生アイコン、停止アイコンの図形が表示され、反転教示を繰り返す。

参考情報

M5AtomでOLED128x128(SPI)を制御する(Arduino版)
XIAOでOLED128x128(SPI)を制御する(Arduino版)
XIAOでLCD160x80(SPI)を制御する(Arduino版)

以上

続きを読む "XIAO/M5AtomでLCD240x240(SPI)を制御する((XIAO/Arduino版、M5Atom/Arduino版)"

| | コメント (0)

2020年10月13日 (火)

XIAO/M5Atomで気圧センサー(HP206C)を動かす(XIAO/Arduino版、M5Atom/Arduino版)

2020/10/16
wio-terminal用のplatformio.iniを追加した。

2020/10/13 初版

PlatformIO XAIO M5ATOM HP206C

PlatformIO XAIO M5ATOM HP206C

概要

XIAO/M5Atomで以下の気圧センサー(HP206C)を動かす(XIAO/Arduino版、M5Atom/Arduino版)。
platformがArduinoなのでソースを共通化して動かしてみる。

Grove 高精度気圧計 - Grove Barometer
https://wiki.seeedstudio.com/Grove-Barometer-High-Accuracy/

開発ツールplatformioのインストールについては以下を参照のこと:
開発ツールPlatformIOをcliで使う(Seeeduino-XIAO版)
M5Atomを開発ツールPlatformIOで使う(M5Atom/Arduino版)
M5Atomを開発ツールPlatformIOで使う(Windows10版)

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 upload_protocol = sam-ba monitor_speed = 115200 lib_deps = # HP20x lib https://github.com/Seeed-Studio/Grove_Barometer_HP20x.git 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 # HP20x lib https://github.com/Seeed-Studio/Grove_Barometer_HP20x.git lib_ldf_mode = deep+

デモ・スケッチ

以下の手順でダウンロードする:

cd src wget https://raw.githubusercontent.com/Seeed-Studio/Grove_Barometer_HP20x/master/examples/HP20x_demo/HP20x_demo.ino

これを以下のように編集してXIAO/M5ATOM共通化する:
src/HP20x_demo.ino

/* Demo name : HP20x_dev demo Usage : I2C PRECISION BAROMETER AND ALTIMETER [HP206C hopeRF] Author : Oliver Wang from Seeed Studio Version : V0.1 Change log : Add kalman filter 2014/04/04 */ #ifdef M5ATOM #include "M5Atom.h" #endif #include <HP20x_dev.h> #include "Arduino.h" #include "Wire.h" #include <KalmanFilter.h> unsigned char ret = 0; /* Instance */ KalmanFilter t_filter; //temperature filter KalmanFilter p_filter; //pressure filter KalmanFilter a_filter; //altitude filter void setup() { #ifdef M5ATOM M5.begin(); // Wire.begin() must be after M5.begin() Wire.begin(26, 32); // Grove Connector of Atom Matrix (I2C GPIO Pin: G26,G32) #endif //Serial.begin(9600); // start serial for output Serial.begin(115200); // start serial for output Serial.println("****HP20x_dev demo by seeed studio****\n"); Serial.println("Calculation formula: H = [8.5(101325-P)]/100 \n"); /* Power up,delay 150ms,until voltage is stable */ delay(150); /* Reset HP20x_dev */ HP20x.begin(); delay(100); } void loop() { Serial.println("------------------\n"); long Temper = HP20x.ReadTemperature(); Serial.println("Temper:"); float t = Temper / 100.0; Serial.print(t); Serial.println("C.\n"); Serial.println("Filter:"); Serial.print(t_filter.Filter(t)); Serial.println("C.\n"); long Pressure = HP20x.ReadPressure(); Serial.println("Pressure:"); t = Pressure / 100.0; Serial.print(t); Serial.println("hPa.\n"); Serial.println("Filter:"); Serial.print(p_filter.Filter(t)); Serial.println("hPa\n"); long Altitude = HP20x.ReadAltitude(); Serial.println("Altitude:"); t = Altitude / 100.0; Serial.print(t); Serial.println("m.\n"); Serial.println("Filter:"); Serial.print(a_filter.Filter(t)); Serial.println("m.\n"); Serial.println("------------------\n"); delay(1000); }

該当の気圧センサーはI2Cタイプなので(I2C用の)Grove-Conectorに接続する。
(XIAOは専用のshield経由で接続する)

ビルド・実行

以下の手順でビルド・実行する:
(platformio.iniは、ボードごとに切り替える)

run pio -t upload

出力

通信ソフトを起動すると以下のような出力が得られる:

------------------ Temper: 27.23C. Filter: 26.96C. Pressure: 1003.36hPa. Filter: 995.89hPa Altitude: 83.92m. Filter: 83.82m. ------------------ ------------------ Temper: 27.22C. Filter: 27.09C. Pressure: 1003.40hPa. Filter: 1000.78hPa Altitude: 83.59m. Filter: 83.69m. ------------------ <省略>

追加(wio-terminal用platformio.ini)

以下のplatformio.iniに切り替えると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 = # HP20x lib https://github.com/Seeed-Studio/Grove_Barometer_HP20x.git upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+

接続するGrove-Connectorは、LCD画面を正面にして下側の左のほうのConnectorが I2C用なので、こちらに該当モジュールを接続する。

参考情報

Seeeduino XIAO用Grove シールド バッテリー管理チップ 搭載

以上

続きを読む "XIAO/M5Atomで気圧センサー(HP206C)を動かす(XIAO/Arduino版、M5Atom/Arduino版)"

| | コメント (0)

2020年10月 9日 (金)

XIAOボードでTinyGOを動かす(Windows10版)

2020/10/9++:
初版

TinyGO Install XIAO on Windows10

TinyGO Install XIAO on Windows10

概要

以下のXIAOボードでTinyGOを動かす(Windows10版)。
tinygo_0.15.0でxiaoが正式にサポートされたので、それをインストールして使ってみる。
なお、ホストPCとしてはwindows10を想定している。

Seeeduino XIAO

tinygoのインストール

以下の手順でインストールする:
PowerShell:

# scoopをインストール Set-ExecutionPolicy RemoteSigned -scope CurrentUser iwr -useb get.scoop.sh | iex # goをインストールする scoop install go # tinygoをインストールする scoop install tinygo scoop update tinygo # その他のツールをインストールする scoop install git # windows用VScodeをインストールする scoop bucket add extras scoop install vscode

scoopの簡単な説明:

# xxxxをインストール scoop install # Scoop自身とローカル内にあるアプリの更新情報を更新 scoop update # 最新バージョンでないアプリがあるかをチェック scoop status # xxxxを更新 scoop update xxxx # すべてのアプリを更新 scoop update * # xxxxをアンインストール scoop uninstall xxxx

bootloader mode

XIAOにfirmwareを書き込めるモードを「bootloader mode」といい、このモードでは、USBストレージとしてArduinoが現れる。
arduinoのプログラムかCircuitPythonのプログラムが書き込まれている場合、RSTパッドを2度GNDとショートすると このモードに入りUSBストレージとしてarduinoが現れる。

examples/blinky1を動かす

xiaoをホストに接続して、bootloader-modeにして、以下を実行する:

tinygo flash -size full -target xiao examples/blinky1

コンパイルと書き込み実行が自動的に行われ、ボードのLEDが点滅する。

注意: シリアルポートが複数ある場合、xiaoが接続しているポートを指定する必要があるので 以下のようにportを指定する。

tinygo flash -port com4 -size full -target xiao examples/blinky1

上の例は、com4がxiaoのポートの場合である。
また、接続し直すと、comの番号が変わるので注意が必要である。
接続しているポートを確認は、TeraTermなどの通信ソフトを起動して シリアルポートの設定を見て知ることができる。

任意のプログラムを動かす

(1)以下のようにプロジェクト用ディレクトリを作成する:

cd tigo_ws mkdir blink cd blink

(2)プロジェクト(blink)ディレクトリに以下のファイルを作成する:
main.go

package main // This is the most minimal blinky example and should run almost everywhere. import ( "machine" "time" ) func main() { led := machine.LED led.Configure(machine.PinConfig{Mode: machine.PinOutput}) for { led.Low() time.Sleep(time.Millisecond * 1000) led.High() time.Sleep(time.Millisecond * 1000) } }

(3)ビルド実行
xiaoをホストに接続して、bootloader-modeにして、以下を実行する:

tinygo flash -size full -target xiao .

コンパイルと書き込み実行が自動的に行われ、ボードのLEDが点滅する。
(example/blinky1と区別しにくいと思うので、点滅周期を変更して実行してみる)

TinyGOのモジュールを利用する

実行例: # 以下で、モジュールをインストールする go get tinygo.org/x/drivers # 参考(ダウンロードしたモジュールは「~/go/src」の配下に置かれる # インポートしたいモジュールを確認する ls ~/go/src/tinygo.org/x/drivers ... adt7410 ds1307 l9110x shifter vl53l1x adxl345 ds3231 lis3dh shiftregister waveshare-epd amg88xx easystepper lsm6ds3 sht3x wifinina apa102 espat mag3110 ssd1306 ws2812 at24cx examples mcp3008 ssd1331 bh1750 flash microbitmatrix st7735 ... # ここでは例として「ws2812」を使用する mkdir ws2812 cd ws2812 # exampleのmain.goをコピーする cp ~/go/src/tinygo.org/x/driver/examples/ws2812/main.go .

以下のようにmain.goを変更する:
main.go

// Connects to an WS2812 RGB LED strip with 10 LEDS. // // See either the others.go or digispark.go files in this directory // for the neopixels pin assignments. package main import ( "image/color" "machine" "time" "tinygo.org/x/drivers/ws2812" ) var leds [10]color.RGBA func main() { led := machine.LED led.Configure(machine.PinConfig{Mode: machine.PinOutput}) neo := machine.D4 // for Feater-M4/XIAO // neo := machine.NEOPIXELS neo.Configure(machine.PinConfig{Mode: machine.PinOutput}) ws := ws2812.New(neo) rg := false for { rg = !rg for i := range leds { rg = !rg if rg { // Alpha channel is not supported by WS2812 so we leave it out leds[i] = color.RGBA{R: 0xff, G: 0x00, B: 0x00} } else { leds[i] = color.RGBA{R: 0x00, G: 0xff, B: 0x00} } } ws.WriteColors(leds[:]) led.Set(rg) time.Sleep(100 * time.Millisecond) } }

続き:

# ボードをbootloader-modeに入れる tinygo flash -size full -target xiao .

D4をneopixelsのDIN,3V3をVCC,GNDをGNDに接続する。
書き込んで実行すると、接続したneopixelsが色を変えて光る。

tmp102(i2c)を動かす

以下を実行する:

mkdir tmp102 cd tmp102 cp ~/go/src/tinygo.org/x/driver/examples/tmp102/main.go . # bootloader-modeに入る tinygo flash -size full -target xiao .

他の外部モジュールを利用する

# 以下で、モジュールをインストールする go get github.com/aykevl/ledsgo # 参考(以下のディレクトリにダウンロードしたものが置かれる) ls ~/go/src github.com tinygo.org ls ~/go/src/github.com aykevl # プログラムを置くディレクトリを作る mkdir neopixels0 cd neopixels0 # デモ・プログラムをダウンロードする wget https://gist.githubusercontent.com/aykevl/47d0a24408cf585f6ba181c4dc663bca/raw/c4db52a1fedb215b4743a31842aeba31a4f2fe77/ws2812.go

以下のようにws2812.goを修正する:
ws2812.go

package main // This is an example of controlling WS2812 LEDs from an ESP32. // The following PRs are still needed to get this to work: // https://github.com/tinygo-org/tinygo/pull/1353 // https://github.com/tinygo-org/tinygo/pull/1354 // https://github.com/tinygo-org/drivers/pull/198 import ( "machine" "time" "github.com/aykevl/ledsgo" "tinygo.org/x/drivers/ws2812" ) const brightness = 0x44 const pin = machine.D2 // 2 for Grove Connector of XIAO //const pin = machine.Pin(27) // G27 for Matrix(5x5) of M5Atom //const pin = machine.Pin(26) // G26 for Grove Connector of M5Atom //const pin = machine.Pin(25) // G25 for M5Atom var ws ws2812.Device func main() { //strip := make(ledsgo.Strip, 25) // for Matrix(5x5) M5Atom strip := make(ledsgo.Strip, 15) // for Grove Neopixel //strip := make(ledsgo.Strip, 50) pin.Configure(machine.PinConfig{Mode: machine.PinOutput}) ws = ws2812.New(pin) rainbow(strip) } func rainbow(strip ledsgo.Strip) { for { now := time.Now().UnixNano() for i := range strip { strip[i] = ledsgo.Color{uint16(now>>15) - uint16(i)<<12, 0xff, brightness}.Spectrum() } ws.WriteColors(strip) time.Sleep(time.Second / 100) } } func noise(strip ledsgo.Strip) { for { now := time.Now().UnixNano() for i := range strip { const spread = 100 val := int32(ledsgo.Noise2(int32(now>>22), int32(i*spread))) * 3 / 2 strip[i] = ledsgo.Color{uint16(val), 0xff, brightness}.Spectrum() } ws.WriteColors(strip) time.Sleep(time.Second / 100) } }

XIAOのGrove_Shield経由でGroveコネクタにnexpixelsを接続する。
参照:Seeeduino XIAO用Grove シールド バッテリー管理チップ 搭載

以下でビルド実行する:

tinygo flash -size full -target=xiao .

書き込み実行すると、neopixelsが虹色に変化して光る。

XIAOのピン定義

port pin
PA02 A0/D0
PA04 A1/D1
PA10 A2/D2
PA11 A3/D3
PA08 A4/D4
PA09 A5/D5
PB08 A6/D6
PB09 A7/D7
PA07 A8/D8
PA05 A9/D9
PA06 A10/D10

参考情報

WindowsコマンドラインツールScoopのすすめ(基礎編)
Windowsでパッケージ管理したいなら、先ずScoopより始めよ

https://github.com/tinygo-org/tinygo
https://tinygo.org/
https://tinygo.org/getting-started/linux/

Seeeduino XIAO用Grove シールド バッテリー管理チップ 搭載

ESP32 and ESP8266 support in TinyGo

コンピュータボードでTinyGOを動かす
docker/TinyGO Helper Script
TinyGOでLightSensorを動かす

TinyGoで始める組み込みプログラミング
TinyGo on Arduino Uno: An Introduction

Circuit Playground Express
Adafruit Circuit Playground Express - Overview
Infrared Receive and Transmit with Circuit Playground Express

Adafruit Circuit Playground Express - PINOUT
Adafruit Circuit Playground Express Pin Assign

NUCLEO-F103RB mbed pinout
NUCLEO-F103RB Pin Assign
STM32F4DISCO Pin Assign
MICROBIT Pin Assign
ARDUINO-NANO Pin Assign
ARDUINO Pin Assign

TinyGo Drivers

USB Flashing Format (UF2)

XIAO Schematic(zip)
How to use Seeeduino XIAO to log in to your Raspberry PI

以上

続きを読む "XIAOボードでTinyGOを動かす(Windows10版)"

| | コメント (0)

2020年10月 5日 (月)

プログラミング言語RustをXIAOで動かす(v2)

2020/10/5:
初版

Rust XIAO v2

Rust XIAO v2

概要

プログラミング言語Rustを以下のXIAOで動かす(v2)。
前の記事をubuntu_20.04に対応して改版した。
なお、ホストPCとしてはubuntu_20.04を想定している。

Seeeduino XIAO

関連ツールのインストール

(0)udev設定
以下を実行する:

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 udevadm control --reload-rules sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER

(1)bossac(書き込み)ツールのインストール
以下で必要なツールをインスールする:

sudo apt-get update sudo apt-get install bossa sudo apt-get install bossa-cli

bossaでGUIツール、bossacでCLIツールが起動する。
参照:https://www.shumatech.com/web/products/bossa

(2)rustツールのインストール

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh #入力を促すので、「1」を入力する source $HOME/.cargo/env

(3)Cコンパイラのインストール
binを作成するのに、これに含まれるツールを使用するのでインストールする

sudo apt-get install gcc-arm-none-eabi

(4)picocom(通信ソフト)のインストール

sudo apt-get install picocom

(5)rust関連ツールのインストール

# for samd11, samd21: rustup target add thumbv6m-none-eabi # for samd51, same54: rustup target add thumbv7em-none-eabihf # uf2conv etc install rustup component add llvm-tools-preview cargo install uf2conv cargo-binutils

blinkを実行する

# download git clone https://github.com/atsamd-rs/atsamd.git cd atsamd/boards/xiao_m0 # build cargo build --example blink # conv elf to bin arm-none-eabi-objcopy -O binary target/thumbv6m-none-eabi/debug/examples/blink firmware.bin # bootloader-modeにする(resetを2度押す) # flash bossac -p /dev/ttyACM0 -i -e -w -v -R -o 0x2000 firmware.bin

実行結果として、オンボードの3つのLEDが点滅する。 (グリーンのLEDは通電表示のLEDなので点滅せずに光っている)

出力例:

$ bossac -p /dev/ttyACM0 -i -e -w -v -R -o 0x2000 firmware.bin Device : ATSAMD21x18 Version : v1.1 [Arduino:XYZ] Nov 27 2019 16:35:59 Address : 0x0 Pages : 4096 Page Size : 64 bytes Total Size : 256KB Planes : 1 Lock Regions : 16 Locked : none Security : false BOD : true BOR : true Erase flash Done in 0.834 seconds Write 13260 bytes to flash (208 pages) [==============================] 100% (208/208 pages) Done in 0.087 seconds Verify 13260 bytes of flash [==============================] 100% (208/208 pages) Verify successful Done in 0.080 seconds

usb_serial

# download git clone https://github.com/atsamd-rs/atsamd.git cd atsamd/boards/xiao_m0 # build cargo build --example usb_serial --features="usb" # conv elf to bin arm-none-eabi-objcopy -O binary target/thumbv6m-none-eabi/debug/examples/usb_serial firmware.bin # bootloader-modeにする(resetを2度押す) # flash bossac -p /dev/ttyACM0 -i -e -w -v -R -o 0x2000 firmware.bin

書き込みが終了すると、USBシリアルのエコープログラムが動作する。
「picocom /dev/ttyACM0 -b115200」で通信プログラムを起動して キー入力すると、入力したキーが表示される。キーの入力に応じて、 オンボードの青いLEDが点滅する。

参照情報

旧版:プログラミング言語RustをXIAOで動かす

atsamd & atsame support for Rust
Running bossac on the command line

STM32 Nucleo Board STM32F103RB

The Embedded Rust Book
The Embedded Rust Book - Semihosting

UbuntuにRustをインストールする

Adding a new board

以上

続きを読む "プログラミング言語RustをXIAOで動かす(v2)"

| | コメント (0)

XIAOボードでTinyGOを動かす(v2)

2020/10/8:
もう一つのnexpixelのデモを追加した。

2020/10/5:
初版

TinyGO Install XIAO v2

TinyGO Install XIAO v2

概要

以下のXIAOボードでTinyGOを動かす(v2)。
tinygo_0.15.0でxiaoが正式にサポートされたので、それをインストールして使ってみる。
前の記事では、その時点では、XIAOはサポート対象外だったので、同じチップを採用しているFeather-M0としてビルドして試用していた。
なお、ホストPCとしてはubuntu20.04を想定している。

Seeeduino XIAO

準備

以下のツールを予めインストールする:
(0)udev設定
以下を実行する:

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 udevadm control --reload-rules sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER

(1)TinyGOのインストール
以下の手順でインストールする:

mkdir tinygo_ws cd tinygo_ws wget https://github.com/tinygo-org/tinygo/releases/download/v0.15.0/tinygo_0.15.0_amd64.deb sudo dpkg -i tinygo_0.15.0_amd64.deb export PATH=$PATH:/usr/local/tinygo/bin # xiaoには不要だが、ターゲットがarduinoのときに # 必要となるツールをついでにインストールする sudo apt-get install gcc-avr sudo apt-get install avr-libc sudo apt-get install avrdude

(2)GOのインストール
TinyGOのモジュールを使用するのにGOが必要なので 予めインストールする。
(ただし、TinyGOとの整合性により最新版ではない)

wget https://dl.google.com/go/go1.13.7.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.13.7.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin export GOPATH=$HOME/tinygo_ws

なお、GOPATHのパス設定値は、任意だが、それをベースに その配下にTinyGO/GOの関係ファイル/ディレクトリが置かれる。

(3)BOSSAのインスール
ここでは使用しないが、xiaoの書き込みツールをインストールする:

sudo apt-get update sudo apt-get install bossa sudo apt-get install bossa-cli

bossaでGUIツール、bossacでCLIツールが起動する。
参照:https://www.shumatech.com/web/products/bossa

以上のexportは、.bashrcに登録する。

(4)export登録(まとめ)
以下を.bashrcに追加する:

# tinygo/go export PATH=$PATH:/usr/local/go/bin export PATH=$PATH:/usr/local/tinygo/bin export GOPATH=$HOME/tinygo_ws export TIGOLIBS=$GOPATH/src/tinygo.org/x/drivers/

bootloader mode

XIAOにfirmwareを書き込めるモードを「bootloader mode」といい、このモードでは、USBストレージとしてArduinoが現れる。
arduinoのプログラムかCircuitPythonのプログラムが書き込まれている場合、RSTパッドを2度GNDとショートすると このモードに入りUSBストレージとしてarduinoが現れる。

examples/blinky1を動かす

xiaoをホストに接続して、bootloader-modeにして、以下を実行する:

tinygo flash -size full -target xiao examples/blinky1

コンパイルと書き込み実行が自動的に行われ、ボードのLEDが点滅する。

任意のプログラムを動かす

(1)以下のようにプロジェクト用ディレクトリを作成する:

cd tigo_ws mkdir blink cd blink

(2)プロジェクト(blink)ディレクトリに以下のファイルを作成する:
main.go

package main // This is the most minimal blinky example and should run almost everywhere. import ( "machine" "time" ) func main() { led := machine.LED led.Configure(machine.PinConfig{Mode: machine.PinOutput}) for { led.Low() time.Sleep(time.Millisecond * 1000) led.High() time.Sleep(time.Millisecond * 1000) } }

(3)ビルド実行
xiaoをホストに接続して、bootloader-modeにして、以下を実行する:

tinygo flash -size full -target xiao .

コンパイルと書き込み実行が自動的に行われ、ボードのLEDが点滅する。
(example/blinky1と区別しにくいと思うので、点滅周期を変更して実行してみる)

TinyGOのモジュールを利用する

実行例: # 以下で、モジュールをインストールする go get tinygo.org/x/drivers # インストールしたモジュールのパスを設定する export TIGOLIBS=$GOPATH/src/tinygo.org/x/drivers/ # インポートしたいモジュールを確認する ls $TIGOLIBS ... adt7410 ds1307 l9110x shifter vl53l1x adxl345 ds3231 lis3dh shiftregister waveshare-epd amg88xx easystepper lsm6ds3 sht3x wifinina apa102 espat mag3110 ssd1306 ws2812 at24cx examples mcp3008 ssd1331 bh1750 flash microbitmatrix st7735 ... # ここでは例として「ws2812」を使用する mkdir ws2812 cd ws2812 # exampleのmain.goをコピーする cp $TIGOLIBS/examples/ws2812/main.go .

以下のようにmain.goを変更する:
main.go

// Connects to an WS2812 RGB LED strip with 10 LEDS. // // See either the others.go or digispark.go files in this directory // for the neopixels pin assignments. package main import ( "image/color" "machine" "time" "tinygo.org/x/drivers/ws2812" ) var leds [10]color.RGBA func main() { led := machine.LED led.Configure(machine.PinConfig{Mode: machine.PinOutput}) neo := machine.D4 // for Feater-M4/XIAO // neo := machine.NEOPIXELS neo.Configure(machine.PinConfig{Mode: machine.PinOutput}) ws := ws2812.New(neo) rg := false for { rg = !rg for i := range leds { rg = !rg if rg { // Alpha channel is not supported by WS2812 so we leave it out leds[i] = color.RGBA{R: 0xff, G: 0x00, B: 0x00} } else { leds[i] = color.RGBA{R: 0x00, G: 0xff, B: 0x00} } } ws.WriteColors(leds[:]) led.Set(rg) time.Sleep(100 * time.Millisecond) } }

続き:

# ボードをbootloader-modeに入れる tinygo flash -size full -target xiao .

D4をneopixelsのDIN,3V3をVCC,GNDをGNDに接続する。
書き込んで実行すると、接続したneopixelsが色を変えて光る。

tmp102(i2c)を動かす

以下を実行する:

mkdir tmp102 cd tmp102 cp $TIGOLIBS/examples/tmp102/main.go . # bootloader-modeに入る tinygo flash -size full -target xiao .

他の外部モジュールを利用する

# 以下で、モジュールをインストールする go get github.com/aykevl/ledsgo # 参考(以下のディレクトリにダウンロードしたものが置かれる) ls $GOPATH/src github.com tinygo.org ls $GOPATH/src/github.com aykevl # プログラムを置くディレクトリを作る mkdir neopixels0 cd neopixels0 # デモ・プログラムをダウンロードする wget https://gist.githubusercontent.com/aykevl/47d0a24408cf585f6ba181c4dc663bca/raw/c4db52a1fedb215b4743a31842aeba31a4f2fe77/ws2812.go

以下のようにws2812.goを修正する:
ws2812.go

package main // This is an example of controlling WS2812 LEDs from an ESP32. // The following PRs are still needed to get this to work: // https://github.com/tinygo-org/tinygo/pull/1353 // https://github.com/tinygo-org/tinygo/pull/1354 // https://github.com/tinygo-org/drivers/pull/198 import ( "machine" "time" "github.com/aykevl/ledsgo" "tinygo.org/x/drivers/ws2812" ) const brightness = 0x44 const pin = machine.D2 // 2 for Grove Connector of XIAO //const pin = machine.Pin(27) // G27 for Matrix(5x5) of M5Atom //const pin = machine.Pin(26) // G26 for Grove Connector of M5Atom //const pin = machine.Pin(25) // G25 for M5Atom var ws ws2812.Device func main() { //strip := make(ledsgo.Strip, 25) // for Matrix(5x5) M5Atom strip := make(ledsgo.Strip, 15) // for Grove Neopixel //strip := make(ledsgo.Strip, 50) pin.Configure(machine.PinConfig{Mode: machine.PinOutput}) ws = ws2812.New(pin) rainbow(strip) } func rainbow(strip ledsgo.Strip) { for { now := time.Now().UnixNano() for i := range strip { strip[i] = ledsgo.Color{uint16(now>>15) - uint16(i)<<12, 0xff, brightness}.Spectrum() } ws.WriteColors(strip) time.Sleep(time.Second / 100) } } func noise(strip ledsgo.Strip) { for { now := time.Now().UnixNano() for i := range strip { const spread = 100 val := int32(ledsgo.Noise2(int32(now>>22), int32(i*spread))) * 3 / 2 strip[i] = ledsgo.Color{uint16(val), 0xff, brightness}.Spectrum() } ws.WriteColors(strip) time.Sleep(time.Second / 100) } }

XIAOのGrove_Shield経由でGroveコネクタにnexpixelsを接続する。
参照:Seeeduino XIAO用Grove シールド バッテリー管理チップ 搭載

以下でビルド実行する:

tinygo flash -size full -target=xiao .

書き込み実行すると、neopixelsが虹色に変化して光る。

XIAOのピン定義

port pin
PA02 A0/D0
PA04 A1/D1
PA10 A2/D2
PA11 A3/D3
PA08 A4/D4
PA09 A5/D5
PB08 A6/D6
PB09 A7/D7
PA07 A8/D8
PA05 A9/D9
PA06 A10/D10

参考情報

https://github.com/tinygo-org/tinygo
https://tinygo.org/
https://tinygo.org/getting-started/linux/

Seeeduino XIAO用Grove シールド バッテリー管理チップ 搭載

ESP32 and ESP8266 support in TinyGo

旧版:XIAOボードでTinyGOを動かす

コンピュータボードでTinyGOを動かす
docker/TinyGO Helper Script
TinyGOでLightSensorを動かす

TinyGoで始める組み込みプログラミング
TinyGo on Arduino Uno: An Introduction

Circuit Playground Express
Adafruit Circuit Playground Express - Overview
Infrared Receive and Transmit with Circuit Playground Express

Adafruit Circuit Playground Express - PINOUT
Adafruit Circuit Playground Express Pin Assign

NUCLEO-F103RB mbed pinout
NUCLEO-F103RB Pin Assign
STM32F4DISCO Pin Assign
MICROBIT Pin Assign
ARDUINO-NANO Pin Assign
ARDUINO Pin Assign

TinyGo Drivers

USB Flashing Format (UF2)

XIAO Schematic(zip)
How to use Seeeduino XIAO to log in to your Raspberry PI

以上

続きを読む "XIAOボードでTinyGOを動かす(v2)"

| | コメント (0)

2020年8月15日 (土)

XIAOにWiFiモジュールを接続する(STARWARS)

2020/8/16:
接続、スケッチ改版

2020/8/15:
初版

PlatformIO XIAO WiFi-module

PlatformIO XIAO WiFi-module

概要

XIAOに以下のWiFiモジュールを接続する(STARWARS)
本記事は 「XIAOを使ってWiFiモジュール(ESP-WROOM-02)の動作確認をする」の続きになる。
(ホストPCとしてはubuntuを想定している)

ESP-WROOM-02開発ボード(AE-ESP-WROOM02-DEV)
このボードには出荷時にATファームウェアが書き込まれている。(WiFiモジュールとして使用する場合、Arduinoのファームなどを書き込まない)

接続

ESP-WROOM-02開発ボード(AE-ESP-WROOM02-DEV)の場合

AE-ESP-WROOM02-DEV XIAO
1(3V3入力) USB給電の場合、接続しない
2(EN) D8
14(TXD) D7(RX)
13(RXD) D6(TX)
9(GND) GND

USB給電の場合は、オンボードのUSBにホストPCなどを接続して行なう。(USBシリアルとしては使用しない)
XIAOのUSBシリアルして使用するので、XIOAのUSBはホストPCに接続して通信ソフトを起動する。

starwars_test

telnetでASCIIアートの「StarWars」アニメを表示するプログラム:
src/starwars_test.ino

// set your wifi ssid, passwd #define MY_SSID "your_ssid" #define MY_PASSWD "your_passwd" #define esp8266_reset_pin 8 // Connect this pin to CH_PD(chip power-down) on the esp8266, not reset. char res[6000]; // need big buffer for StarWars bool printReply = true; const char Hline[] = "-----\n\r"; char ipAddress [20]; void getReply(int wait) { int tempPos = 0; long int time = millis(); while( (time + wait) > millis()) { while(Serial1.available()>0) { char c = Serial1.read(); //if (tempPos < 500) { res[tempPos] = c; tempPos++; } res[tempPos] = c; tempPos++; } res[tempPos] = 0; } if (printReply) { Serial.println( res ); Serial.println(Hline); } } void setup() { // **** we need chip rest **** pinMode(esp8266_reset_pin, OUTPUT); digitalWrite(esp8266_reset_pin, LOW);//Start with radio off //delay(500); delay(1000); digitalWrite(esp8266_reset_pin, HIGH); // select the radio // **** end of chip rest **** // serials init while (!Serial); while (!Serial1); Serial.begin(115200); //serial port of Arduino Main Serial1.begin(115200); //serial port of ESP8266 delay(3000); //Serial.print("Type a key to start.\r\n"); //while(!Serial.available()) continue; // wait for some input //pinMode(LED_BUILTIN, OUTPUT); //delay(3000); Serial.print("\r\n\r\n\r\n\r\n\r\n"); // no need rest command /********* Serial1.print("AT+RST\r\n"); getReply(2000); ***********/ Serial1.print("AT+GMR\r\n"); getReply(2000); Serial1.print("AT+CWQAP\r\n"); getReply(2000); Serial1.print("AT+CWMODE=1\r\n"); getReply(2000); // set your own wifi Serial1.printf("AT+CWJAP=\"%s\",", MY_SSID); Serial1.printf("\"%s\"\r\n", MY_PASSWD); getReply(10000); Serial1.print("AT+CIFSR\r\n"); getReply(10000); //-- get IP Address -- int len = strlen( res ); bool done=false; bool error = false; int pos = 0; while (!done) { if ( res[pos] == '\"') { done = true;} pos++; if (pos > len) { done = true; error = true;} } if (!error) { int buffpos = 0; done = false; while (!done) { if ( res[pos] == '\"' ) { done = true; } else { ipAddress[buffpos] = res[pos]; buffpos++; pos++; } } ipAddress[buffpos] = 0; } else { strcpy(ipAddress,"ERROR"); } Serial.printf("ipAddress:%s\r\n\r\n",ipAddress); Serial1.print("AT+CIPMUX=1\r\n"); getReply( 1500 ); Serial1.print("AT+CIPSERVER=1,80\r\n"); getReply( 1500 ); // display off printReply = false; // telnet access //Serial.print("AT+CIPSTART=1,\"TCP\",\"towel.blinkenlights.nl\",23\r\n"); //Serial1.print("AT+CIPSTART=1,\"TCP\",\"towel.blinkenlights.nl\",23\r\n"); // do this if DNS fail Serial.print("AT+CIPSTART=1,\"TCP\",\"94.142.241.111\",23\r\n"); Serial1.print("AT+CIPSTART=1,\"TCP\",\"94.142.241.111\",23\r\n"); } //------------------------------------------------------- void get_res(void) { int cpos = 0; for(int cc=0; cc<24000000; cc++) { while (Serial1.available()) { res[cpos] = (char)Serial1.read(); cpos++; }; }; res[cpos] = 0; } void get_res2(void) { int cpos = 0; for(int cc=0; cc<500000; cc++) { while (Serial1.available()) { res[cpos] = (char)Serial1.read(); cpos++; }; }; res[cpos] = 0; } //------------------------------------------------------- void dispatch(void) { // setup string pointer table char *h[20]; for(int i=0; i<20; i++) h[i]=NULL; h[0] = &res[0]; int pi = 1; int cp; int len = (int)strlen(res); // keep length of res[] for (int i=0; i<len; i++) { if ((res[i]=='+') && (res[i+1]=='I') && (res[i+2]=='P') && (res[i+3]=='D') ) { // check +IPD //for (cp = i+3; cp<len; cp++) { for (cp = i+4; cp<len; cp++) { if (res[cp]==':') break; } res[i] = 0; // make string terminator h[pi] = &res[cp+1]; pi++; } }; // display removed IPD header for(int i=0; i<20; i++) { if (h[i] != NULL) Serial.print(h[i]); } } //------------ void loop() { digitalWrite(LED_BUILTIN, HIGH); // debug: for indicate in-loop /** // test loop while(true) { if (Serial1.available()) Serial.write((char)Serial1.read()); if (Serial.available()) Serial1.write((char)Serial.read()); }; **/ while(true) { get_res2(); //getReply(1000); if ((int)strlen(res) != 0) { //usart0_print("\r\nRES:\r\n"); //usart0_println(res); dispatch(); } else { //usart0_print("."); // indicating input wait } } }

以下については、自分の環境に合わせて変更すること:
#define MY_SSID "your_ssid"
#define MY_PASSWD "your_passwd"

書き込み後に「picocom /dev/ttyACM0 -b115200」で通信ソフトを起動すると以下のような出力が表示される:

$ picocom /dev/ttyACM0 -b115200 AT+GMR AT version:1.7.4.0(May 11 2020 19:13:04) SDK version:3.0.4(9532ceb) compile time:May 27 2020 10:12:20 Bin version(Wroom 02):1.7.4 OK WIFI GOT IP ----- AT+CWQAP OK WIFI DISCONNECT ----- AT+CWMODE=1 OK ----- AT+CWJAP="YOUR_SSID","YOUR_PASSWD" WIFI CONNECTED WIFI GOT IP OK ----- AT+CIFSR +CIFSR:STAIP,"192.168.0.19" +CIFSR:STAMAC,"84:f3:eb:87:14:72" OK <省略> # STARWARSのASCIIアートのアニメが表示される

実行するとStarWarsのASCIIアートのアニメが表示される。

参考情報

PlatformIO Core (CLI)

ESP8266をTCPサーバとTCPクライアントにするATコマンド実例 (1/4)
esp8266_at_command_examples_en.pdf

ESP8266をWifiモデムとして使う - ATコマンドによるMQTT通信
MQTT_via_ESP01
Arduino WiFi library for ESP8266 modules

espressif/ESP8266_AT - examples
Espressif Documentation

「wio lite RISC-V」による実装例:
Wio_Lite_RISC-VボードでWiFiを動かす(その4:MQTT)
Wio_Lite_RISC-VボードでWiFiを動かす(その3:OSC)
Wio_Lite_RISC-VボードでWiFiを動かす(その2:STARWARS,REST-API)
Wio_Lite_RISC-VボードでWiFiを動かす
開発ツールPlatformIOをcliで使う(Wio_Lite_RISC-V版)

以上

続きを読む "XIAOにWiFiモジュールを接続する(STARWARS)"

| | コメント (0)