« M5Stamp-C3 Arduino Install | トップページ | verilog事始め(sample#4 @Gowin RUNBER board) »

2021年12月12日 (日)

M5Stamp-PICO Arduino Install

2021/12/12
初版

M5Stamp-PICO Arduino Install

M5Stamp-PICO Arduino Install

概要

Arduino-IDEで「M5Stamp Pico Mate」を動かす。
ただし、本ボード単体では書き込みができないので、USBシリアルボードを用意する必要がある。キットとして書き込みボード付きの「M5Stamp Pico DIY Kit」ものもあるので、それを購入するのが一番簡単である。
書き込みのピン配列も合わせてあるので、余計なジャンパー無しに使用できる。ただし、価格的に割高な感がある。
なお、Arduino-IDEの最新版がインストール済みのものとする。
また、platformioでの使用する際のplatformio.iniについても記載する。

linuxのArduino-IDEのインストールについては以下を参照のこと。
Install the Arduino Software (IDE) on Linux

本記事は、linux版Arduino-IDEについて記述したものであるが、 ほとんど、そのままwindows版でも適応可能である。

USB serial ドライバーの設定

windows10については特別に何かをインストールする必要はなかった。
linuxの場合、udevの設定が必要になるが、platformioでの設定を以下のように流用する。

udev登録 以下を実行して、udevのrulesを登録する: 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

ボード情報(*.json)のインストール

Arduino-IDEを起動して以下を実行する:
1.[ファイル]/[環境設定]を選択する
2.画面の「追加のボードマネージャーのURL」に以下を入力(追加)する

https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json

3.入力後、[OK]をクリックする
4.[ツール]/[ボード]/[ボードマネージャー]を選択する
5.検索欄に「M5」と入力する
6.検索結果から「M5STACK」を選び、[インストール]をクリックする
7.インストール後、[閉じる]をクリックする

8.[ツール]/[ボード]/[M5Stack Arduino]/[STAMP-PICO]を選択する

以上で、ボードとして[STAMP-PICO]が選択されたことになる。

なお、シリアルポートは通常「/dev/ttyACM0」になる。

注意:
書き込みボード(ESP32-DOWNLOADER)は、接続用のピンをSTAMP-PICOボードに単純に差し込んだ状態でも書き込みが可能だが、
接触が不安定になるので、手で押さえるなり、接触が安定する工夫が必要となる。

以下、実際に動かしたスケッチを挙げる:

ASCIITablePico.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 modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. <http://www.zambetti.com> */ void setup() { //Initialize serial and wait for port to open: //Serial.begin(9600); 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 == '~') { thisByte = 33-1; Serial.println("--------------------------------------------------"); //Serial.println("--------------------------------------------------"); Serial.println(""); delay(500); /* // This loop loops forever and does nothing while (true) { continue; } */ } // go on to the next character thisByte++; }

Arduinoの標準サンプルをserialのbpsの変更とリセット無しに繰り返すようにしたものになる。

platformioの設定

plaformio.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 = esp32dev board = m5stick-c framework = arduino //upload_port = /dev/ttyUSB0 upload_port = /dev/ttyACM0 monitor_speed = 115200 lib_deps = # use M5Atom lib 3113 # use "FastLED" 126 lib_ldf_mode = deep+

sample code for platfomio

b3NTP.ino

// select board ////#define WIO_TERMINAL ////#define ESP8266 ////#define ESP32 ////#define M5ATOM //------------------ // NTP Client for Wio-Terminal/ESP8266/ESP32 #ifdef M5ATOM #include "M5Atom.h" #define ESP32 #endif #ifdef WIO_TERMAL //#include <AtWiFi.h> #include <rpcWiFi.h> #endif #ifdef ESP8266 #include <ESP8266WiFi.h> #endif #ifdef ESP32 #include <WiFi.h> #endif #include <time.h> #define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password" void setup() { Serial.begin(115200); delay(100); Serial.print("\r\n\nReset:\r\n"); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while(WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(500); } Serial.println(); Serial.printf("Connected, IP address: "); Serial.println(WiFi.localIP()); configTzTime("JST-9", "ntp.nict.jp", "ntp.jst.mfeed.ad.jp"); // 2.7.0以降, esp32コンパチ } void loop() { time_t t; struct tm *tm; static const char *wd[7] = {"Sun","Mon","Tue","Wed","Thr","Fri","Sat"}; t = time(NULL); tm = localtime(&t); /***** Serial.printf("ESP8266/Arduino ver%s : %04d/%02d/%02d(%s) %02d:%02d:%02d\n", __STR(ARDUINO_ESP8266_GIT_DESC), tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); ****/ Serial.printf("Arduino NTP: %04d/%02d/%02d(%s) %02d:%02d:%02d\r\n", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); delay(1000); }

以下はwifi環境に応じて変更すること:

#define WIFI_SSID "your_wifi_ssid" #define WIFI_PASSWORD "your_wifi_password"

本ソースは、WIO_TERMINAL、ESP8266、ESP32、M5ATOMで共通になっており、platformio.iniの内容でターゲットを切り替えることができる。

platformioのビルドと書き込み:

# ライブラリのインストール(1回目のみ) pio run -t clean # ボードをPCに接続する pio run -t upload

実行時のシリアル出力(/dev/ttyACM0):

........ Connected, IP address: 192.168.1.15 Arduino NTP: 1970/01/01(Thr) 09:00:04 Arduino NTP: 1970/01/01(Thr) 09:00:05 Arduino NTP: 1970/01/01(Thr) 09:00:06 Arduino NTP: 1970/01/01(Thr) 09:00:07 Arduino NTP: 1970/01/01(Thr) 09:00:08 Arduino NTP: 2021/12/11(Sat) 16:55:59 ← ここでNTPによって時刻が同期している Arduino NTP: 2021/12/11(Sat) 16:56:00 Arduino NTP: 2021/12/11(Sat) 16:56:01

sample code #2 for platformio

main.ino

#include <Adafruit_NeoPixel.h> #define BUTTON 39 // for STAMP-PICO #define LED 27 // for STAMP-PICO #define NUMPIXELS 1 Adafruit_NeoPixel pixels(NUMPIXELS, LED, NEO_GRB + NEO_KHZ800); int lastState = HIGH; int currentState; int buttonCount = 1; void setup() { Serial.begin(115200); pixels.begin(); pinMode(BUTTON, INPUT_PULLUP); } int high = 255; int mid = 128; int low = 0; void setLed() { pixels.clear(); switch (buttonCount) { case 1: pixels.setPixelColor(0, pixels.Color(high, low, low)); break; case 2: pixels.setPixelColor(0, pixels.Color(high, mid, mid)); break; case 3: pixels.setPixelColor(0, pixels.Color(low, high, low)); break; case 4: pixels.setPixelColor(0, pixels.Color(mid, high, mid)); break; case 5: pixels.setPixelColor(0, pixels.Color(low, low, high)); break; case 6: pixels.setPixelColor(0, pixels.Color(mid, mid, high)); break; default: break; } pixels.show(); } void loop() { currentState = digitalRead(BUTTON); if(lastState == LOW && currentState == HIGH) { Serial.println("Button Pressed!"); buttonCount++; if (buttonCount > 6) { buttonCount = 1; } setLed(); } lastState = currentState; }

本サンプルは「This is an example PlatformIO project for M5Stamp C3」のものをSTAMP-PICO用に変更したものになる。
動作としては、ボタンを押すたびにLEDの色が変化する。 またボタンを押すたびに「Button Pressed!」がシリアル出力される。

参考情報

M5Stamp-Pico docs:
M5STAMP-PICO-DIY-KIT
STAMP-PICO Arduino Library

M5Stamp-Pico関連:
M5Stack M5Stamp Picoを買ってみた

Arduino-IDE関連:
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

platformio関連:
arduinoフレームワーク用platformio.ini集
This is an example PlatformIO project for M5Stamp C3

その他:
スルーホール用テストワイヤ TT-200 (10本入)

以上

|

« M5Stamp-C3 Arduino Install | トップページ | verilog事始め(sample#4 @Gowin RUNBER board) »

PlatformIO」カテゴリの記事

Arduino」カテゴリの記事

M5Stamp-Pico」カテゴリの記事

コメント

この記事へのコメントは終了しました。