« M5CameraでCameraWebServerを動かす | トップページ | WebRadio「M5Stack-Core2-MediaPlayer」を動かす。 »

2022年1月 1日 (土)

「M5Stack用回転角ユニット」を動かす

2022/1/1
初版

UNIT_ANGLE

UNIT_ANGLE

概要

UNIT_ANGLE「M5Stack用回転角ユニット」を動かす。
ソースは共通化しており、ターゲットのM5Atom,M5StickCPlus,M5Core2をplatformio.iniの内容で切り替えてビルドする。
直接関係ない話だが、M5Atom用に提供されているUNIT_ANGLEのサンプル・スケッチは、なぜかArduino-IDEではエラーになりコンパイルできなかった。
(なにかしらの環境の問題のようだ)

ソース

src/main.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 读取角度计的角度,并转换为数字量显示 */ #ifdef M5ATOM #include <M5Atom.h> #endif #ifdef M5STICK_CP #include <M5StickCPlus.h> #endif #ifdef M5C2 #include <M5Core2.h> #endif #ifdef M5ATOM int sensorPin = 32; // set the input pin for the potentiometer. 设置角度计的输入引脚 #endif #ifdef M5STICK_CP int sensorPin = 33; #endif #ifdef M5C2 int sensorPin = 33; #endif 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(); pinMode(sensorPin, INPUT); dacWrite(25, 0); #ifdef M5STICK_CP M5.Lcd.setRotation(3); M5.Lcd.setCursor(0, 10, 2); M5.Lcd.print("The value of ANGLE: "); #endif #ifdef M5C2 M5.Lcd.setTextSize(2); //Set the font size to 2. 设置字体大小为2 M5.Lcd.print("the value of ANGLE: "); #endif } void loop() { // read the value from the sensor: cur_sensorValue = analogRead(sensorPin); #ifdef M5ATOM 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); #endif #ifdef M5STICK_CP M5.Lcd.setCursor(80, 50, 6); if(abs(cur_sensorValue - last_sensorValue) > 10){//debaunce M5.Lcd.fillRect(100, 50, 100, 40, BLACK); M5.Lcd.print(cur_sensorValue); last_sensorValue = cur_sensorValue; } delay(50); #endif #ifdef M5C2 M5.Lcd.setCursor(0, 25); if(abs(cur_sensorValue - last_sensorValue) > 10){//debaunce M5.Lcd.fillRect(0, 25, 100, 25, BLACK); M5.Lcd.print(cur_sensorValue); last_sensorValue = cur_sensorValue; } delay(50); #endif }

platformio.ini

M5Atom用

[env:M5ATOM] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5ATOM upload_poert = /dev/ttyUSB0 monitor_speed = 115200 lib_deps = m5stack/M5Atom @ ^0.0.7 fastled/FastLED @ ^3.4.0 adafruit/Adafruit NeoPixel @ ^1.10.3 lib_ldf_mode = deep+

M5StickCPlus用

[env:M5StickCPlus] platform = espressif32 board = m5stick-c framework = arduino build_flags = -DM5STICK_CP monitor_speed = 115200 lib_ldf_mode = deep+ lib_deps = m5stack/M5StickCPlus @ ^0.0.5 tinyu-zhao/FFT @ ^0.0.1 m5stack/UNIT_ENV @ ^0.0.2 adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4 adafruit/Adafruit NeoPixel @ ^1.10.3

M5Core2用

[env:m5core2] platform = espressif32 board = m5stack-core2 framework = arduino upload_speed = 2000000 monitor_speed = 115200 board_build.partitions = default_16MB.csv build_flags = -DM5C2 -DCORE_DEBUG_LEVEL=4 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue lib_deps = https://github.com/m5stack/M5Core2.git https://github.com/FastLED/FastLED ;https://github.com/m5stack/M5Core2/blob/master/examples/core2_for_aws/ArduinoECCX08.zip lovyan03/LovyanGFX adafruit/Adafruit BMP280 Library @ ^2.5.0 adafruit/Adafruit Unified Sensor @ ^1.1.4 m5stack/UNIT_ENV @ ^0.0.2 adafruit/Adafruit NeoPixel @ ^1.10.3 lib_ldf_mode = deep+

動作

実態はポテンショメーターなのでアナログで読み込んだ値がLCDに表示される。
(M5Atomではシリアルに出力される)

M5Atomの出力例(シリアル出力):

$ bt -L 1 No port specified, using ttyUSB0 (last registered). Use -l to list ports. Trying port ttyUSB0... Connected to ttyUSB0 at 115200 bps. Escape character is 'Ctrl-]'. Use escape followed by '?' for help. the value of ANGLE: 2739 the value of ANGLE: 2704 the value of ANGLE: 2717 <省略> the value of ANGLE: 706 the value of ANGLE: 1059 the value of ANGLE: 2411 the value of ANGLE: 4095 the value of ANGLE: 4049 the value of ANGLE: 4095 ...

参考情報

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

M5Atom関連:
M5Atomの細かい仕様
Grove端子(HY2.0-4P、PH2.0-4P)について調べてみた

M5StickC/Plus関連:
M5StickCのIOについて調べてみた
Arduino(M5StickC)でefont Unicodeフォント表示 完結編

M5Core2関連:
M5Stack Core2を使ってみました。

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対応)

M5Stackファミリ関連:
M5Core2 Arduino Install
M5Paper Arduino Install
M5CoreInk Arduino Install
M5Stamp-PICO Arduino Install
M5Stamp-C3 Arduino Install
Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
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編)

以上

|

« M5CameraでCameraWebServerを動かす | トップページ | WebRadio「M5Stack-Core2-MediaPlayer」を動かす。 »

PlatformIO」カテゴリの記事

M5Atom」カテゴリの記事

M5Core2」カテゴリの記事

M5StickCPlus」カテゴリの記事

コメント

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