windows10

2021年3月10日 (水)

platfomioを使ってnaitive(linux/windows)のプログラムをビルドする方法

2021/3/10
初版

platformio naitive build

platformio naitive build

概要

platfomioを使ってnaitive(linux/windows)のプログラムをビルドする方法について述べる。
ここでは、platformioがインストール済みを前提とする。
実行環境はubuntuとwindows10を前提にする。

windows10の場合

ここでは既にscoopなどでplatformioがインストール済みとする。
以下の2つのファイルをプロジェクト・デレクトリに用意する:
platformio.ini

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter, extra scripting ; Upload options: custom port, speed and extra flags ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples ; http://docs.platformio.org/page/projectconf.html [env:windows_x86] # Stable version #platform = windows_x86 # Development version platform = https://github.com/platformio/platform-windows_x86.git

src/main.c

#include <stdio.h> int main() { printf("Hello World from PlatformIO!\n"); return 0; }

ビルド/実行の例:
PowerShell

mkdir win cd win notepad platformio.ini #上の内容になるように編集する。 mkdir src notepad src/main.c #上の内容になるように編集する。 pio run -t clean #必要なツールのダウンロードとインストールが行われる。 # ビルド pio run # 実行 .\.pio\build\windows_x86\program.exe #(実行・出力例) Hello World from PlatformIO!

ubuntuの場合

ここでは既にplatformioがインストール済みとする。
以下の2つのファイルをプロジェクト・デレクトリに用意する:
platformio.ini

; PlatformIO Project Configuration File ; ; Build options: build flags, source filter, extra scripting ; Upload options: custom port, speed and extra flags ; Library options: dependencies, extra library storages ; ; Please visit documentation for the other options and examples ; http://docs.platformio.org/page/projectconf.html [env:linux_x86_64] # Stable version #platform = linux_x86_64 # Development version platform = https://github.com/platformio/platform-linux_x86_64.git

src/main.c

#include <stdio.h> int main() { printf("Hello World from PlatformIO!\n"); return 0; }

ビルド/実行の例:
bash

mkdir pc cd pc gedit platformio.ini #上の内容になるように編集する。 mkdir src gedit src/main.c #上の内容になるように編集する。 pio run -t clean #必要なツールのダウンロードとインストールが行われる。 # ビルド pio run # 実行 ./.pio/build/linux_x86_64/program #(実行・出力例) Hello World from PlatformIO!

参考情報

platformio関連:
windows10にplatformioをインストールする(scoop版)
arduinoフレームワーク用platformio.ini集(linux版PlatformIOのインストール方法)

PlatformIO Core (CLI)
Arduino-IDEとPlatformioのコンパイラーの挙動の違いについて
ubuntu20.04をインストールする

以上

続きを読む "platfomioを使ってnaitive(linux/windows)のプログラムをビルドする方法"

| | コメント (0)

2021年3月 1日 (月)

windows10にplatformioをインストールする(scoop版)

2021/3/1

platformio windows10

platformio windows10

概要

windows10にplatformioをインストールする(scoop版)
windows10にscoopでplatformioをインストールする方法について述べる。

platformioをインストールする

PowerShell

# scoopをインストール Set-ExecutionPolicy RemoteSigned -scope CurrentUser iwr -useb get.scoop.sh | iex # pythonをインストールする scoop install python pip3 install platformio # (必要があれば)windows用VScodeをインストールする scoop bucket add extras scoop install vscode # 別の機能が割り当てられているaliasを削除する del alias:curl del alias:wget # curl, wgetをインストールする scoop install curl scoop install wget # その他の必要となるツールをインストールする scoop install git

scoopの簡単な説明:

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

platformioの使い方

# プロジェクトのディレクトリを作る # (一つのスケッチごとに一つのディレクトリ) mkdir proj cd proj # ソースを置くディレクトリsrcを作る mkdir src # スケッチを作成する # (テスト・スケッチとして以降にASCIITable.inoがある) notepad src/main.ino # 使うボードに対応したplatformio.iniを作る # (内容については以降を参照のこと) notepad platformio.ini # スケッチをビルドする # (最初の1回はライブラリ・ツールを自動的にダウンロードする) pio run # ボードをUSB接続して書き込む pio run -t upload

platformio.iniの具体的な内容は「arduinoフレームワーク用platformio.ini集」を参照のこと

その他の使い方

# build結果をクリアする pio run -t clean # キャッシュをクリアする # (ツールやライブラリがダウンロードし直しになるので注意のこと) rm -r .pio # 環境を切り替えて書き込む pio run -e f303 -t upload pio run -e f103 -t upload

環境を切り替えて書き込む場合のplatformio.iniは
以下のように複数の環境[env:xxx]を持っていること:
platformio.ini

[env:f103] platform = ststm32 board = nucleo_f103rb framework = arduino build_flags = -DNUCLEO_F103RB monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = stlink #lib_deps = [env:f303] platform = ststm32 board = nucleo_f303k8 framework = arduino build_flags = -DNUCLEO_F303K8 monitor_speed = 115200 lib_ldf_mode = deep+ upload_protocol = stlink #lib_deps =

[env:xxxx]のxxxxの部分は環境名にあたり、 ダブらない任意の名前であること。

テスト用スケッチ

src/ASCIItable.ino

/* 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(115200); 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++; }

本スケッチはarduinoのサンプルそのもの(bpsのみ変更)である。

alias削除の永続化

インストール時に以下でalias削除したものは、PowerShellのセッションを閉じると無効になり復活する。

# 別の機能が割り当てられているaliasを削除する del alias:curl del alias:wget

したがって、削除を永続化するためにセッション起動時に自動実行されるPowerShellのスクリプト(Microsoft.PowerShell_profile.ps1)の 末尾に以下を追加する: Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
(存在しない場合、新規に作成する)

del alias:curl del alias:wget

ビルド・エラー

Arduino-IDEのコンパイラと異なり、platformioのコンパイラは、関数定義の後方参照を許さないので、 この場合、関数の未定義エラーになる。したがって、Arduino-IDEでビルドできているソースでもエラーになることがある。このときの対応方法は、未定義エラーになる関数定義をプロトタイプ宣言としてソースの先頭に置き、後方参照を解消する。(関数定義の本体の位置はそのままで移動させる必要はない)

参考情報

WindowsコマンドラインツールScoopのすすめ(基礎編)
Windowsでパッケージ管理したいなら、先ずScoopより始めよ
PowerShell コンソール内で curl や wget が実行できないとお嘆きのあなたへ

PlatformIO M5ATOM on Windows10
TinyGO Install XIAO on Windows10

M5Stack関連:
PlatformIO M5Stack開発の現状
・https://github.com/m5stack/M5StickC-Plus.git
・https://github.com/m5stack/M5StickC.git
・https://github.com/m5stack/M5Stack.git

micro:bit関連:
micro:bit Arduino/MBED開発ツール(v2)(micro:bit-v2対応,linux版)
micro:bit v2 で遊ぶ

platformio関連:

https://docs.platformio.org/en/latest/platforms/creating_board.html Installation 1.Create boards directory in core_dir if it doesn’t exist. 2.Create myboard.json file in this boards directory. 3.Search available boards via pio boards command. You should see myboard board.

PlatformIO Core (CLI)
Arduino-IDEとPlatformioのコンパイラーの挙動の違いについて
ubuntu20.04をインストールする
Advanced Scripting - Before/Pre and After/Post actions

以上

続きを読む "windows10にplatformioをインストールする(scoop版)"

| | コメント (0)

2020年10月 9日 (金)

M5Atomを開発ツールPlatformIOで使う(Windows10版)

2020/10/9+

PlatformIO M5ATOM on Windows10

PlatformIO M5ATOM on Windows10

概要

以下のM5Atomを開発ツールPlatformIOで使う(Windows10版)。
ホストPCとしてはwindows10を想定している。

ATOM Lite
ATOM Matrix

Peripherals Pin Map

Lite:

Func GPIO
RGB Led(Neo) G27
Btn G39
IR G12

Matrix:

Func GPIO
Neo G27
Btn G39
IR G12
CLK(MPU6886) G21
SDA(MPU6886) GP25

Grove Interface

GND 5V G26 G32
GND 5V SDA SCL

platformioをインストールする

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

# scoopをインストール Set-ExecutionPolicy RemoteSigned -scope CurrentUser iwr -useb get.scoop.sh | iex # pythonをインストールする scoop install python pip3 install platformio # 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

テスト用プロジェクト sample を作成/実行する

# プロジェクト sample のディレクトリを作成する mkdir sample cd sample # 以下を実行して必要なファイルを作成する pio init --board m5stick-c # platformをupdateする pio platform update code 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:esp32dev] platform = espressif32 board = m5stick-c framework = arduino monitor_speed = 115200 lib_deps = # use M5Atom lib 3113 # use "FastLED" 126 lib_ldf_mode = deep+
# テスト用のbutton.inoを作成する code src/button.ino 以下のように編集する:
/**************************************************************** * * This Example is used to test button * * Arduino tools Setting * -board : M5StickC * -Upload Speed: 115200 / 750000 / 1500000 * ****************************************************************/ #include "M5Atom.h" uint8_t DisBuff[2 + 5 * 5 * 3]; void setBuff(uint8_t Rdata, uint8_t Gdata, uint8_t Bdata) { DisBuff[0] = 0x05; DisBuff[1] = 0x05; for (int i = 0; i < 25; i++) { DisBuff[2 + i * 3 + 0] = Rdata; DisBuff[2 + i * 3 + 1] = Gdata; DisBuff[2 + i * 3 + 2] = Bdata; } } void setup() { M5.begin(true, false, true); delay(10); setBuff(0xff, 0x00, 0x00); M5.dis.displaybuff(DisBuff); } uint8_t FSM = 0; void loop() { if (M5.Btn.wasPressed()) { switch (FSM) { case 0: setBuff(0x40, 0x00, 0x00); break; case 1: setBuff(0x00, 0x40, 0x00); break; case 2: setBuff(0x00, 0x00, 0x40); break; case 3: setBuff(0x20, 0x20, 0x20); break; default: break; } M5.dis.displaybuff(DisBuff); FSM++; if (FSM >= 4) { FSM = 0; } } delay(50); M5.update(); }

続き:

# build pio run # ボードをホストPCに接続する # build&upload(flash) pio run -t upload # buildしないで書き込む場合は以下を実行する: pio run -t nobuild -t upload -v # -v は、詳細を表示するオプション # 以上で、基本的な操作としては完了となる

書き込み後、ボタンを押す度に、LEDの色が変化する。 (本スケッチは、Matrix/Lite兼用になっていて、Matrixの場合、5x5のLEDが同じ色で光る。Liteの場合、一つのLEDが光る)

これ以降、別のプログラムを動かすときは sampleのディレクトリをまるごと コピーして別のプロジェクトのディレクトリを作り そこにプログラム(.ino)を置く。

例:

cp sample m5a_proj01 cd m5a_proj01 ...

MPU6886を利用するスケッチ#1(Matrix限定)

src/mpu6886_2.ino

#include "M5Atom.h" #define SIG_MAX (4096) uint8_t DisBuff[2 + 5 * 5 * 3]; int16_t adX,adY,adZ; void setBuffP(uint8_t posData, uint8_t Rdata, uint8_t Gdata, uint8_t Bdata) { DisBuff[2 + posData * 3 + 0] = Rdata; DisBuff[2 + posData * 3 + 1] = Gdata; DisBuff[2 + posData * 3 + 2] = Bdata; } void setBuff(uint8_t Rdata, uint8_t Gdata, uint8_t Bdata) { for (uint8_t i = 0; i < 25; i++) setBuffP(i, Rdata, Gdata, Bdata); } void shftBuff() { for (uint8_t i = 24; i > 0; i--) { for (uint8_t j = 0; j < 3; j++) DisBuff[2 + i * 3 + j] = DisBuff[2 + (i-1) * 3 + j]; } } void setup() { DisBuff[0] = 0x05; DisBuff[1] = 0x05; M5.begin(false, true, true); delay(10); M5.IMU.Init(); setBuff(0x20, 0x20, 0x20); M5.dis.displaybuff(DisBuff); // Serial.begin(115200); } void loop() { M5.update(); if (M5.Btn.read()==0) { M5.IMU.getAccelAdc(&adX, &adY, &adZ); int r = min(max((int)map(adX,-SIG_MAX,SIG_MAX,0,255),0),255); int g = min(max((int)map(adY,-SIG_MAX,SIG_MAX,0,255),0),255); int b = min(max((int)map(adZ,-SIG_MAX,SIG_MAX,0,255),0),255); shftBuff(); setBuffP(0,r,g,b); M5.dis.displaybuff(DisBuff); // Serial.printf("x,y,z: %d,%d,%d\r\n", adX, adY, adZ); } delay(20); }

書き込み実行し、M5Atomを傾けるとそれに応じて5x5のLEDの色が変化する。

MPU6886を利用するスケッチ#2(Matrix限定)

src/mpu6886_3.ino

#include "M5Atom.h" float accX = 0, accY = 0, accZ = 0; float gyroX = 0, gyroY = 0, gyroZ = 0; float temp = 0; bool IMU6886Flag = false; void setup() { M5.begin(true, false, true); if (M5.IMU.Init() != 0) IMU6886Flag = false; else IMU6886Flag = true; } void loop() { if (IMU6886Flag == true) { M5.IMU.getGyroData(&gyroX, &gyroY, &gyroZ); M5.IMU.getAccelData(&accX, &accY, &accZ); M5.IMU.getTempData(&temp); Serial.printf("%.2f,%.2f,%.2f o/s \r\n", gyroX, gyroY, gyroZ); Serial.printf("%.2f,%.2f,%.2f mg\r\n", accX * 1000, accY * 1000, accZ * 1000); Serial.printf("Temperature : %.2f C \r\n", temp); } delay(500); M5.update(); }

WiFi対応スケッチ

ESP32のWiFi対応スケッチと互換性があるので、以下をソースの先頭に入れると動作するようだ。

#ifdef M5ATOM #include "M5Atom.h" #define ESP32 #endif

したがって、以下のスケッチの先頭に上のコードを入れるとM5Atomでも動作するようになる:
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチでWorld Time APIを使う(WorldTimeAPI編)
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(HTTP-ACCESS編)
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(REST-API2編)
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(OSC編)
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(MQTT編)

補足

「Serial.printf("Temperature : %.2f C \r\n", temp);」などが動作していないようだ。 (USBシリアルが動作していないようだ)

参考情報

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

Atom pixel tool
wget https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/software/AtomPixTool.exe
windowsのプログラムだがlinuxのwineでも動作するようだ。
マトリックスのデザインを作成でき、それを保存すると、そのデータのC言語ソースができあがる

Display API Document:
https://github.com/m5stack/M5Atom

サンプル・スケッチ:
git clone https://github.com/m5stack/M5Atom.git
git clone https://github.com/hajimef/m5atom-matrix-samples.git
M5AtomをPlatformIOで動かす-ライブラリインストールから加速度取得まで

PlatformIO Core (CLI)

以上

続きを読む "M5Atomを開発ツールPlatformIOで使う(Windows10版)"

| | コメント (0)

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)