編集履歴一覧に戻る
myaonのアイコン画像

myaon が 2022年01月07日20時55分52秒 に編集

初版

タイトルの変更

+

M5StickCとBlynkで作るお手軽リモートカー

タグの変更

+

M5StickC

+

Blynk

メイン画像の変更

メイン画像が設定されました

記事種類の変更

+

製作品

本文の変更

+

**概要** M5stickCとBlynkで作るM5リモートカー - 遠隔地から操縦できます - 前面にスマホを置いてビデオ通話できます **動画** @[youtube](https://youtu.be/66gbO4gptyA) | 構成部品 | |:---:| | M5StickC | | Groveケーブル | | タイヤ×2 | | モーター×2 | | キャスター×2 | | ユニバーサルプレート | | 電池ボックス | | 単3電池×2 | | ジャンパー線 | | M3ねじナット | | 両面テープ | ```arduino:M5RemoteMotor /************************************************************* Download latest Blynk library here: https://github.com/blynkkk/blynk-library/releases/latest Blynk is a platform with iOS and Android apps to control Arduino, Raspberry Pi and the likes over the Internet. You can easily build graphic interfaces for all your projects by simply dragging and dropping widgets. Downloads, docs, tutorials: http://www.blynk.cc Sketch generator: http://examples.blynk.cc Blynk community: http://community.blynk.cc Follow us: http://www.fb.com/blynkapp http://twitter.com/blynk_app Blynk library is licensed under MIT license This example code is in public domain. ************************************************************* This example runs directly on ESP32 chip. Note: This requires ESP32 support package: https://github.com/espressif/arduino-esp32 Please be sure to select the right ESP32 module in the Tools -> Board menu! Change WiFi ssid, pass, and Blynk auth token to run :) Feel free to apply it to any other example. It's simple! *************************************************************/ /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial /* Fill-in your Template ID (only if using Blynk.Cloud) */ #define BLYNK_TEMPLATE_ID "YourTemplateID" #include <WiFi.h> #include <WiFiClient.h> #include <BlynkSimpleEsp32.h> #include <M5StickC.h> //追加部分 // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "YourAuthToken"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "YourNetworkName"; char pass[] = "YourPassword"; void setup() { M5.begin(); //追加部分 M5.Lcd.println("Blynk"); //追加部分 M5.Lcd.print("M5RemoteMotor"); //追加部分 pinMode(GPIO_NUM_26, OUTPUT); //追加部分 pinMode(GPIO_NUM_0 , OUTPUT); //追加部分 pinMode(GPIO_NUM_32, OUTPUT); //追加部分 pinMode(GPIO_NUM_33, OUTPUT); //追加部分 digitalWrite(GPIO_NUM_26, HIGH); //追加部分 digitalWrite(GPIO_NUM_0 , HIGH); //追加部分 digitalWrite(GPIO_NUM_32, HIGH); //追加部分 digitalWrite(GPIO_NUM_33, HIGH); //追加部分 // Debug console Serial.begin(9600); Blynk.begin(auth, ssid, pass); } void loop() { Blynk.run(); } //追加部分 BLYNK_WRITE(V0) { int16_t LED = param[0].asInt(); if(LED == 0){ l_brake(); } if(LED == 1){ l_front(); } } BLYNK_WRITE(V1) { int16_t LED = param[0].asInt(); if(LED == 0){ r_brake(); } if(LED == 1){ r_front(); } } BLYNK_WRITE(V2) { int16_t LED = param[0].asInt(); if(LED == 0){ l_brake(); } if(LED == 1){ l_back(); } } BLYNK_WRITE(V3) { int16_t LED = param[0].asInt(); if(LED == 0){ r_brake(); } if(LED == 1){ r_back(); } } void l_front(){ digitalWrite(GPIO_NUM_26, HIGH); digitalWrite(GPIO_NUM_0 , LOW); } void r_front(){ digitalWrite(GPIO_NUM_32, HIGH); digitalWrite(GPIO_NUM_33, LOW); } void l_back(){ digitalWrite(GPIO_NUM_26, LOW); digitalWrite(GPIO_NUM_0 , HIGH); } void r_back(){ digitalWrite(GPIO_NUM_32, LOW); digitalWrite(GPIO_NUM_33, HIGH); } void l_brake(){ digitalWrite(GPIO_NUM_26, HIGH); digitalWrite(GPIO_NUM_0 , HIGH); } void r_brake(){ digitalWrite(GPIO_NUM_32, HIGH); digitalWrite(GPIO_NUM_33, HIGH); } ``` **参考文献** - [M5StickCのIOについて調べてみた](https://lang-ship.com/blog/work/m5stickc-io/) GPIO36はdigitalWrite() が使えないみたい - [How to change Virtual Pin Index in Blynk IoT App](https://community.blynk.cc/t/how-to-change-virtual-pin-index-in-blynk-iot-app/56097/9) 新しい方のBlynkのスマホアプリではバーチャルPin番号を変えられず、そこだけはWeb上のダッシュボードから追加する必要がある **参考画像** ![キャプションを入力できます](https://camo.elchika.com/62df44f435ef0c5c4fe9eade5e451fce25871421/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f64656631306632662d356164392d343539322d613131332d6332353130373234613762322f36353335346236332d396336352d343432612d396533642d626431316137383461306431/)