SETUP
*Thanks to Kobayashi sensei of IMAAS for the initial introduction to M5Stack.*
The M5Stack Go kit is available on Amazon.com:
https://www.amazon.com/gp/product/B07F8QR7NB/
1 stop for all the tools, plugins, and drivers:
https://shop.m5stack.com/pages/download
Downloaded CP2104 Driver and M5Burner.
Run M5Burner and update the firmware of M5Stack Go to v1.7.6-en
(The latest version available at the moment)
Install CP2104 Driver.
Follow this tutorial to set up Arduino IDE. I am using Arduino 1.8.13, it works with this setup.
Useful links from the video:
Virtual com port drivers https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
**This link opens up a blank page in my Chrome but works in Firefox.
Arduino IDE arduino.cc/en/Main/Software
Boards manager link https://dl.espressif.com/dl/package_esp32_index.json
M5stack library https://github.com/m5stack/M5Stack
**Now M5stack Library appears directly in the Arduino library manager on searching M5Stack
TEST 1 – HID KEYBOARD
The USB HID (Human Interface Device) specification allows us to build plug-and-play alternative controllers for a variety of devices without the need to install additional drivers. In this test, M5Stack Go is disguised as a normal HID Keyboard. Instead of serial communication, M5Stack GO will process the sensor data locally and send a correspondent keystroke defined by the designer. Keystrokes are like digital switches, so HID Keyboard can’t send over analog data.
Install library ESP32-BLE-Keyboard manually from GitHub:
https://github.com/T-vK/ESP32-BLE-Keyboard
Based on this tutorial and combine it with the DUAL_BUTTON example.
https://programresource.net/en/2020/04/09/3251.html
Tested and worked with STYLY in Unity, on the Web, in AR (Mobile), in Oculus Quest (standalone), and on PCVR (Oculus Link or Air Link).
PCVR and WEB TEST SCENE
Connect the controller to your computer, go to the following page and add it to your list. PCVR users find the scene in My List in STYLY app. Web users can just open it in the browser.
https://gallery.styly.cc/scene/871fdff9-475c-4224-af41-9e8afba32922
Quest (Portable)
Connect the controller to your headset, go to the link above and add it to your list. You can find it in My List in your STYLY app.
AR TEST SCENE
Connect the controller to your mobile phone and scan the QR code with the STYLY app.
Advanced Topic: Would it be possible to read bleKeyboard.print() all at once as a string. If so, I can send over analog data as a string without having to scale it down to letters.
Arduino Project: M5HIDKEYBOARD
Test Scene Unitypackage *require Playmaker and STYLY installed
TEST 2 – HID GAMEPAD I
The biggest difference with HID Gamepad is the ability to send over joystick information. A joystick is made of 2 axes (usually 10K potentiometers), so with left and right joysticks and the two shoulder buttons, HID Gamepad is capable of communicating 6 analog data over in the format of axes by default. It’s worth mentioning that HID mouse is also capable of communicating over 1 analog value over its scroll wheel.
Download and install library ESP32-BLE-GAMEPAD from GitHub:
https://github.com/lemmingDev/ESP32-BLE-Gamepad
Combine IndividualAxes and PotAsAxis example in ESP32-BLE-Gamepad and JOYSTICK example in M5Stack/Units.
After some initial testing, the old input system in Unity editor can’t recognize the ESP32 BLE Gamepad. When connected through Bluetooth, it doesn’t show up as a gamepad as the TEST 3 did. The new input system recognizes it but the action needed to access the inputs is a custom one which is not included in Playmaker’s standard actions.
Digitom (New) Input System actions:
https://hutonggames.com/playmakerforum/index.php?topic=21797.msg95729#msg95729
Install link:
https://gitlab.com/toomasio/playmakerinputsystemactions.git
Tutorial worth watching:
https://www.youtube.com/watch?v=tfI6KEf5CHA
TEST 3 – HID GAMEPAD II
This test is based on a custom library put together by Shigeru Kobayashi. This library allows the ESP32 gamepad to be discovered by both old and new input systems in Unity 3D as the default Axes X and Y and buttons 0 to button 4.
TEST 4 – SPEECH TO TEXT
https://github.com/MhageGH/esp32_CloudSpeech
- Set up a (free) billing account on Google and enable the service: https://cloud.google.com/speech-to-text/
- Recommend to go through the tutorial and it will create the service with a click of a button.
https://cloud.google.com/speech-to-text/docs/quickstart-protocol - Under the Credentials, create an API KEY
- Set network parameter and your account information in network_param.h.
- Say to the microphone and see the serial monitor.
Test this in the command prompt (Windows 10):curl -s -X POST -H "Content-Type: application/json" -d @request.json "https://speech.googleapis.com/v1/speech:recognize?key= API_KEY"
- Make sure the request.json file is in the same directory in which the curl command is executed.
In order to get this sketch to run on M5Stack, I have to set up OPENSSL on my Windows 10. Here is a recent tutorial:
https://tecadmin.net/install-openssl-on-windows/
One confusing thing in this tutorial is the directory name. I downloaded the Winx64 version as instructed, so my directory should be C:\OpenSSL-Win64 not C:\OpenSSL-Win32 as shown in the tutorial. The environmental variables should be like this:
set OPENSSL_CONF=C:\OpenSSL-Win64\bin\openssl.cfg
set Path=......Other Values here......;C:\OpenSSL-Win64\bin
- Don’t forget to restart the computer afterward.
- After generating the certificate with OpenSSL in the command prompt, copy and replace the value of root_ca. Make sure to keep the same exact format.
- One last thing that caused an error callback for me was the name of a property in the HttpBody1 was wrong. It should be “sampleRateHertz\” not “sampleRate\”. While I was there, I also changed “languageCode\”:\”ja-JP\” to “languageCode\”:\”en-US\”.
I was able to get it to work after all these changes. I said “Hello Hello” and this came back in the Serial Monitor, pretty satisfying!
{ "results": [ { "alternatives": [ { "transcript": "hello hello", "confidence": 0.95336735 } ] } ] }
I realized the client.read() returns more than just the JSON data, there is a huge header too. After some research online, didn’t find anything useful on how to get rid of the header, so I went for the old-school way -> remove(); After cleaning up extra strings both before and after the data, it works beautifully with the ArduinoJSON library.
Helps to calculate the size of the data and also shows how to access specific data in the JSON tree. I was having problems understanding the examples in the library but this tool did it for me :
https://arduinojson.org/v6/assistant/
To get this code to work, I made a total of 48 requests to the Google Cloud Platform and used 2.75 minutes. I think as an indie experimentalist, 60 minutes/month for free is a really good deal.