« Teensy3.6ボードでTinyGOを動かす | トップページ | M5Atomを開発ツールPlatformIOで使う(Windows10版) »

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

以上

|

« Teensy3.6ボードでTinyGOを動かす | トップページ | M5Atomを開発ツールPlatformIOで使う(Windows10版) »

TinyGO」カテゴリの記事

XIAO」カテゴリの記事

windows10」カテゴリの記事

コメント

コメントを書く



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




« Teensy3.6ボードでTinyGOを動かす | トップページ | M5Atomを開発ツールPlatformIOで使う(Windows10版) »