Wio Terminal

2022年2月 3日 (木)

Wio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする

2022/2/3
初版

Wio_ExtFlashLoad sketch build by platformio

Wio_ExtFlashLoad sketch build by platformio

概要

Wio Ext Flash Load」、 「External Flash Loader library for Wio Terminal」 にあるWio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする。
arduinoのサンプル・スケッチとして提供されているものだが、plaformioビルド環境でビルドする。
Wio_ExtFlashLoadは、アプリを起動するメニューになっており、
SDカードにビルドした.binを起き、それを選択して起動する。

WriteSampleMenu.ino

以下の手順をダウンロード/ビルド/書き込みする:

# platformioの環境に入る # プロジェクト・ディレクトリを作成する mkdir Wio_ExtFlashLoad cd Wio_ExtFlashLoad mkdir src cd src wget https://raw.githubusercontent.com/ciniml/ExtFlashLoader/master/examples/WriteSampleMenu/WriteSampleMenu.ino wget https://raw.githubusercontent.com/ciniml/ExtFlashLoader/master/examples/WriteSampleMenu/menu_data.h cd .. gedit platformio.ini # 後節にあるplatformio.iniの内容を作成する # ビルド&書き込み pio run -t upload

以上で、実行すると、メニューが表示されるようになる。

platformio.ini

wio-terminal用:

[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+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # arduino-libraries/NTPClient@^3.1.0 # ciniml/ExtFlashLoader@^0.1.2

アプリ用.binを作成する

アプリ用SDの詳細は「External Flash Loader library for Wio Terminal」に記述されているので、その中に入れる.binの作成方法について説明する。

「pio run」でビルドすると
以下に.binができる:

.pio/build/seeed_wio_terminal/firmware.bin

これをfirmware.binをapp.binにリネームしてSDにコピーする。

これだけでメニューから起動できる。
ただ、このままだとアプリ起動後、
メニューに戻ることができないので
setup()にボタンAを押しながらリセットしたときに
メニューに戻るコードを埋め込む。

(1)TFT_eSPI対応アプリの場合、「External Flash Loader library for Wio Terminal」の「アプリケーションのメニューアプリ対応」を参照のこと。

(2)LGFX対応アプリの場合は
以下のコードを埋め込む:

以下のヘッダーを追加する: /////////////////////////////////////////// // application menu header #include <cstdint> #include <ExtFlashLoader.h> /////////////////////////////////////////// 変更前: void setup() { lcd.init(); ------------------- → 変更後: void setup() { //// goto application menu /////////////// lcd.init(); pinMode(WIO_KEY_A, INPUT_PULLUP); if( digitalRead(WIO_KEY_A) == LOW) { lcd.print("Launching QSPI application\r\n"); // for LGFX ExtFlashLoader::ExtFlashLoader loader; } ////////////////////////////////////////// // //lcd.init();

platformio.iniには
以下のライブラリを追加する:

lib_deps = ... <省略> ... # ciniml/ExtFlashLoader@^0.1.2

参照情報

terminal関連:
Bootterm – a developer-friendly serial terminal program

LovyanGFX関連:
LovyanGFX - Display (LCD / OLED / EPD) graphics library (for ESP32 SPI, I2C, 8bitParallel / ESP8266 SPI, I2C / ATSAMD51 SPI) - M5Stack / M5StickC / TTGO T-Watch / ODROID-GO / ESP-WROVER-KIT / WioTerminal / and more...
LovyanGFX LCD Graphics driver
LovyanGFX-Display ライブラリを使用したスケッチをplatformioでビルドする

platformio関連:
arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

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

以上

続きを読む "Wio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする"

| | コメント (0)

2022年1月20日 (木)

Wio-TerminalでMQTTを動かす

2022/1/20
初版

Wio-Terminal MQTT

Wio-Terminal MQTT

概要

Wio-TerminalでMQTTを動かす。
MQTT on Wio Terminal」の記事のコードを利用して、Wio-TerminalでMQTTを動かす。
ビルド環境としては、platformioを使用する。
ここでは、Wio-TerminalをPublisher(送信側)、PCやiPhoneをSubscriber(受信側)にする。

Publisher(送信側)

当該の「MQTT on Wio Terminal」の記事のコードにある[ボタン]でコードをコピーまたはダウンロードして platformioのプロジェクト(ディレクトリ)のsrc配下に置く。
# ダウンロードしたものは、ファイルタイプが「.c」になっているので、「.ino」にする。

src配下に置いたコードに以下のパッチを当てる:

src/WioTerminal_MQTT_Example.ino

#6行目付近を以下のように変更する。(新しいファームを使用する) //#include <AtWiFi.h> // old firmware #include <rpcWiFi.h> #22行目付近を自分のWiFi環境に合わせて変更する。 // Update these with values suitable for your network. const char* ssid = "***"; // WiFi Name const char* password = "***"; // WiFi Password const char* mqtt_server = "broker.mqtt-dashboard.com"; // MQTT Broker URL

plaformio.iniは以下のものにする: 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: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+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # arduino-libraries/NTPClient@^3.1.0 # powerbroker2/SafeString@^4.1.14 seeed-studio/Seeed Arduino RTC@^2.0.0 # lovyan03/LovyanGFX@^0.4.10 https://github.com/tanakamasayuki/efont.git https://github.com/Tamakichi/Arduino-misakiUTF16.git # adafruit/Adafruit Unified Sensor@^1.1.4 adafruit/Adafruit BME280 Library@^2.2.2 adafruit/Adafruit DPS310@^1.1.1 adafruit/RTClib@^2.0.2 ;neironx/RTCLib@^1.6.0 ;wemos/WEMOS SHT3x@^1.0.0 https://github.com/Seeed-Studio/Grove_SHT31_Temp_Humi_Sensor.git # knolleary/PubSubClient@^2.8

以下のコマンドラインでビルドと書き込みを行う:

pio run -t upload #通信ソフトを起動する bt -L 1

USBシリアルからは、publishしているメッセージが表示される。

Subscriber(受信側)

Subscriberとしては、Andoroid,iPhone,PCが使用できるが、ここでは、PCとiPhoneを取り上げる:

PCの場合:
以下のurlにwebブラウザーでアクセスする。
http://www.hivemq.com/demos/websocket-client/
websocket client

[Connect]をクリックして、broker-serverに接続して Subscriptionsの[Add New Topic Subuscription]をクリックして Wio-TerminalのPublisherで使用しているTopicの「WTout」を入力して Subscribeする。
そうすると、Wio-Terminalからのメッセージが表示される。 以下、表示例:

Messages 2022-01-20 09:02:49 Topic: WTout Qos: 0 Wio Terminal #6241 2022-01-20 09:02:47 Topic: WTout Qos: 0 Wio Terminal #6240 2022-01-20 09:02:45 Topic: WTout Qos: 0 Wio Terminal #6239 2022-01-20 09:02:42 Topic: WTout Qos: 0 Wio Terminal #6238   ...

iPhoneの場合:
アプリとしてMQTTtoolかEasyMQTTをインストールして 以下の情報を設定する:

MQTTtool設定情報:

HOST broker.mqtt-dashboard.com Port 1883 Client ID アプリ側で自動設定されるので特に入力は無い Username/Passwaordは不要。 SubscribeのTopicは「WTout」を設定する。

EasyMQTT設定情報:

HOST broker.mqtt-dashboard.com Port 1883 Client ID Wio Terminal MQTT Username/Passwaordは不要。 SubscribeのTopicは「WTout」を設定する。

broker-serverの設定情報

MQTT connection settings

Connection Name: Public MQTT Broker Client ID: Wio Terminal MQTT(任意) Broker Web/IP address: broker.mqtt-dashboard.com TCP Port: 1883 Websocket Port: 8000

以下をアクセスするとMQTTのアクセス状況が表示される:
http://broker.mqtt-dashboard.com/
HIVEMQ MQTT Dashboard

参考情報

terminal関連:
Bootterm – a developer-friendly serial terminal program

Wio-Terminal関連:
wio-terminal firmware update(v2) (linux)
nixieクロックにNTPクライアントの機能を追加する(v2,rpcファーム対応)

MQTT関連:
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
10 Free Public MQTT Brokers(Private & Public)

platformio関連:
arduinoフレームワーク用platformio.ini集
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(REST-API編)
Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(OSC編)
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。
Arduino勉強会/37-RaspberryPi Picoをはじめよう - デバッガー

Arduino-IDE関連:
Raspberry Pi PicoでI2C/SPI通信
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

以上

続きを読む "Wio-TerminalでMQTTを動かす"

| | コメント (0)

2022年1月17日 (月)

wio-terminalでGROVEを使う

2022/1/17
初版

WIOT_TWO_GROVES

WIOT_TWO_GROVES

概要

wio-terminalでGROVEを使う。
Wio Terminal」はGROVEソケットを2つ持っている。 wio-terminalで、正面のボタンを下にして
右側のGROVEはアナログ入力/デジタル用ポート、
左側のGROVEはI2C用ポートになる。

参照:
Wio Terminal Wio Terminalをはじめよう

ここでは、右側のGROVEソケット(アナログ入力/デジタル・ポート)、左側のGROVE(I2Cポート)を使ったスケッチを紹介する。

アナログ入力ポートのスケッチ例

右側のGROVEにUNIT_ANGLE「M5Stack用回転角ユニット」を接続したスケッチを紹介する。

src/UNIT_ANGLE_wiot.ino

/* ******************************************************************************* * Copyright (c) 2021 by M5Stack * Equipped with Atom-Lite/Matrix sample source code * 配套 Atom-Lite/Matrix 示例源代码 * Visit the website for more information:https://docs.m5stack.com/en/products * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products * * describe:Angle. 角度计 * date:2021/8/9 ******************************************************************************* Description: Read the Angle of the angometer and convert it to digital display 读取角度计的角度,并转换为数字量显示 */ //#include <M5Atom.h> //int sensorPin = 32; // set the input pin for the potentiometer. 设置角度计的输入引脚 int sensorPin = 0; // for grove of wio-terminal int last_sensorValue = 100; // Stores the value last read by the sensor. 存储传感器上次读取到的值 int cur_sensorValue = 0; // Stores the value currently read by the sensor. 存储传感器当前读取到的值 void setup() { //M5.begin(); //Init M5Atom. 初始化 M5Atom Serial.begin(115200); pinMode(sensorPin, INPUT); //Sets the specified pin to input mode. 设置指定引脚为输入模式 //dacWrite(25, 0); } void loop() { // cur_sensorValue = analogRead(sensorPin); // read the value from the sensor. 读取当前传感器的值 cur_sensorValue = (500*analogRead(sensorPin))/330; // scalling for wio-terminal if(abs(cur_sensorValue - last_sensorValue) > 10){ //If the difference is more than 10. 如果差值超过10 Serial.print("the value of ANGLE: "); Serial.println(cur_sensorValue); last_sensorValue = cur_sensorValue; } delay(200); }

本スケッチはM5ATOMのものをwio-terminal用に変更したものである、

デジタル出力ポートとしてのスケッチ例

右側のGROVEに「GROVE - 7セグメント4桁ディスプレイ」を接続したスケッチを紹介する。

src/NumberFlow_wiot.ino

/* * TM1637.cpp * A library for the 4 digit display * * Copyright (c) 2012 seeed technology inc. * Website : www.seeed.cc * Author : Frankie.Chu * Create Time: 9 April,2012 * Change Log : * * The MIT License (MIT) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "TM1637.h" /* #define CLK 2//pins definitions for TM1637 and can be changed to other ports #define DIO 3 */ /* // for MAKER PI RP2040 #define CLK 27 //pins definitions for TM1637 and can be changed to other ports #define DIO 26 */ // wio-terminal #define CLK 0 #define DIO 1 TM1637 tm1637(CLK,DIO); void setup() { tm1637.init(); tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; } void loop() { int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F int8_t ListDisp[4]; unsigned char i = 0; unsigned char count = 0; delay(150); while(1) { i = count; count ++; if(count == sizeof(NumTab)) count = 0; for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++) { ListDisp[BitSelect] = NumTab[i]; i ++; if(i == sizeof(NumTab)) i = 0; } tm1637.display(0,ListDisp[0]); tm1637.display(1,ListDisp[1]); tm1637.display(2,ListDisp[2]); tm1637.display(3,ListDisp[3]); delay(1000); //(300); } }

I2Cポートのスケッチ例#1

左側のGROVEにM5Stack用「M5Stack用大気圧センサーユニット【M5STACK-U090】」を接続したスケッチになる。
本ユニットはBMP280を使用しており、BMP280のAdafruitのライブラリが使用できる。
以下は提供されているスケッチにピン割当、デバイスアドレスの変更をしたものである。

src/bmp280_sensortest_wiot.ino

/*************************************************************************** This is a library for the BMP280 humidity, temperature & pressure sensor This example shows how to take Sensor Events instead of direct readings Designed specifically to work with the Adafruit BMP280 Breakout ----> http://www.adafruit.com/products/2651 These sensors use I2C or SPI to communicate, 2 or 4 pins are required to interface. 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 & Kevin Townsend for Adafruit Industries. BSD license, all text above must be included in any redistribution ***************************************************************************/ #include <Wire.h> #include <SPI.h> #include <Adafruit_BMP280.h> Adafruit_BMP280 bmp; // use I2C interface Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor(); Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor(); void setup() { Serial.begin(9600); while ( !Serial ) delay(100); // wait for native usb Serial.println(F("BMP280 Sensor event test")); /******************** // MAKER // GROVE#4 for I2C#0 Wire.setSDA(16); Wire.setSCL(17); Wire.begin(); **********************/ unsigned status; //status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID); status = bmp.begin(0x76); // for BPS UNIT of M5Stack if (!status) { Serial.println(F("Could not find a valid BMP280 sensor, check wiring or " "try a different address!")); Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16); Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); Serial.print(" ID of 0x60 represents a BME 280.\n"); Serial.print(" ID of 0x61 represents a BME 680.\n"); while (1) delay(10); } /* Default settings from datasheet. */ bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ Adafruit_BMP280::FILTER_X16, /* Filtering. */ Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ bmp_temp->printSensorDetails(); } void loop() { sensors_event_t temp_event, pressure_event; bmp_temp->getEvent(&temp_event); bmp_pressure->getEvent(&pressure_event); Serial.print(F("Temperature = ")); Serial.print(temp_event.temperature); Serial.println(" *C"); Serial.print(F("Pressure = ")); Serial.print(pressure_event.pressure); Serial.println(" hPa"); Serial.println(); delay(2000); }

シリアル出力例:

BMP280 Sensor event test ------------------------------------ Sensor: BMP280 Type: Ambient Temp (C) Driver Ver: 1 Unique ID: 280 Min Value: -40.00 Max Value: 85.00 Resolution: 0.01 ------------------------------------ Temperature = 22.55 *C Pressure = 1010.33 hPa Temperature = 22.59 *C Pressure = 1010.26 hPa Temperature = 22.60 *C Pressure = 1010.27 hPa Temperature = 22.62 *C Pressure = 1010.28 hPa Temperature = 22.65 *C Pressure = 1010.28 hPa Temperature = 22.68 *C Pressure = 1010.29 hPa

I2Cポートのスケッチ例#2

Qwiic - 小型OLEDモジュールをQwiic->Grove変換ケーブル経由で左側のGROVEに接続する。

src/Example10_MultiDemo_v13.ino

/* SFE_MicroOLED Library Demo Paul Clark @ SparkFun Electronics Original Creation Date: December 11th, 2020 This sketch uses the MicroOLED library to show all the functionality built into the library using the begin function defined in version v1.3 of the library - which allows different TwoWire ports and custom I2C addresses to be used. If you are using the standard Micro OLED display, its I2C address will be 0x3D or 0x3C depending on how you have the D/C or ADDR jumper configured. Hardware Connections: This example assumes you are using Qwiic. See the SPI examples for a detailed breakdown of connection info. Want to support open source hardware? Buy a board from SparkFun! https://www.sparkfun.com/products/13003 https://www.sparkfun.com/products/14532 This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! Distributed as-is; no warranty is given. */ #include <Wire.h> #include <SFE_MicroOLED.h> //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED #define PIN_RESET 9 /* // This is the old way of instantiating oled. You can still do it this way if you want to. #define DC_JUMPER 1 MicroOLED oled(PIN_RESET, DC_JUMPER); // I2C declaration */ // From version v1.3, we can also instantiate oled like this (but only for I2C) MicroOLED oled(PIN_RESET); // The TwoWire I2C port is passed to .begin instead void setup() { delay(100); Wire.begin(); // <-- Change this to (e.g.) Qwiic.begin(); as required //Wire.setClock(400000); // Uncomment this line to increase the I2C bus speed to 400kHz /* // This is the old way of initializing the OLED. // You can still do it this way if you want to - but only // if you instantiated oled using: MicroOLED oled(PIN_RESET, DC_JUMPER) oled.begin(); // Initialize the OLED */ // This is the new way of initializing the OLED. // We can pass a different I2C address and TwoWire port oled.begin(0x3D, Wire); // Initialize the OLED /* // This is the new way of initializing the OLED. // We can pass a different I2C address and TwoWire port oled.begin(0x3C, Qwiic); // Initialize the OLED */ oled.clear(ALL); // Clear the display's internal memory oled.display(); // Display what's in the buffer (splashscreen) delay(1000); // Delay 1000 ms oled.clear(PAGE); // Clear the buffer. randomSeed(analogRead(A0) + analogRead(A1)); } void pixelExample() { printTitle("Pixels", 1); for (int i = 0; i < 512; i++) { oled.pixel(random(oled.getLCDWidth()), random(oled.getLCDHeight())); oled.display(); } } void lineExample() { int middleX = oled.getLCDWidth() / 2; int middleY = oled.getLCDHeight() / 2; int xEnd, yEnd; int lineWidth = min(middleX, middleY); printTitle("Lines!", 1); for (int i = 0; i < 3; i++) { for (int deg = 0; deg < 360; deg += 15) { xEnd = lineWidth * cos(deg * PI / 180.0); yEnd = lineWidth * sin(deg * PI / 180.0); oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd); oled.display(); delay(10); } for (int deg = 0; deg < 360; deg += 15) { xEnd = lineWidth * cos(deg * PI / 180.0); yEnd = lineWidth * sin(deg * PI / 180.0); oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd, BLACK, NORM); oled.display(); delay(10); } } } void shapeExample() { printTitle("Shapes!", 0); // Silly pong demo. It takes a lot of work to fake pong... int paddleW = 3; // Paddle width int paddleH = 15; // Paddle height // Paddle 0 (left) position coordinates int paddle0_Y = (oled.getLCDHeight() / 2) - (paddleH / 2); int paddle0_X = 2; // Paddle 1 (right) position coordinates int paddle1_Y = (oled.getLCDHeight() / 2) - (paddleH / 2); int paddle1_X = oled.getLCDWidth() - 3 - paddleW; int ball_rad = 2; // Ball radius // Ball position coordinates int ball_X = paddle0_X + paddleW + ball_rad; int ball_Y = random(1 + ball_rad, oled.getLCDHeight() - ball_rad); //paddle0_Y + ball_rad; int ballVelocityX = 1; // Ball left/right velocity int ballVelocityY = 1; // Ball up/down velocity int paddle0Velocity = -1; // Paddle 0 velocity int paddle1Velocity = 1; // Paddle 1 velocity //while(ball_X >= paddle0_X + paddleW - 1) while ((ball_X - ball_rad > 1) && (ball_X + ball_rad < oled.getLCDWidth() - 2)) { // Increment ball's position ball_X += ballVelocityX; ball_Y += ballVelocityY; // Check if the ball is colliding with the left paddle if (ball_X - ball_rad < paddle0_X + paddleW) { // Check if ball is within paddle's height if ((ball_Y > paddle0_Y) && (ball_Y < paddle0_Y + paddleH)) { ball_X++; // Move ball over one to the right ballVelocityX = -ballVelocityX; // Change velocity } } // Check if the ball hit the right paddle if (ball_X + ball_rad > paddle1_X) { // Check if ball is within paddle's height if ((ball_Y > paddle1_Y) && (ball_Y < paddle1_Y + paddleH)) { ball_X--; // Move ball over one to the left ballVelocityX = -ballVelocityX; // change velocity } } // Check if the ball hit the top or bottom if ((ball_Y <= ball_rad) || (ball_Y >= (oled.getLCDHeight() - ball_rad - 1))) { // Change up/down velocity direction ballVelocityY = -ballVelocityY; } // Move the paddles up and down paddle0_Y += paddle0Velocity; paddle1_Y += paddle1Velocity; // Change paddle 0's direction if it hit top/bottom if ((paddle0_Y <= 1) || (paddle0_Y > oled.getLCDHeight() - 2 - paddleH)) { paddle0Velocity = -paddle0Velocity; } // Change paddle 1's direction if it hit top/bottom if ((paddle1_Y <= 1) || (paddle1_Y > oled.getLCDHeight() - 2 - paddleH)) { paddle1Velocity = -paddle1Velocity; } // Draw the Pong Field oled.clear(PAGE); // Clear the page // Draw an outline of the screen: oled.rect(0, 0, oled.getLCDWidth() - 1, oled.getLCDHeight()); // Draw the center line oled.rectFill(oled.getLCDWidth() / 2 - 1, 0, 2, oled.getLCDHeight()); // Draw the Paddles: oled.rectFill(paddle0_X, paddle0_Y, paddleW, paddleH); oled.rectFill(paddle1_X, paddle1_Y, paddleW, paddleH); // Draw the ball: oled.circle(ball_X, ball_Y, ball_rad); // Actually draw everything on the screen: oled.display(); delay(25); // Delay for visibility } delay(1000); } void textExamples() { printTitle("Text!", 1); // Demonstrate font 0. 5x8 font oled.clear(PAGE); // Clear the screen oled.setFontType(0); // Set font to type 0 oled.setCursor(0, 0); // Set cursor to top-left // There are 255 possible characters in the font 0 type. // Lets run through all of them and print them out! for (int i = 0; i <= 255; i++) { // You can write byte values and they'll be mapped to // their ASCII equivalent character. oled.write(i); // Write a byte out as a character oled.display(); // Draw on the screen delay(10); // Wait 10ms // We can only display 60 font 0 characters at a time. // Every 60 characters, pause for a moment. Then clear // the page and start over. if ((i % 60 == 0) && (i != 0)) { delay(500); // Delay 500 ms oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left } } delay(500); // Wait 500ms before next example // Demonstrate font 1. 8x16. Let's use the print function // to display every character defined in this font. oled.setFontType(1); // Set font to type 1 oled.clear(PAGE); // Clear the page oled.setCursor(0, 0); // Set cursor to top-left // Print can be used to print a string to the screen: oled.print(" !\"#$%&'()*+,-./01234"); oled.display(); // Refresh the display delay(1000); // Delay a second and repeat oled.clear(PAGE); oled.setCursor(0, 0); oled.print("56789:;<=>?@ABCDEFGHI"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("JKLMNOPQRSTUVWXYZ[\\]^"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("_`abcdefghijklmnopqrs"); oled.display(); delay(1000); oled.clear(PAGE); oled.setCursor(0, 0); oled.print("tuvwxyz{|}~"); oled.display(); delay(1000); // Demonstrate font 2. 10x16. Only numbers and '.' are defined. // This font looks like 7-segment displays. // Lets use this big-ish font to display readings from the // analog pins. for (int i = 0; i < 25; i++) { oled.clear(PAGE); // Clear the display oled.setCursor(0, 0); // Set cursor to top-left oled.setFontType(0); // Smallest font oled.print("A0: "); // Print "A0" oled.setFontType(2); // 7-segment font oled.print(analogRead(A0)); // Print a0 reading oled.setCursor(0, 16); // Set cursor to top-middle-left oled.setFontType(0); // Repeat oled.print("A1: "); oled.setFontType(2); oled.print(analogRead(A1)); oled.setCursor(0, 32); oled.setFontType(0); oled.print("A2: "); oled.setFontType(2); oled.print(analogRead(A2)); oled.display(); delay(100); } // Demonstrate font 3. 12x48. Stopwatch demo. oled.setFontType(3); // Use the biggest font int ms = 0; int s = 0; while (s <= 5) { oled.clear(PAGE); // Clear the display oled.setCursor(0, 0); // Set cursor to top-left if (s < 10) oled.print("00"); // Print "00" if s is 1 digit else if (s < 100) oled.print("0"); // Print "0" if s is 2 digits oled.print(s); // Print s's value oled.print(":"); // Print ":" oled.print(ms); // Print ms value oled.display(); // Draw on the screen ms++; // Increment ms if (ms >= 10) // If ms is >= 10 { ms = 0; // Set ms back to 0 s++; // and increment s } } } void loop() { //pixelExample(); // Run the pixel example function lineExample(); // Then the line example function shapeExample(); // Then the shape example textExamples(); // Finally the text example } // Center and print a small title // This function is quick and dirty. Only works for titles one // line long. void printTitle(String title, int font) { int middleX = oled.getLCDWidth() / 2; int middleY = oled.getLCDHeight() / 2; oled.clear(PAGE); oled.setFontType(font); // Try to set the cursor in the middle of the screen oled.setCursor(middleX - (oled.getFontWidth() * (title.length() / 2)), middleY - (oled.getFontHeight() / 2)); // Print the title: oled.print(title); oled.display(); delay(1500); oled.clear(PAGE); }

提供されているスケッチが変更無しで動作した。

platformio.ini

以上のスケッチには、以下のplatformio.iniでビルドできる。

wio-terminal用:
platformio.ini

[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+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # arduino-libraries/NTPClient@^3.1.0 # powerbroker2/SafeString@^4.1.14 seeed-studio/Seeed Arduino RTC@^2.0.0 # lovyan03/LovyanGFX@^0.4.10 # adafruit/Adafruit Unified Sensor@^1.1.4 adafruit/Adafruit BME280 Library@^2.2.2 adafruit/Adafruit DPS310@^1.1.1 https://github.com/Seeed-Studio/Grove_SHT31_Temp_Humi_Sensor.git # seeed-studio/Grove 4-Digit Display@^1.0.0

参考情報

terminal関連:
Bootterm – a developer-friendly serial terminal program

GROVE使用スケッチ関連:
MAKER_PI_RP2040でI2Cを使う(Arduino編)

platformio関連:

arduinoフレームワーク用platformio.ini集
Building Core2 FactoryDemo in PlatformIO
VSCodeとPlatformIOでM5Stack Core2開発
M5Stack Core2とVSCode + PlatformIOとでM5Stackプログラミングを始めてみた。

Arduino-IDE関連:
Raspberry Pi PicoでI2C/SPI通信
Arduino IDE environment - M5Paper
Arduino IDEのインストールと設定 (Windows, Mac, Linux対応)

以上

続きを読む "wio-terminalでGROVEを使う"

| | コメント (0)

2021年2月18日 (木)

nixieクロックにNTPクライアントの機能を追加する(V2)

2021/2/18:
第2版

pio nixie NTP Client v2

pio nixie NTP Client v2

概要

以下のnixieクロックにNTPクライアントの機能を追加する(V2)

Wio nixie tube clock

本記事は「 nixieクロックにNTPクライアントの機能を追加する 」の第2版にあたる。 これは、wio-terminalのWiFiファームウェアのアップグレードに対する対応になる。(wio-terminalのファームウェア・アップデートについて(v2)(linux版))

NTPクライアントの機能を追加しているので、RTCのハードを追加する必要はない。 (ホストPCとしてはubuntuを想定している)

プロジェクト wiot-nixie-NTP のディレクトリを作成する

mkdir wiot-nixie-NTP cd wiot-nixie-NTP # 以下を実行して必要なファイルを作成する pio init --board seeed_wio_terminal # platformをupdateする pio platform update nano 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: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+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # 551 #https://github.com/arduino-libraries/NTPClient.git arduino-libraries/NTPClient@^3.1.0

該当スケッチのダウンロード

cd wiot-nixie-NTP wget https://macsbug.files.wordpress.com/2020/05/wio_nixie_tube_clock.zip_-4.pdf mv wio_nixie_tube_clock.zip_-4.pdf wio_nixie_tube_clock.zip unzip wio_nixie_tube_clock.zip cp Wio_nixie_tube_clock/*.* src/

デモ・スケッチ

上でダウンロートしたスケッチにNTPクライアント機能を追加して以下のようなソースに編集する:

src/Wio_nixie_tube_clock_NTP.ino

// NTP Client part added on 2020/08/01 by xshige //#include <AtWiFi.h> #include <rpcWiFi.h> #include <NTPClient.h> #include <WiFiUdp.h> const char *ssid = "your_ssid"; const char *password = "your_passwd"; //<---------------------------------------------------------- // derived/forked from http://mrkk.ciao.jp/memorandom/unixtime/unixtime.html #define ARRAYSIZE(_arr) (sizeof(_arr) / sizeof(_arr[0])) #define TIME_OFFSET 0 #define SECONDS_IN_A_DAY (24*60*60) #define EPOCH_DAY (1969*365L + 1969/4 - 1969/100 + 1969/400 + 306) // days from 0000/03/01 to 1970/01/01 #define UNIX_EPOCH_DAY EPOCH_DAY #define YEAR_ONE 365 #define YEAR_FOUR (YEAR_ONE * 4 + 1) // it is YEAR_ONE*4+1 so the maximum reminder of day / YEAR_FOUR is YEAR_ONE * 4 and it occurs only on 2/29 #define YEAR_100 (YEAR_FOUR * 25 - 1) #define YEAR_400 (YEAR_100*4 + 1) // it is YEAR_100*4+1 so the maximum reminder of day / YEAR_400 is YEAR_100 * 4 and it occurs only on 2/29 void ConvertUnixTimeToLocalTime(uint64_t unixtime, uint32_t *pyear, uint8_t *pmonth, uint8_t *pday, uint8_t *phour, uint8_t *pminute, uint8_t *psecond) { uint32_t unixday; uint16_t year = 0; uint8_t leap = 0; uint32_t n; uint8_t month, day, weekday; uint8_t hour, minute, second; static const uint16_t monthday[] = { 0,31,61,92,122,153,184,214,245,275,306,337 }; unixtime += TIME_OFFSET; second = unixtime % 60; minute = (unixtime / 60) % 60; hour = (unixtime / 3600) % 24; unixday = (uint32_t)(unixtime / SECONDS_IN_A_DAY); weekday = (uint8_t)((unixday + 3) % 7); // because the unix epoch day is thursday unixday += UNIX_EPOCH_DAY; // days from 0000/03/01 to 1970/01/01 year += 400 * (unixday / YEAR_400); unixday %= YEAR_400; n = unixday / YEAR_100; year += n * 100; unixday %= YEAR_100; if (n == 4){ leap = 1; } else { year += 4 * (unixday / YEAR_FOUR); unixday %= YEAR_FOUR; n = unixday / YEAR_ONE; year += n; unixday %= YEAR_ONE; if (n == 4) { leap = 1; } } if (leap != 0) { month = 2; day = 29; } else { month = (unixday * 5 + 2) / 153; day = unixday - monthday[month] + 1; // month += 3; if (month > 12) { ++year; month -= 12; } } *psecond = second; *pminute = minute; *phour = hour; *pyear = year; *pmonth = month; *pday = day; } //>---------------------------------------------------------- char *weekday[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; uint32_t year; uint8_t month, day, hour, minu, sec; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "ntp.nict.jp", 3600*9, 60000); // set JST // You can specify the time server pool and the offset, (in seconds) // additionaly you can specify the update interval (in milliseconds). // NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); //================================================================ // added NTP Client feature: 2020.08.01 xshige // Woi Terminal nixie tube clock : 2020.05.25 macsbug // https://macsbug.wordpress.com/2020/05/25/wio-nixie-tube-clock/ // M5Stack nixie tube clock : 2019.06.16 macsbug // https://macsbug.wordpress.com/2019/06/16/m5stack-nixie-tube-clock/ // M5StickC Nixie tube Clock : 2019.06.06 macsbug // https://macsbug.wordpress.com/2019/06/06/m5stickc-nixie-tube-clock/ // RTC DS3231 : https://wiki.52pi.com/index.php/Raspberry_Pi_Super_Capacitor_RTC(English) // RTClib : https://www.arduinolibraries.info/libraries/rt-clib // mode controll : 5 way switch // mode 1 : yyyy_mmdd_hhmmss // mode 2 : mmdd_hh_mmss // mode 3 : mmdd_ss_hhmm // rtc : DS3231, SDA1 = 2, SCL1= 3; #include <SPI.h> #include <TFT_eSPI.h> TFT_eSPI tft = TFT_eSPI(); #include <Wire.h> //#include "RTClib.h" //RTC_DS3231 rtc; #include "vfd_18x34.c" // font 18px34 #include "vfd_35x67.c" // font 35x67 #include "vfd_70x134.c" // font 70px134 #include "apple_35x41.c" // icon 35px41 uint32_t targetTime = 0; // for next 1 second timeout const uint8_t*n[] = { // vfd font 18x34 vfd_18x34_0,vfd_18x34_1,vfd_18x34_2,vfd_18x34_3,vfd_18x34_4, vfd_18x34_5,vfd_18x34_6,vfd_18x34_7,vfd_18x34_8,vfd_18x34_9 }; const uint8_t*m[] = { // vfd font 35x67 vfd_35x67_0,vfd_35x67_1,vfd_35x67_2,vfd_35x67_3,vfd_35x67_4, vfd_35x67_5,vfd_35x67_6,vfd_35x67_7,vfd_35x67_8,vfd_35x67_9, vfd_35x67_q,vfd_35x67_n }; const uint8_t*b[] = { // vfd font 70x134 vfd_70x134_0,vfd_70x134_1,vfd_70x134_2,vfd_70x134_3,vfd_70x134_4, vfd_70x134_5,vfd_70x134_6,vfd_70x134_7,vfd_70x134_8,vfd_70x134_9, vfd_70x134_q,vfd_70x134_n }; const char *monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; uint16_t yy; uint8_t mn, dd, hh, mm, ss; uint8_t md = 2; // mode 1, 2, 3 void setup() { // Serial.begin(115200); WiFi.begin(ssid, password); while ( WiFi.status() != WL_CONNECTED ) { delay ( 500 ); Serial.print ( "." ); } timeClient.begin(); //--------------------- tft.init(); tft.setRotation(3); tft.fillScreen(TFT_BLACK); pinMode(WIO_5S_PRESS, INPUT_PULLUP); /**** Wire.begin(SDA1,SCL1); delay(10); rtc.begin(); rtc.adjust(DateTime(__DATE__, __TIME__)); // Set the PC time // esp_timer_init(); // wifi_setup(); rtc_setup(); // Read the value of RTC ****/ } void loop() { timeClient.update(); // if (targetTime < esp_timer_get_time()/1000 ){ // display current clock on serial port ConvertUnixTimeToLocalTime(timeClient.getEpochTime(), &year, &month, &day, &hour, &minu, &sec); Serial.printf("%4d/%02d/%02d(%s): %02d:%02d:%02d\r\n", year, month, day, weekday[timeClient.getDay()], hour, minu, sec); /**** DateTime now = rtc.now(); yy = now.year(); mn = now.month(); dd = now.day(); hh = now.hour(); mm = now.minute(); ss = now.second(); ****/ yy = year; mn = month; dd = day; hh = hour; mm = minu; ss = sec; if(digitalRead(WIO_5S_PRESS) == LOW){ // mode change if (md == 3){md = 1;tft.fillRect(1,1,317,236,TFT_BLACK);return;} if (md == 2){md = 3;tft.fillRect(1,1,317,236,TFT_BLACK);return;} if (md == 1){md = 2;tft.fillRect(1,1,317,236,TFT_BLACK);return;} } if ( md == 3 ){ hhmm();} // yyyy,mm,dd,ss,hh,mm if ( md == 2 ){ yyyy_mmdd_hhmmss();} // yyyy,mm,dd,hh,mm,ss if ( md == 1 ){ mmss();} // mm,ss // periodic_ntp(); delay(500); } /**** void rtc_setup(){ DateTime now = rtc.now(); // time geting from RTC if (now.year() == 2165){ // rtc check tft.setCursor(20,200);tft.setTextColor(TFT_RED); tft.print("RTC not installed");delay(2000); tft.fillRect(1, 1, 317, 236, TFT_BLACK); }else{ yy = now.year(); mn = now.month(); dd = now.day(); hh = now.hour(); mm = now.minute(); ss = now.second(); //Serial.printf("%d %d %d %d %d %d\n",yy,mn,dd,hh,mm,ss); tft.setCursor(20,200);tft.setTextColor(TFT_BLUE); tft.print("SET UP RTC");delay(2000); tft.fillRect(1, 1, 317, 236, TFT_BLACK); } } ****/ void yyyy_mmdd_hhmmss(){ int y1 = (yy / 1000) % 10; int y2 = (yy / 100) % 10; int y3 = (yy / 10) % 10; int y4 = yy % 10; int ma = (mn / 10) % 10; int mb = mn % 10; int d1 = (dd / 10) % 10; int d2 = dd % 10; int h1 = (hh / 10) % 10; int h2 = hh % 10; int m1 = (mm / 10) % 10; int m2 = mm % 10; int s1 = (ss / 10) % 10; int s2 = ss % 10; //int p0 = 8; int x0 = 40; int t0 = 22; // icon //tft.pushImage( p0 + 0*x0, t0, 35,41, (uint16_t *)apple_35x41); int p1 = 80; int px1 = 40; int py1 = 5; tft.pushImage( p1 + 0*px1, py1, 35,67, (uint16_t *)m[y1]); tft.pushImage( p1 + 1*px1, py1, 35,67, (uint16_t *)m[y2]); tft.pushImage( p1 + 2*px1, py1, 35,67, (uint16_t *)m[y3]); tft.pushImage( p1 + 3*px1, py1, 35,67, (uint16_t *)m[y4]); int p2 = 80; int px2 = 40; int py2 = 76; tft.pushImage( p2 + 0*px2, py2, 35,67, (uint16_t *)m[ma]); tft.pushImage( p2 + 1*px2, py2, 35,67, (uint16_t *)m[mb]); //tft.drawPixel(118,13, ORANGE); tft.drawPixel(119,23,ORANGE); tft.pushImage( p2 + 2*px2, py2, 35,67, (uint16_t *)m[d1]); tft.pushImage( p2 + 3*px2, py2, 35,67, (uint16_t *)m[d2]); int p3 = 2; int px3 = 40; int py3 = 150; tft.pushImage( p3 + 0*px3, py3, 35,67, (uint16_t *)m[h1]); tft.pushImage( p3 + 1*px3, py3, 35,67, (uint16_t *)m[h2]); tft.pushImage( p3 + 2*px3, py3, 35,67, (uint16_t *)m[10]); tft.pushImage( p3 + 3*px3, py3, 35,67, (uint16_t *)m[m1]); tft.pushImage( p3 + 4*px3, py3, 35,67, (uint16_t *)m[m2]); tft.pushImage( p3 + 5*px3, py3, 35,67, (uint16_t *)m[10]); tft.pushImage( p3 + 6*px3, py3, 35,67, (uint16_t *)m[s1]); tft.pushImage( p3 + 7*px3, py3, 35,67, (uint16_t *)m[s2]); if ( s1 == 0 && s2 == 0 ){ fade1();} } void mmss(){ int ma = (mn / 10) % 10; int mb = mn % 10; int d1 = (dd / 10) % 10; int d2 = dd % 10; int h1 = (hh / 10) % 10; int h2 = hh % 10; int m1 = (mm / 10) % 10; int m2 = mm % 10; int s1 = (ss / 10) % 10; int s2 = ss % 10; int p0 = 8; int x0 = 40; int t0 = 22; // icon tft.pushImage( p0 + 0*x0, t0, 35,41, (uint16_t *)apple_35x41); int p2 = 65; int px2 = 40; int py2 = 10; tft.pushImage( p2 + 0*px2, py2, 35,67, (uint16_t *)m[ma]); tft.pushImage( p2 + 1*px2, py2, 35,67, (uint16_t *)m[mb]); //tft.drawPixel(118,13, ORANGE); tft.drawPixel(119,23,ORANGE); tft.pushImage( p2 + 2*px2, py2, 35,67, (uint16_t *)m[d1]); tft.pushImage( p2 + 3*px2, py2, 35,67, (uint16_t *)m[d2]); int p3 = 240; int px3 = 40; int py3 = 10; tft.pushImage( p3 + 0*px3, py3, 35,67, (uint16_t *)m[h1]); tft.pushImage( p3 + 1*px3, py3, 35,67, (uint16_t *)m[h2]); int p4 = 2; int px4 = 80; int py4 = 100; tft.pushImage( p4 + 0*px4 , py4, 70,134, (uint16_t *)b[m1]); tft.pushImage( p4 + 1*px4 -4, py4, 70,134, (uint16_t *)b[m2]); //tft.drawPixel(155,150, ORANGE); tft.drawPixel(155,190,ORANGE); tft.fillCircle(156,151,3,TFT_ORANGE);tft.fillCircle(156,191,3,TFT_ORANGE); tft.fillCircle(156,151,1,TFT_YELLOW);tft.fillCircle(156,191,1,TFT_YELLOW); tft.pushImage( p4 + 2*px4 +4, py4, 70,134, (uint16_t *)b[s1]); tft.pushImage( p4 + 3*px4 , py4, 70,134, (uint16_t *)b[s2]); if ( m1 == 0 && m2 == 0 ){ fade2();} } void hhmm(){ int ma = (mn / 10) % 10; int mb = mn % 10; int d1 = (dd / 10) % 10; int d2 = dd % 10; int h1 = (hh / 10) % 10; int h2 = hh % 10; int m1 = (mm / 10) % 10; int m2 = mm % 10; int s1 = (ss / 10) % 10; int s2 = ss % 10; //int p0 = 8; int x0 = 40; int t0 = 22; // icon //tft.pushImage( p0 + 0*x0, t0, 35,41, (uint16_t *)apple_35x41); int p2 = 65; int px2 = 40; int py2 = 10; tft.pushImage( p2 + 0*px2, py2, 35,67, (uint16_t *)m[ma]); tft.pushImage( p2 + 1*px2, py2, 35,67, (uint16_t *)m[mb]); //tft.drawPixel(118,13, ORANGE); tft.drawPixel(119,23,ORANGE); tft.pushImage( p2 + 2*px2, py2, 35,67, (uint16_t *)m[d1]); tft.pushImage( p2 + 3*px2, py2, 35,67, (uint16_t *)m[d2]); int p3 = 240; int px3 = 40; int py3 = 10; tft.pushImage( p3 + 0*px3, py3, 35,67, (uint16_t *)m[s1]); tft.pushImage( p3 + 1*px3, py3, 35,67, (uint16_t *)m[s2]); int p4 = 2; int px4 = 80; int py4 = 100; tft.pushImage( p4 + 0*px4 , py4, 70,134, (uint16_t *)b[h1]); tft.pushImage( p4 + 1*px4 -4, py4, 70,134, (uint16_t *)b[h2]); //tft.drawPixel( 155,150, ORANGE); tft.drawPixel(155,190,ORANGE); tft.fillCircle(156,151,3,TFT_ORANGE);tft.fillCircle(156,191,3,TFT_ORANGE); tft.fillCircle(156,151,1,TFT_YELLOW);tft.fillCircle(156,191,1,TFT_YELLOW); tft.pushImage( p4 + 2*px4 +4, py4, 70,134, (uint16_t *)b[m1]); tft.pushImage( p4 + 3*px4 , py4, 70,134, (uint16_t *)b[m2]); if ( h1 == 0 && h2 == 0 ){ fade2();} } void fade1(){ int p3 = 2; int px3 = 40; int py3 = 150; for ( int i = 0; i < 2; i++ ){ tft.pushImage( p3 + 2*px3, py3, 35,67, (uint16_t *)m[11]); tft.pushImage( p3 + 5*px3, py3, 35,67, (uint16_t *)m[11]); delay(25); tft.pushImage( p3 + 2*px3, py3, 35,67, (uint16_t *)m[10]); tft.pushImage( p3 + 5*px3, py3, 35,67, (uint16_t *)m[10]); delay(25); } } void fade2(){ int p3 = 2; int px3 = 40; int py3 = 150; for ( int i = 0; i < 2; i++ ){ tft.fillCircle(156,151,3,TFT_BLACK);tft.fillCircle(156,191,3,TFT_BLACK); delay(25); tft.fillCircle(156,151,3,TFT_ORANGE);tft.fillCircle(156,191,3,TFT_ORANGE); delay(25); } }

以下の変更がWiFiファームウェア・アップグレードの対応にあたる:

//#include <AtWiFi.h> #include <rpcWiFi.h>

以下については、自分の環境に合わせて変更すること:

const char *ssid = "your_ssid"; const char *password = "your_passwd";

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

$ picocom /dev/ttyACM0 -b115200 Terminal ready 2020/08/01(Sat): 22:44:44 2020/08/01(Sat): 22:44:44 2020/08/01(Sat): 22:44:45 2020/08/01(Sat): 22:44:46 2020/08/01(Sat): 22:44:46 2020/08/01(Sat): 22:44:47 2020/08/01(Sat): 22:44:48 2020/08/01(Sat): 22:44:48 2020/08/01(Sat): 22:44:49 2020/08/01(Sat): 22:44:49 2020/08/01(Sat): 22:44:50 2020/08/01(Sat): 22:44:50 2020/08/01(Sat): 22:44:51 2020/08/01(Sat): 22:44:51 2020/08/01(Sat): 22:44:52 2020/08/01(Sat): 22:44:53 2020/08/01(Sat): 22:44:53 2020/08/01(Sat): 22:44:54

また、起動後、ニキシー管の時計が表示され、ボタンで表示画面を切り換えられる。

参考情報

Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)

PlatformIO Core (CLI)

以上

続きを読む "nixieクロックにNTPクライアントの機能を追加する(V2)"

| | コメント (0)

2020年12月28日 (月)

Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)

2020/12/28:
初版

board3 Ascii STARWARS v2

board3 Ascii STARWARS v2

概要

Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)
本記事は「 Wio-TerminalでWiFiで使う(その2: STARTWARS,WEB_ACCESS) 」 のStarwarsのスケッチを複数ボード対応とwio-terminalのファームウェア・バージョンアップに対応したものである。

wio-terminalのファームウェアのバージョンアップで以下の不具合も解消している。
(描画速度も大幅な改善が見られる)

一部、以下のようなATコマンドのレスポンス・ヘッダーが表示されることがある。 wifi関係のライブラリにバグがあるようだ。 +IPD,4,988,94.142.241.111,23:__|_____|___________|__|____________|_||____ +IPD,4,1460,94.142.241.111,23: +IPD,4,1460,94.142.241.111,23: |(I/ /][][\| {}/ {} \[][][]

wio-terminalのファームウェアのアップデート方法については以下を参照のこと:
wio-terminalのファームウェア・アップデートについて(v2)(linux版)

デモ・スケッチ

src/wifi_starwars.ino

// select board ////#define WIO_TERMINAL ////#define ESP8266 ////#define ESP32 ////#define M5ATOM //------------------ #ifdef M5ATOM #include "M5Atom.h" #define ESP32 #endif #ifdef WIO_TERMINAL //#include <AtWiFi.h> #include <rpcWiFi.h> #endif #ifdef ESP8266 #include <ESP8266WiFi.h> #endif #ifdef ESP32 #include <WiFi.h> #endif const char* ssid = "your_ssid"; const char* passwd = "yours_passwd"; // Use WiFiClient class to create TCP connections WiFiClient client; void setup() { Serial.begin(115200); while(!Serial); // Wait for Serial to be ready delay(1000); // Set WiFi to station mode and disconnect from an AP if it was previously connected WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(2000); WiFi.begin(ssid, passwd); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.println("Connecting to WiFi.."); } Serial.println("Connected to the WiFi network"); Serial.print("IP Address: "); Serial.println (WiFi.localIP()); // prints out the device's IP address // set url for telnet const char* host = "towel.blinkenlights.nl"; const uint16_t port = 23; Serial.print("Connecting to "); Serial.println(host); while (!client.connect(host, port)) { Serial.println("Connection failed."); Serial.println("Waiting 5 seconds before retrying..."); delay(5000); } } void loop() { while (!client.available()) { delay(1); //delay 1 msec } // no buffering for ASCII Art Animation while (client.available()) { char c = client.read(); Serial.write(c); } /*********** if (client.available() > 0) { String line = client.readString(); // Read from the server response Serial.print(line); } ************/ }

wio-terminalのファームウェアのバージョン・アップにともない
以下のようにヘッダーが変更になっている:

//#include <AtWiFi.h> #include <rpcWiFi.h>

以下の#defineでボードを切り換えているがボードの種類を設定すると、 システムで設定されている定義が有効になるので特にソースを変更する必要はない。

#define WIO_TERMINAL #define ESP8266 #define ESP32 #define M5ATOM

以下については、自分の環境に合わせて変更すること:

const char ssid[] = "yours_ssid"; const char passwd[] = "yours_passwd";

書き込み後に「picocom /dev/ttyACM0 -b115200」または「picocom /dev/ttyUSB0 -b115200」で通信ソフトを起動すると以下のような出力が表示される:
(M5Atomの場合、実行時にリセット・ボタンを押す必要があるようだ)

$ picocom /dev/ttyACM0 -b115200 #以下のようなAsciiArtのアニメが実行される: ........... @@@@@ @@@@@ ........... .......... @ @ @ @ .......... ........ @@@ @ @ .......... ....... @@ @ @ ......... ...... @@@@@@@ @@@@@ th ........ ..... ----------------------- ....... .... C E N T U R Y ....... ... ----------------------- ..... .. @@@@@ @@@@@ @ @ @@@@@ ... == @ @ @ @ @ == __||__ @ @@@@ @ @ __||__ | | @ @ @ @ @ | | _________|______|_____ @ @@@@@ @ @ @ _____|______|_________

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 upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip

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:esp32dev] platform = espressif32 #board = esp32dev board = m5stick-c framework = arduino monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = # use M5Atom lib 3113 # use "FastLED" 126

ESP32の場合:

; 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 framework = arduino build_flags = -DESP32 monitor_speed = 115200 lib_ldf_mode = deep+

ESP8266の場合:

; 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:huzzah] platform = espressif8266 #board = huzzah board = esp_wroom_02 framework = arduino monitor_speed = 115200 lib_ldf_mode = deep+

wio-terminalのファームウェアを切り替えたときの注意

古いファームウェアのライブラリを動かした後は、古いライブラリがキャッシュで残っていると ビルド・エラーになるので以下を実行すること:

cd project_directory rm -r .pio/libdeps/seeed_wio_terminal/* rm -r .pio/build/seeed_wio_terminal/*

参考情報

PlatformIO Core (CLI)

以上

続きを読む "Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)"

| | コメント (0)

2020年12月27日 (日)

Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)

2020/12/27:
初版

board3 MQTT v2

board3 MQTT v2

概要

Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)

本記事は「 Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(MQTT編) 」 の改版にあたり、wio-terminalのファームウェア・バージョンアップに対応している。

wio-terminalのファームウェアのアップデート方法については以下を参照のこと:
wio-terminalのファームウェア・アップデートについて(v2)(linux版)

デモ・スケッチ

src/MQTT_test.ino

// select board ////#define WIO_TERMINAL ////#define ESP8266 ////#define ESP32 ////#define M5ATOM //------------------ // // MQTT program for Wio-Terminal/ESP8266/ESP32 // // Forked from the following code: //-------------------------------------------- // This example uses an Adafruit Huzzah ESP8266 // to connect to shiftr.io. // // You can check on your device after a successful // connection here: https://shiftr.io/try. // // by Joël Gähwiler // https://github.com/256dpi/arduino-mqtt //-------------------------------------------- #ifdef M5ATOM #include "M5Atom.h" #define ESP32 #endif #ifdef WIO_TERMINAL //#include <AtWiFi.h> #include <rpcWiFi.h> #endif #ifdef ESP8266 #include <ESP8266WiFi.h> #endif #ifdef ESP32 #include <WiFi.h> #endif #include <MQTT.h> const char ssid[] = "yours_ssid"; const char pass[] = "yours_passwd"; WiFiClient net; MQTTClient client; unsigned long lastMillis = 0; void connect() { Serial.print("checking wifi..."); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(1000); } Serial.print("\nconnecting..."); while (!client.connect("arduino", "try", "try")) { // for "broker.shiftr.io" //while (!client.connect("arduino", "", "")) { // no username. no passwd (for "mqtt.eclipse.org") Serial.print("."); delay(1000); } Serial.println("\nconnected!"); client.subscribe("topic0"); // client.unsubscribe("/hello"); } void messageReceived(String &topic, String &payload) { Serial.println("incoming: " + topic + " - " + payload); } void setup() { Serial.begin(115200); WiFi.begin(ssid, pass); // Note: Local domain names (e.g. "Computer.local" on OSX) are not supported by Arduino. // You need to set the IP address directly. // uncomment one of them to select MQTT server client.begin("broker.shiftr.io", net); //OK //client.begin("mqtt.eclipse.org", net); //OK //client.begin("test.mosquitto.org", net); //NG? client.onMessage(messageReceived); connect(); } void loop() { char s[100]; // buf for sprintf // dumy sensor values float pascals = 101312; float altm = 42; //m float tempC = 28.7; // deg C client.loop(); delay(10); // <- fixes some issues with WiFi stability if (!client.connected()) { connect(); } // publish a message roughly every second. if (millis() - lastMillis > 1000) { lastMillis = millis(); // publish sensor values sprintf(s,"{ \"press\" : %.2f, \"altm\" : %.1f, \"tempC\" : %.1f}", pascals/100, altm, tempC); client.publish("topic0", &s[0]); } delay(1000); }

wio-terminalのファームウェアのバージョン・アップにともない
以下のようにヘッダーが変更になっている:

//#include <AtWiFi.h> #include <rpcWiFi.h>

以下の#defineでボードを切り換えているがボードの種類を設定すると、 システムで設定されている定義が有効になるので特にソースを変更する必要はない。

#define WIO_TERMINAL #define ESP8266 #define ESP32 #define M5ATOM

以下については、自分の環境に合わせて変更すること:

const char ssid[] = "yours_ssid"; const char pass[] = "yours_passwd";

以下は利用するMQTTサーバー(broker)に合わせてコメントアウトする:

<省略> while (!client.connect("arduino", "try", "try")) { // for "broker.shiftr.io" //while (!client.connect("arduino", "", "")) { // no username. no passwd (for "mqtt.eclipse.org") <省略> <省略> client.begin("broker.shiftr.io", net); //OK //client.begin("mqtt.eclipse.org", net); //OK <省略>

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

$ picocom /dev/ttyACM0 -b115200 Terminal ready # 実際のセンサーを接続していないので一定のダミーデータを受信する incoming: topic0 - { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} incoming: topic0 - { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} incoming: topic0 - { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} incoming: topic0 - { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} incoming: topic0 - { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} incoming: topic0 - { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} ... <省略>

対向する送受信プログラム

以下をブラウザ(chromeのみ)で動かす:

MQTT_AT_webTestZero_02.html

<html> <script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script> <body> <script> //var mqtt_url = 'ws://test.mosquitto.org:8081' //var mqtt_url = 'ws://mqtt.eclipse.org/mqtt:443' var mqtt_url = 'wss://try:try@broker.shiftr.io' document.body.innerHTML = ''; var consout = 'MQTT over WebSockets Test'+'('+mqtt_url+')<br>' document.body.innerHTML = consout; //var mqtt = require('mqtt'); var client = mqtt.connect(mqtt_url); // subscribe Topic //client.subscribe('hello'); client.subscribe('topic0'); //client.subscribe('topic0/sample/hello'); //client.subscribe('topic0/sample/#'); // wildcard topic //client.subscribe('topic0/#'); //client.subscribe('#'); client.on('message', function(topic, payload) { console.log([topic, payload].join(': ')); consout += [topic, payload].join(': ')+'<br>' document.body.innerHTML = consout // disconnect //client.end(); }); // publish messages client.publish('topic0', 'hello world of MQTT! #1'); client.publish('topic0', 'hello world of MQTT! #2'); client.publish('topic0', 'hello world of MQTT! #3'); client.publish('topic0', 'hello world of MQTT! #4'); client.publish('topic0', 'hello world of MQTT! #5'); </script> </body> </html>

以下の部分は使用しているbrokerによって変更すること:
(brokerが止まっていることがあるようなので、そのときはbrokerを変えてみる)

//var mqtt_url = 'ws://test.mosquitto.org:8081' //var mqtt_url = 'ws://mqtt.eclipse.org/mqtt:443' var mqtt_url = 'wss://try:try@broker.shiftr.io'

デモプログラムを起動後、上の「MQTT_AT_webTestZero_02.html」をプラウザーで起動すると
以下のweb画面が表示される(例):

MQTT over WebSockets Test(wss://try:try@broker.shiftr.io) topic0: hello world of MQTT! #1 topic0: hello world of MQTT! #2 topic0: hello world of MQTT! #3 topic0: hello world of MQTT! #4 topic0: hello world of MQTT! #5 topic0: { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} topic0: { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} topic0: { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} topic0: { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} topic0: { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} topic0: { "press" : 1013.12, "altm" : 42.0, "tempC" : 28.7} ...

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 upload_protocol = sam-ba monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # MQTT lib 617

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:esp32dev] platform = espressif32 #board = esp32dev board = m5stick-c framework = arduino monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = # use M5Atom lib 3113 # use "FastLED" 126 # MQTT lib 617

ESP32の場合:

; 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 framework = arduino monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = # MQTT lib 617

ESP8266の場合:

; 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:huzzah] platform = espressif8266 #board = huzzah board = esp_wroom_02 framework = arduino monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = # MQTT lib 617

wio-terminalのファームウェアを切り替えたときの注意

古いファームウェアのライブラリを動かした後は、古いライブラリがキャッシュで残っていると ビルド・エラーになるので以下を実行すること:

cd project_directory rm -r .pio/libdeps/seeed_wio_terminal/* rm -r .pio/build/seeed_wio_terminal/*

参考情報

https://docs.shiftr.io/interfaces/mqtt/

The following ports are available on the broker.shiftr.io host: MQTT MQTTS MQTTWS MQTTWSS 1883 8883 80 443

MQTT test server @mosquitto.org

https://test.mosquitto.org/ The server listens on the following ports: 1883 : MQTT, unencrypted 8883 : MQTT, encrypted 8884 : MQTT, encrypted, client certificate required 8080 : MQTT over WebSockets, unencrypted 8081 : MQTT over WebSockets, encrypted websocketで使用するurlは以下になる: 'ws://test.mosquitto.org:8081'

MQTT test server @eclipse.org

http://mqtt.eclipse.org/ This is a public test MQTT broker service. It currently listens on the following ports: 1883 : MQTT over unencrypted TCP 8883 : MQTT over encrypted TCP 80 : MQTT over unencrypted WebSockets (note: URL must be /mqtt ) 443 : MQTT over encrypted WebSockets (note: URL must be /mqtt ) websocketで使用するurlは以下になる: 'ws://mqtt.eclipse.org/mqtt:443'

10 Free Public & Private MQTT Brokers(For Testing & Production)

PlatformIO Core (CLI)

ESP-WROOM-02ボードでMQTTとMPL3115A2(気圧・高度・気温センサ)を動かす(Arduino版)
本記事のスケッチは、この記事のスケッチとほとんど同じであるので参考にできる。

以上

続きを読む "Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)"

| | コメント (0)

2020年12月23日 (水)

nixieクロックにNTPクライアントの機能を追加する(v2,rpcファーム対応)

2020/12/23
初版

pio nixie NTP Client FWrpc

pio nixie NTP Client FWrpc

概要

nixieクロックにNTPクライアントの機能を追加する(v2,rpcファーム対応)
nixieクロックにNTPクライアントの機能を追加する」で古いファームウェア(Atインターフェース)で 動作している前提で、それを新しいファームウェア(rpcインターフェース)のものに切り替える方法について述べる。

新しいファームウェアへの対応方法

1.古いファームウェアのスケッチのプロジェクト・ディレクトリをコピーする 例: cp -r wiot-nixie-NTP wiot-nixie-NTP2 2.コピーしたプロジェクトのキャッシュ(.pio/libdep/<board名>,.pio/build/<boad名>)をクリアする 例: cd wiot-nixie-NTP2 rm -r .pio/libdeps/seeed_wio_terminal/* rm -r .pio/build/seeed_wio_terminal/* 3.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: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+ lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip # 以下、必要なライブラリを登録する https://github.com/Seeed-Studio/Seeed_Arduino_LCD/archive/master.zip # arduino-libraries/NTPClient@^3.1.0

上のようにネットワークに必要なライブラリの登録の後に必要なライブラリを登録する。

4.スケッチのヘッダー<AtWiFi.h>を<rpcWiFi.h>に変更(編集)する

例:src/Wio_nixie_tube_clock_NTP.ino

//#include <AtWiFi.h> #include <rpcWiFi.h> (基本的に他は変更する必要はない)

5.ビルド&実行 pio run -t upload

参考情報

wio-terminalのファームウェア・アップデートについて(v2)(linux版)

Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)

PlatformIO Core (CLI)

以上

続きを読む "nixieクロックにNTPクライアントの機能を追加する(v2,rpcファーム対応)"

| | コメント (0)

2020年12月21日 (月)

wio-terminalのファームウェア・アップデートについて(v2)(linux版)

2020/12/21
初版

wio-terminal firmware update(v2) (linux)

wio-terminal firmware update(v2) (linux)

概要

wio-terminalのファームウェア・アップデートについて(v2)(linux版)
RTL8720ファームウェアの最新版(v2.0.4)でWiFi/BLEの両方に対応したので そのファームウェアのアップデートの方法について述べる。

注意:
今回のアップデートでヘッダーファイルが変更になっているのでプログラムを作成するときは注意のこと。
基本的には、ヘッダー<AtWifi.h>をヘッダー<rpcWiFi.h>を置き換えるだけで互換性が保てるらしい。

手順

以下を実行する:

mkdir wio-terminal cd wio-terminal mkdir firmware cd firmware # 必要なファイルをダウンロード&解凍する: wget http://files.seeedstudio.com/wiki/Wio-Terminal/res/rtl8720_update_v2.uf2 wget https://github.com/Seeed-Studio/seeed-ambd-firmware/releases/download/v2.0.4/20201216-seeed-ambd-firmware-rpc-v2.0.4-JP.zip unzip 20201216-seeed-ambd-firmware-rpc-v2.0.4-JP.zip wget https://github.com/LynnL4/ambd_flash_tool/archive/master.zip unzip master.zip # wio-terminalをUSB接続する # wio-terminalの電源スイッチを素早く2度押す(bootloader-modeにする) # Arduinoのディレクトリが出現する(以下のUSERは自分の環境に合わせる) cp rtl8720_update_v2.uf2 /media/USER/Arduino/ # ここで、wio-terminalのスケッチが書き込まれる cd ~/wio-terminal/firmware/ambd_flash_tool-master/ python3 ambd_flash_tool.py erase python3 ambd_flash_tool.py flash -d ~/wio-terminal/firmware/

以上の手順でファームウェア・アップデートが完了する。

実行例

$ cd ~/wio-terminal/firmware/ $ cp rtl8720_update_v2.uf2 /media/USER/Arduino/ $ cd ~/wio-terminal/firmware/ambd_flash_tool-master $ python3 ambd_flash_tool.py erase Erasing... All images are sent successfully! Image tool closed! Success! # 意外と時間がかかるので、辛抱強く待つ。 $ python3 ambd_flash_tool.py flash -d ~/wio-terminal/firmware/ copy img to workspace... Flashing... All images are sent successfully! Image tool closed! Success! # ここでファームウェアの書き込みが終了する

動作確認

platformioで以下の設定でビルド実行する:

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:seeed_wio_terminal] platform = atmelsam board = seeed_wio_terminal framework = arduino build_flags = -DWIO_TERMINAL lib_deps = https://github.com/Seeed-Studio/Seeed_Arduino_FreeRTOS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_mbedtls/archive/dev.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcUnified/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcBLE/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_rpcWiFi/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_FS/archive/master.zip https://github.com/Seeed-Studio/Seeed_Arduino_SFUD/archive/master.zip lib_ldf_mode = deep+

src/main.ino

/* This Sketch is a combination of WiFi Scan and BLE Scan example provided by SeeedStudio */ #include <rpcWiFi.h> #include <rpcBLEDevice.h> #include <BLEScan.h> #include <BLEAdvertisedDevice.h> int scanTime = 5; //In seconds BLEScan* pBLEScan; class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { void onResult(BLEAdvertisedDevice advertisedDevice) { Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); } }; void setup() { Serial.begin(115200); // Set WiFi to station mode and disconnect from an AP if it was previously connected WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); BLEDevice::init(""); pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster pBLEScan->setInterval(100); pBLEScan->setWindow(99); // less or equal setInterval value Serial.println("Setup done"); } void loop() { Serial.println("scan start"); // WiFi.scanNetworks will return the number of networks found int n = WiFi.scanNetworks(); Serial.println("scan done"); if (n == 0) { Serial.println("no networks found"); } else { Serial.print(n); Serial.println(" networks found"); for (int i = 0; i < n; ++i) { // Print SSID and RSSI for each network found Serial.print(i + 1); Serial.print(": "); Serial.print(WiFi.SSID(i)); Serial.print(" ("); Serial.print(WiFi.RSSI(i)); Serial.print(")"); Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*"); delay(10); } } Serial.println(""); BLEScanResults foundDevices = pBLEScan->start(scanTime, false); Serial.print("Devices found: "); Serial.println(foundDevices.getCount()); Serial.println("Scan done!"); pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory delay(2000); // Wait a bit before scanning again delay(5000); }

出力例:

picocom --imap lfcrlf -b115200 /dev/ttyACM0 scan start scan done 9 networks found 1: 2xxxxxxxxxxxxxxxxxx (-63)* 2: ryyyyyyyyyyyyyy (-83)* 3: rzzzzzzzzzzzzzz (-83)* 4: 5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (-87)* 5: 2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (-87)* 6: 0xxxxxxxxx (-88)* 7: Hxxxxxx (-91)* 8: axxxxxx (-93)* 9: 9xxxxxxxxxxx (-94)* Advertised Device: Name: , Address: c7:50:1b:ef:f3:78 Advertised Device: Name: , Address: 52:5c:26:a4:76:7a Advertised Device: Name: , Address: c8:72:2d:5d:21:34, serviceUUID: <NULL> Advertised Device: Name: , Address: fa:65:0f:f8:d9:53 Advertised Device: Name: , Address: e9:99:fc:aa:18:64 Advertised Device: Name: , Address: a5:75:b2:a9:31:1c Devices found: 6 Scan done!

以上のような出力が出れば動作確認としてOKとなる。

ファームウェア・バージョン確認スケッチ

rpcVersion.ino

#include "seeed_rpcUnified.h" #include "rtl_wifi/wifi_unified.h" void setup() { Serial.begin(115200); } void loop() { Serial.println("hey"); Serial.println(rpc_system_version()); }

これを実行するとファームウェアのバージョンが出力される。

参考情報

https://www.hackster.io/Salmanfarisvp/the-new-wio-terminal-erpc-firmware-bfd8bd
The New Wio Terminal eRPC Firmware

https://lab.seeed.co.jp/entry/2020/11/12/120000
2020-11-12 Wio Terminalの新しいRTL8720ファームウェアをリリースしました

https://forum.seeedstudio.com/t/using-other-mbedtls-cryptographic-function-together-with-rpcwifi-library/255232
Using other mbedtls cryptographic function together with rpcWiFi library

https://wiki.seeedstudio.com/Wio-Terminal-Wi-Fi/
Wi-Fi Connectivity
https://wiki.seeedstudio.com/Wio-Terminal-Advanced-Wi-Fi/
Advanced Wi-Fi Usage

以上

続きを読む "wio-terminalのファームウェア・アップデートについて(v2)(linux版)"

| | コメント (0)

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)

より以前の記事一覧