From 2a9f3085924b0098c7db6308a434501d9975934e Mon Sep 17 00:00:00 2001 From: edumeneses Date: Fri, 8 Oct 2021 13:07:50 -0400 Subject: [PATCH] FW200422 --- Docs/Firmware_update_instructions.md | 202 ++++++ Docs/OSC.md | 65 ++ ...00320.pd => 2Stick_Sopranino2GW_200330.pd} | 671 ++++++++++-------- firmware/README.md | 21 +- .../Capsense.ino | 12 +- .../IMU.ino | 18 +- .../OSC.ino | 138 ++-- .../WiFi.ino | 20 +- .../data.ino | 91 ++- .../data/config.json | 16 +- .../esp32_arduino_FW200422.ino} | 70 +- .../fs_json.ino | 46 +- .../esp32_arduino_FW200422/instrument.ino | 268 +++++++ .../libmapper.ino | 69 +- .../platforms/ESP32.h | 0 .../platforms/ESP8266.h | 0 16 files changed, 1263 insertions(+), 444 deletions(-) create mode 100644 Docs/Firmware_update_instructions.md create mode 100644 Docs/OSC.md rename Test_config/PD/{2Stick_Sopranino2GW_200320.pd => 2Stick_Sopranino2GW_200330.pd} (73%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/Capsense.ino (90%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/IMU.ino (53%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/OSC.ino (65%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/WiFi.ino (93%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/data.ino (65%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/data/config.json (85%) rename firmware/{esp32_arduino_FW200320/esp32_arduino_FW200320.ino => esp32_arduino_FW200422/esp32_arduino_FW200422.ino} (84%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/fs_json.ino (88%) create mode 100644 firmware/esp32_arduino_FW200422/instrument.ino rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/libmapper.ino (63%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/platforms/ESP32.h (100%) rename firmware/{esp32_arduino_FW200320 => esp32_arduino_FW200422}/platforms/ESP8266.h (100%) diff --git a/Docs/Firmware_update_instructions.md b/Docs/Firmware_update_instructions.md new file mode 100644 index 0000000..6a8bcd5 --- /dev/null +++ b/Docs/Firmware_update_instructions.md @@ -0,0 +1,202 @@ +# T-Stick 2GW (Firmware version: 200422) + +- [First time firmware upload instructions](#first-time-firmware-upload-instructions) + * [Option 1: using .bin files and esptool.py](#option-1-using-bin-files-and-esptoolpy) + * [Option 2: Using Arduino IDE](#option-2-using-arduino-ide) +- [Update firmware instructions](#update-firmware-instructions) +- [Other Documentation](#other-documentation) +- [Firmware information](#firmware-information) + +## First time firmware upload instructions: + +### Option 1: using .bin files and esptool.py - NOT AVAILABLE AT THE MOMENT + +
+ +This method is easier/faster. It uses [esptool.py](https://github.com/espressif/esptool). + +##### Download the [bin files](./bin): + +- Download the .bin files located at the bin [folder](./bin) + +##### Download [esptool.py](https://github.com/espressif/esptool): + +- Download the _esptool.py_ from https://github.com/espressif/esptool. Use the `Download ZIP` option from Github +- Unzip the _esptool-master.zip_ file + +##### Download [mkspiffs tool](https://github.com/igrr/mkspiffs): + +- Download the mkspiffs tool. Download the latest version for the ESP32 according to your OS at the [release page](https://github.com/igrr/mkspiffs/releases) +- Extract the file +- Copy the [data](./esp32_arduino_19X_19111/data) folder to the _mkspiffs_ folder +- Edit the `/data/config.json` file for the information to match yout T-Stick (serial number, firmware version, color, etc.) + +##### Create the .spiffs.bin file (T-Stick configuration file) + +- Open a _Terminal_ window (macOS/Linux) or the _Command Prompt_ (Windows) +- Navigate to the _mkspiffs_ folder +- Execute `./mkspiffs -c data -d 5 -b 4096 -p 256 -s 1507328 esp32_arduino_19X_19111.spiffs.bin` (macOS/Linux) or `mkspiffs.exe -c data -d 0 -b 4096 -p 256 -s 1507328 esp32_arduino_19X_19111.spiffs.bin` (Windows) + +##### Connect the T-Stick to the computer and check the USB port: + +- [Check the T-Stick (ESP32) port in your computer](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/establish-serial-connection.html): + - For MacOS/Linux: + - Open a _Terminal_ window + - Execute the command `ls /dev/cu.*`. The command will return a list of ports in your computer. + - Plug the T-Stick (USB) and run the command `ls /dev/cu.*` one more time. You can now compare the lists and anotate the T-Stick USB port. Should be something similar to `/dev/cu.wchusbserial1410`, probably with a different number + - Linux users should also give the currently logged user read and write access the serial port over USB. Check [here](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/establish-serial-connection.html) for more information + - For Windows: + - Check the list of identified COM ports in the [Windows Device Manager](https://support.microsoft.com/en-ca/help/4026149/windows-open-device-manager) + - Plug the T-Stick (USB) and check the list of identified COM ports in the [Windows Device Manager](https://support.microsoft.com/en-ca/help/4026149/windows-open-device-manager) again. The T-Stick port should appear on the list. Anotate the T-Stick USB port, it should be something similar to `COM3` or `COM16` + + +##### Flash the firmware (.bin files): + +- Use _Finder_, _Terminal_, or _File Explorer_ to copy the contents of the [bin](./bin/) folder (you should copy 4 .bin files) to the _esptool-master_ folder +- Use _Finder_, _Terminal_, or _File Explorer_ to copy the `esp32_arduino_19X_19111.spiffs.bin` file from the _mkspiffs_ folder to the _esptool-master_ folder +- Navigate to the _esptool-master_ folder in _Terminal_ or _Command Prompt_ +- Run the command (__don't forget to replace the --port (/dev/cu.wchusbserial1410) option for your T-Stick port__): `esptool.py --chip esp32 --port /dev/cu.wchusbserial1410 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 boot_app0.bin 0x1000 bootloader_dio_80m.bin 0x10000 esp32_arduino_19X_19111.ino.bin 0x8000 esp32_arduino_19X_19111.ino.partitions.bin 2686976 esp32_arduino_19X_19111.spiffs.bin`. Wait for the process to be complete. Do not unplug or turn off your T-Stick during the process. + +To test if the data is being send correctly: + +- Connect the T-Stick to a network (instructions [here](./Docs/T-Stick_2GW_Connecting_Guide(v1.1).md)); +- Open the Pure Data (PD) or Max/MSP patch to receive T-Stick messages (they can be found [here](./Configuration)); +- Start receive OSC messages according to the chosen patch. + +
+ +### Option 2: Using Arduino IDE + +_READ ALL DEPENDENCIES AND OBSERVATIONS BEFORE UPLOAD !_ + +##### Install Arduino IDE: + +To download and install Arduino IDE, follow the instructions at https://www.arduino.cc/en/main/software. + +##### Install Arduino ESP32 filesystem uploader: + +You need to upload a file (data/config.json) into ESP32 filesystem. +Follow the instructions at https://github.com/me-no-dev/arduino-esp32fs-plugin. + +##### Install all depencencies: + +1. ESP32 Arduino core 1.0.4 or newer. Instructons at https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md. Install using [boards manager](https://www.arduino.cc/en/guide/cores) +2. For some systems it may be required to also install the ESP8266 Arduino core. Instructons at https://github.com/esp8266/Arduino. Install using [boards manager](https://www.arduino.cc/en/guide/cores) +3. [Wifi32Manager](https://github.com/edumeneses/WiFi32Manager). Instructons at https://github.com/edumeneses/WiFi32Manager#installing. Install using [manual installation](https://www.arduino.cc/en/guide/libraries#toc5) +4. [Adafruit_LSM9DS1](https://github.com/adafruit/Adafruit_LSM9DS1). Install using [library manager](https://www.arduino.cc/en/guide/libraries#toc3) +5. [ArduinoJSON](https://github.com/bblanchon/ArduinoJson) v6.12 or up. Install using [library manager](https://www.arduino.cc/en/guide/libraries#toc3) +6. [CNMAT OSC library](https://github.com/CNMAT/OSC) v3.5.7 or up. Install using [library manager](https://www.arduino.cc/en/guide/libraries#toc3) +7. [DocSunset MIMU Library](https://github.com/DocSunset/MIMU). Install using [manual installation](https://www.arduino.cc/en/guide/libraries#toc5) +8. [Eigen linear algebra library for Arduino](https://github.com/bolderflight/Eigen). Install using [manual installation](https://www.arduino.cc/en/guide/libraries#toc5) + +Observations: + +1. MINU library complains if you keep any IMU-related files other than MIMU_LSM9DS1.h and MIMU_LSM9DS1.cpp +2. Microcontroller currently in use for T-Stick 2GW: [Wemos LOLIN D32 PRO](https://wiki.wemos.cc/products:d32:d32_pro) + +##### Create your custom config.json file: + +Each T-Stick uses a _config.json_ file to store all configuration paramethers. + +- Make the necessary changes to the [_config.json_](./esp32_arduino_FW200422/data/config.json) file: + - device: replace _color_ with the shrinking material color, and _19X_ with T-stick's serial number + - author: replace _IDMIL_ with the builder's name (or alias) + - nickname: replace _color_ with the shrinking material color + - id: replace _190_ with your T-Stick serial number +- Save the file at the _data_ folder (inside _esp32_arduino_19X_19101_). Make sure _config.json_ is the only file at _data_ folder + +##### Upload (flash) the firmware and config.json into the T-Stick: + +- Open the file `esp32_arduino_FW200422.ino` using Arduino IDE +- Choose the proper _board_: `Tools -> Board: "*******" -> LOLIN D32 PRO` +- Choose Upload Speed: `Tools -> Upload Speed: "******" -> 115200` +- Choose port: + - Keep the T-Stick disconnected to the computer + - Go to: `Tools -> Port` and take note the available ports + - connect the T-Stick to the computer using an USB cable and turn the T-Stick ON + - Go to: `Tools -> Port` and choose the new available port (T-Stick port) +- Upload the firmware: `Sketch -> Upload`. Do not disconnect or turn the T-Stick off during the upload process +- Upload _config.json_: `Tools -> ESP32 Sketch Data Upload`. Do not disconnect or turn the T-Stick off during the upload process + +##### Test T-Stick: + +To test your T-Stick after flashing firmware/config.json, you can use Arduino IDE: + +- Choose T-Stick serial port +- Open the _Serial Monitor_ (`Tools -> Serial Monitor`) + +You should see T-Stick booting process. + +To test if the data is being send correctly: + +- Connect the T-Stick to a network (instructions [here](./Docs/T-Stick_2GW_Connecting_Guide(v1.1).md)) +- Open the Pure Data (PD) or Max/MSP patch to receive T-Stick messages (they can be found [here](./Configuration)) +- Start receive OSC messages according to the chosen patch + +## Update firmware instructions + +Updating the firmware does not erase the T-Stick saved configuration and it is a relatively simple process: + +:warning: **bin files not available for this firmware version**: Please update using [Arduino IDE](#option-2-using-arduino-ide) + +
+ +##### Download the [bin files](./bin): + +- Download the .bin files located at the bin [folder](./bin) + +##### Download [esptool.py](https://github.com/espressif/esptool): + +- Download the _esptool.py_ from https://github.com/espressif/esptool. Use the `Download ZIP` option from Github +- Unzip the _esptool-master.zip_ file + +##### Connect the T-Stick to the computer and check the USB port: + +- [Check the T-Stick (ESP32) port in your computer](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/establish-serial-connection.html): + - For MacOS/Linux: + - Open a _Terminal_ window + - Execute the command `ls /dev/cu.*`. The command will return a list of ports in your computer. + - Plug the T-Stick (USB) and run the command `ls /dev/cu.*` one more time. You can now compare the lists and anotate the T-Stick USB port. Should be something similar to `/dev/cu.wchusbserial1410`, probably with a different number + - Linux users should also give the currently logged user read and write access the serial port over USB. Check [here](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/establish-serial-connection.html) for more information + - For Windows: + - Check the list of identified COM ports in the [Windows Device Manager](https://support.microsoft.com/en-ca/help/4026149/windows-open-device-manager) + - Plug the T-Stick (USB) and check the list of identified COM ports in the [Windows Device Manager](https://support.microsoft.com/en-ca/help/4026149/windows-open-device-manager) again. The T-Stick port should appear on the list. Anotate the T-Stick USB port, it should be something similar to `COM3` or `COM16` + + +##### Flash the firmware (.bin files): + +- Use _Finder_, _Terminal_, or _File Explorer_ to copy the contents of the [bin](./bin/) folder (you should copy 4 .bin files) to the _esptool-master_ folder +- Use _Finder_, _Terminal_, or _File Explorer_ to copy the `esp32_arduino_19X_19111.spiffs.bin` file from the _mkspiffs_ folder to the _esptool-master_ folder +- Navigate to the _esptool-master_ folder in _Terminal_ or _Command Prompt_ +- Run the command (__don't forget to replace the --port (/dev/cu.wchusbserial1410) option for your T-Stick port, and the .bin names for the version you plan to upload__): `esptool.py --chip esp32 --port /dev/cu.wchusbserial1410 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 boot_app0.bin 0x1000 bootloader_dio_80m.bin 0x10000 esp32_arduino_19X_19111.ino.bin 0x8000 esp32_arduino_19X_19111.ino.partitions.bin`. Wait for the process to be complete. Do not unplug or turn off your T-Stick during the process. + +
+ +## Other Documentation: + +[T-Stick connection guide – v1.1 for wireless T-Sticks](./Docs/T-Stick_2GW_Connecting_Guide(v1.1).md) (model 2GW-19X) + +[How to build a T-Stick Sopranino](./Docs/T-Stick_2GW_building_instructions.md) + + +## Firmware information: + +Sopranino T-Stick 2GW - LOLIN D32 PRO - USB -WiFi +Input Devices and Music Interaction Laboratory (IDMIL) +Created: February 2018 by Alex Nieva +April 2020 by Edu Meneses - firmware version 200422 +Notes: Based on test program for reading CY8C201xx using I2C by Joseph Malloch 2011 +Adapted to work with Arduino IDE 1.8.10 and T-Stick Sopranino 2GW + +WiFi32Manager - For use with ESP8266 or ESP32 +Created originally for the T-Stick project: +http://www-new.idmil.org/project/the-t-stick/ +This code uses code (fork) of 3 other projects: +https://github.com/kentaylor/WiFiManager +https://github.com/tzapu/WiFiManager +https://github.com/zhouhan0126/WIFIMANAGER-ESP32 +Edu Meneses - IDMIL - Mar 2019 + +MIMU - Magnetometer + accelerometer + gyroscope orientation library +https://github.com/DocSunset/MIMU +Travis West - IDMIL - Oct 2019 diff --git a/Docs/OSC.md b/Docs/OSC.md new file mode 100644 index 0000000..702477b --- /dev/null +++ b/Docs/OSC.md @@ -0,0 +1,65 @@ +# T-Stick firmware 200422 - OSC sensor data + +#### (Replace XXX for the T-Stick ID number) + +## Raw data + +/TStick_XXX/raw/capsense, i..., 0--255, ... (1 int per 8 capacitive stripes -- 8 bits) + +/TStick_XXX/raw/button/short, i, 0 or 1 + +/TStick_XXX/raw/button/long, i, 0 or 1 + +/TStick_XXX/raw/button/double, i, 0 or 1 + +/TStick_XXX/raw/fsr, i, 0--4095 + +/TStick_XXX/raw/piezo, i, 0--1023 + +/TStick_XXX/raw/accl, iii, +/-32767 (integers) + +/TStick_XXX/raw/gyro, fff, +/-34.90659 (floats) + +/TStick_XXX/raw/magn, iii, +/-32767 (integers) + +/raw (IMU data to be send to callibration app) + +## Normalized data + +/TStick_XXX/norm/fsr, f, 0--1 + +/TStick_XXX/norm/piezo, f, 0--1 + +/TStick_XXX/norm/accl, fff, +/-1, +/-1, +/-1 + +/TStick_XXX/norm/gyro, fff, +/-1, +/-1, +/-1 + +/TStick_XXX/norm/magn, fff, +/-1, +/-1, +/-1 + +## Instrument data + +/TStick_XXX/orientation, ffff, ?, ? ,? ,? + +/TStick_XXX/instrument/ypr, fff, +/-180, +/-90 ,+/-180 (degrees) + +/TStick_XXX/instrument/touch/all, f, 0--1 + +/TStick_XXX/instrument/touch/top, f, 0--1 + +/TStick_XXX/instrument/touch/middle, f, 0--1 + +/TStick_XXX/instrument/touch/bottom, f, 0--1 + +/TStick_XXX/instrument/brush, f, 0--? (~cm/s) + +/TStick_XXX/instrument/multibrush, ffff, 0--? (~cm/s) + +/TStick_XXX/instrument/rub, f, 0--? (~cm/s) + +/TStick_XXX/instrument/multirub, ffff, 0--? (~cm/s) + +/TStick_XXX/instrument/shakexyz, fff, 0--? + +/TStick_XXX/instrument/jabxyz, fff, 0--? + +/TStick_XXX/battery diff --git a/Test_config/PD/2Stick_Sopranino2GW_200320.pd b/Test_config/PD/2Stick_Sopranino2GW_200330.pd similarity index 73% rename from Test_config/PD/2Stick_Sopranino2GW_200320.pd rename to Test_config/PD/2Stick_Sopranino2GW_200330.pd index 0242d19..b36e487 100755 --- a/Test_config/PD/2Stick_Sopranino2GW_200320.pd +++ b/Test_config/PD/2Stick_Sopranino2GW_200330.pd @@ -1,49 +1,49 @@ -#N canvas 197 23 1374 955 10; +#N canvas 240 23 1374 955 10; #X declare -lib Gem; #X obj 357 25 cnv 15 464 210 empty empty T-Stick 20 12 0 20 -228856 -66577 0; -#X obj 97 510 vsl 45 135 -32767 32767 0 0 empty empty AccelX 0 -9 0 -10 -262144 -1 -1 6896 1; -#X obj 147 510 vsl 45 135 -32767 32767 0 0 empty empty AccelY 0 -9 -0 10 -262144 -1 -1 6893 1; -#X obj 197 510 vsl 45 135 -32767 32767 0 0 empty empty AccelZ 0 -9 -0 10 -262144 -1 -1 6716 1; -#X obj 247 510 vsl 45 135 -41 41 0 0 empty empty GyroX 0 -9 0 10 -262144 --1 -1 6697 1; -#X obj 297 510 vsl 45 135 -41 41 0 0 empty empty GyroY 0 -9 0 10 -262144 --1 -1 6702 1; -#X obj 347 510 vsl 45 135 -41 41 0 0 empty empty GyroZ 0 -9 0 10 -262144 --1 -1 6697 1; -#X obj 547 510 vsl 45 135 0 4095 0 0 empty empty Pressure 0 -9 0 10 --262144 -1 -1 9162 1; -#X obj 597 510 vsl 45 135 0 1023 0 0 empty empty Piezo 0 -9 0 10 -262144 +#X obj 97 488 vsl 45 135 -32767 32767 0 0 empty empty AccelX 0 -9 0 +10 -262144 -1 -1 6700 1; +#X obj 147 488 vsl 45 135 -32767 32767 0 0 empty empty AccelY 0 -9 +0 10 -262144 -1 -1 6561 1; +#X obj 197 488 vsl 45 135 -32767 32767 0 0 empty empty AccelZ 0 -9 +0 10 -262144 -1 -1 6948 1; +#X obj 247 488 vsl 45 135 -41 41 0 0 empty empty GyroX 0 -9 0 10 -262144 +-1 -1 6708 1; +#X obj 297 488 vsl 45 135 -41 41 0 0 empty empty GyroY 0 -9 0 10 -262144 +-1 -1 6704 1; +#X obj 347 488 vsl 45 135 -41 41 0 0 empty empty GyroZ 0 -9 0 10 -262144 +-1 -1 6694 1; +#X obj 547 488 vsl 45 135 0 4095 0 0 empty empty Pressure 0 -9 0 10 +-262144 -1 -1 9254 1; +#X obj 597 488 vsl 45 135 0 1023 0 0 empty empty Piezo 0 -9 0 10 -262144 -1 -1 13400 1; -#X obj 397 510 vsl 45 135 -32767 32767 0 0 empty empty MagX 0 -9 0 -10 -262144 -1 -1 6837 1; -#X obj 447 510 vsl 45 135 -32767 32767 0 0 empty empty MagY 0 -9 0 -10 -262144 -1 -1 6613 1; -#X obj 497 510 vsl 45 135 -32767 32767 0 0 empty empty MagZ 0 -9 0 -10 -262144 -1 -1 6678 1; -#X obj 904 561 timer; -#X floatatom 904 585 8 0 0 0 - - -; -#X obj 904 536 t b b; -#X obj 904 511 r rawtimer; +#X obj 397 488 vsl 45 135 -32767 32767 0 0 empty empty MagX 0 -9 0 +10 -262144 -1 -1 6751 1; +#X obj 447 488 vsl 45 135 -32767 32767 0 0 empty empty MagY 0 -9 0 +10 -262144 -1 -1 6797 1; +#X obj 497 488 vsl 45 135 -32767 32767 0 0 empty empty MagZ 0 -9 0 +10 -262144 -1 -1 6871 1; +#X obj 1067 222 timer; +#X floatatom 1067 246 8 0 0 0 - - -; +#X obj 1067 197 t b b; +#X obj 1067 172 r rawtimer; #N canvas 0 22 450 278 (subpatch) 0; #X array rawtime 100 float 1; -#A 0 13.0612 15.9637 17.415 14.5125 15.9637 15.9637 15.9637 15.9637 -14.5125 17.415 15.9637 15.9637 14.5125 14.5125 17.415 14.5125 13.0612 -18.8662 15.9637 15.9637 11.61 17.415 17.415 15.9637 15.9637 15.9637 -15.9637 15.9637 14.5125 17.415 10.1587 20.3175 15.9637 14.5125 15.9637 -15.9637 15.9637 15.9637 14.5125 15.9637 15.9637 15.9637 15.9637 15.9637 -17.415 14.5125 15.9637 14.5125 15.9637 15.9637 14.5125 15.9637 17.415 -15.9637 14.5125 15.9637 15.9637 15.9637 14.5125 17.415 14.5125 15.9637 -15.9637 15.9637 15.9637 14.5125 15.9637 15.9637 15.9637 15.9637 14.5125 -15.9637 17.415 11.61 20.3175 15.9637 14.5125 15.9637 15.9637 15.9637 -14.5125 17.415 15.9637 15.9637 15.9637 14.5125 14.5125 17.415 15.9637 -15.9637 15.9637 14.5125 15.9637 15.9637 15.9637 15.9637 15.9637 15.9637 -15.9637 7.25624; +#A 0 7.25624 11.61 10.1587 13.0612 7.25624 15.9637 5.80499 15.9637 +5.80499 14.5125 7.25624 14.5125 5.80499 15.9637 5.80499 15.9637 7.25624 +14.5125 5.80499 15.9637 5.80499 15.9637 5.80499 15.9637 5.80499 15.9637 +5.80499 15.9637 5.80499 15.9637 2.90249 17.415 5.80499 15.9637 5.80499 +15.9637 5.80499 15.9637 5.80499 15.9637 5.80499 14.5125 7.25624 15.9637 +5.80499 14.5125 5.80499 15.9637 5.80499 15.9637 4.35374 15.9637 5.80499 +15.9637 7.25624 14.5125 5.80499 15.9637 5.80499 15.9637 5.80499 14.5125 +8.70748 14.5125 4.35374 17.415 5.80499 15.9637 5.80499 17.415 5.80499 +14.5125 7.25624 15.9637 5.80499 15.9637 5.80499 14.5125 5.80499 15.9637 +7.25624 14.5125 5.80499 15.9637 5.80499 15.9637 5.80499 15.9637 5.80499 +15.9637 4.35374 18.8662 5.80499 14.5125 5.80499 15.9637 5.80499 15.9637 +5.80499 14.5125; #X coords 0 100 99 0 200 140 1; -#X restore 698 508 graph; +#X restore 861 169 graph; #N canvas 264 335 568 475 timegraph 0; #X obj 111 257 list store; #X obj 117 300 list split 100; @@ -65,23 +65,23 @@ #X connect 4 0 0 0; #X connect 5 0 3 0; #X connect 6 0 2 0; -#X restore 904 609 pd timegraph; -#X obj 904 633 array set rawtime; +#X restore 1067 270 pd timegraph; +#X obj 1067 294 array set rawtime; #X obj 310 18 inlet; -#X floatatom 197 653 7 0 0 0 - - -; -#X floatatom 247 653 7 0 0 0 - - -; -#X floatatom 297 653 7 0 0 0 - - -; -#X floatatom 347 653 7 0 0 0 - - -; -#X floatatom 547 653 7 0 0 0 - - -; -#X floatatom 597 653 7 0 0 0 - - -; -#X floatatom 397 653 7 0 0 0 - - -; -#X floatatom 447 653 7 0 0 0 - - -; -#X floatatom 497 653 7 0 0 0 - - -; -#X floatatom 147 653 7 0 0 0 - - -; -#X floatatom 97 653 7 0 0 0 - - -; -#X obj 257 278 netreceive -u -b; -#X obj 257 299 oscparse; -#N canvas 475 22 1130 740 cook_touch_sopranino 0; +#X floatatom 197 631 7 0 0 0 - - -; +#X floatatom 247 631 7 0 0 0 - - -; +#X floatatom 297 631 7 0 0 0 - - -; +#X floatatom 347 631 7 0 0 0 - - -; +#X floatatom 547 631 7 0 0 0 - - -; +#X floatatom 597 631 7 0 0 0 - - -; +#X floatatom 397 631 7 0 0 0 - - -; +#X floatatom 447 631 7 0 0 0 - - -; +#X floatatom 497 631 7 0 0 0 - - -; +#X floatatom 147 631 7 0 0 0 - - -; +#X floatatom 97 631 7 0 0 0 - - -; +#X obj 257 266 netreceive -u -b; +#X obj 257 287 oscparse; +#N canvas 475 23 1130 740 cook_touch_sopranino 0; #X obj 360 19 inlet; #X obj 18 366 unpack f f; #X obj 106 304 t b b l; @@ -1230,22 +1230,17 @@ #X connect 61 0 60 0; #X connect 61 1 59 1; #X connect 62 1 46 0; -#X restore 45 435 pd cook_touch_sopranino; +#X restore 40 373 pd cook_touch_sopranino; #X text 405 168 port to receive messages; #X msg 257 243 listen \$1; #X floatatom 366 169 6 0 0 0 - - -; #X obj 173 15 loadbang; -#X obj 198 435 unpack f f f; -#X obj 278 435 unpack f f f; -#X obj 359 435 unpack f f f; -#X obj 187 299 s rawtimer; -#X msg 986 344 disconnect; -#X obj 986 367 netsend -u -b; -#X obj 1112 311 pack s f; +#X obj 93 396 unpack f f f; +#X obj 173 396 unpack f f f; +#X obj 254 396 unpack f f f; +#X obj 187 287 s rawtimer; #X symbolatom 366 87 20 0 0 2 T-Stick_IP toip ip; #X floatatom 496 87 5 0 0 2 port toport port; -#X obj 1142 291 i; -#X obj 1112 271 t b f; #X floatatom 594 160 10 0 1 1 FSR_offset(between_0_and_1) fsr fsr-send ; #X obj 595 52 bng 15 250 50 0 write empty Write 17 7 0 10 -262144 -1 @@ -1254,7 +1249,7 @@ -1; #X text 594 32 T-Stick memory; #X obj 157 102 unpack s f; -#X obj 257 320 route list; +#X obj 524 251 route list; #X msg 111 88 8000; #X obj 367 122 tgl 25 0 empty empty Receive_OSC_messages 30 14 0 14 -262144 -1 -1 1 1; @@ -1262,49 +1257,33 @@ #X msg 172 38 0; #X obj 118 48 t 1 b b; #X obj 45 88 delay 500; -#X obj 923 441 unpack f f f f; -#X floatatom 857 472 10 0 0 0 - - -; -#X floatatom 923 472 10 0 0 0 - - -; -#X floatatom 989 472 10 0 0 0 - - -; -#X floatatom 1055 472 10 0 0 0 - - -; -#X text 932 422 Quaternions; -#X obj 833 229 oscformat state touchMask; -#X obj 880 296 list prepend send; -#X obj 880 320 list trim; +#X obj 561 337 unpack f f f f; +#X floatatom 495 368 10 0 0 0 - - -; +#X floatatom 561 368 10 0 0 0 - - -; +#X floatatom 627 368 10 0 0 0 - - -; +#X floatatom 693 368 10 0 0 0 - - -; +#X text 570 318 Quaternions; #X obj 118 20 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; -#X obj 991 229 oscformat state json; -#X msg 997 201 1; -#X msg 1056 200 2; #N canvas 0 22 450 278 (subpatch) 0; #X array Touch 16 float 1; -#A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; +#A 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0; #X coords 0 2 15 -1 60 140 1; -#X restore 659 767 graph; -#X obj 295 390 s info; +#X restore 650 486 graph; +#X obj 672 317 s info; #X obj 1072 31 r info; #X obj 972 102 s serial; #X obj 1027 102 s firmware; -#X obj 1112 351 list trim; #X obj 366 55 tgl 15 0 empty empty Send_OSC_messages_to_T-Stick 17 7 0 10 -262144 -1 -1 0 1; -#X obj 94 130 sel 1 0; -#X obj 95 180 t b b; -#X obj 1112 331 list prepend connect; -#X obj 682 353 oscformat state info; -#X msg 682 334 1; +#X obj 94 120 sel 1 0; +#X obj 95 170 t b b; #X floatatom 594 106 7 0 0 3 Serial_number serial sserial; #X floatatom 694 106 7 0 0 3 Firmware_version firmware sfirmware; #X obj 595 86 bng 15 250 50 0 getinfo empty Get_T-Stick_info 17 7 0 10 -262144 -1 -1; -#X obj 594 180 bng 15 250 50 0 empty empty send_FSR_offset 17 7 0 10 --262144 -1 -1; -#X obj 1133 203 f; -#X obj 578 257 spigot; -#X obj 651 312 delay 1000; -#X msg 741 277 0; -#X msg 651 333 1; -#X obj 650 292 t b b b; +#X obj 594 180 bng 15 250 50 0 send_FSR_offset empty send_FSR_offset +17 7 0 10 -262144 -1 -1; #N canvas 874 259 723 647 visual_orientation 0; #X obj 30 158 gemwin; #X msg 30 83 0 \, destroy; @@ -1396,114 +1375,231 @@ #X connect 43 0 44 0; #X connect 44 0 39 0; #X connect 45 0 4 0; -#X restore 1092 616 pd visual_orientation; -#X obj 1090 573 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 +#X restore 993 543 pd visual_orientation; +#X obj 1038 562 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; -#X text 1108 573 Click here to check orientation; -#X floatatom 1152 498 10 0 0 0 - - -; -#X floatatom 1218 498 10 0 0 0 - - -; -#X floatatom 1284 498 10 0 0 0 - - -; -#X obj 1188 457 unpack f f f; +#X text 1056 562 Click here to check orientation; +#X floatatom 1015 513 10 0 0 0 - - -; +#X floatatom 1081 513 10 0 0 0 - - -; +#X floatatom 1147 513 10 0 0 0 - - -; +#X obj 1051 489 unpack f f f; #X obj 172 59 s touch; -#X obj 997 174 r write; -#X obj 1056 175 r read; -#X obj 1112 251 r port; -#X obj 113 158 s todisconect; -#X obj 986 322 r todisconect; -#X obj 135 250 s toport; -#X obj 162 231 s toip; -#X obj 1079 272 r ip; -#X obj 1148 180 r fsr-send; -#X obj 1133 227 oscformat state FSRoffset; -#X obj 650 264 r getinfo; +#X obj 113 148 s todisconect; +#X obj 135 200 s toport; +#X obj 162 181 s toip; #X obj 1094 134 s fsr; -#X obj 97 769 vsl 45 135 -1 1 0 0 empty empty AccelX 0 -9 0 10 -262144 --1 -1 6896 1; -#X obj 147 769 vsl 45 135 -1 1 0 0 empty empty AccelY 0 -9 0 10 -262144 --1 -1 6893 1; -#X obj 197 769 vsl 45 135 -1 1 0 0 empty empty AccelZ 0 -9 0 10 -262144 --1 -1 6716 1; -#X obj 247 769 vsl 45 135 -1 1 0 0 empty empty GyroX 0 -9 0 10 -262144 --1 -1 6697 1; -#X obj 297 769 vsl 45 135 -1 1 0 0 empty empty GyroY 0 -9 0 10 -262144 --1 -1 6702 1; -#X obj 347 769 vsl 45 135 -1 1 0 0 empty empty GyroZ 0 -9 0 10 -262144 --1 -1 6697 1; -#X obj 547 769 vsl 45 135 0 1 0 0 empty empty Pressure 0 -9 0 10 -262144 +#X obj 97 777 vsl 45 135 -1 1 0 0 empty empty AccelX 0 -9 0 10 -262144 +-1 -1 6700 1; +#X obj 147 777 vsl 45 135 -1 1 0 0 empty empty AccelY 0 -9 0 10 -262144 +-1 -1 6561 1; +#X obj 197 777 vsl 45 135 -1 1 0 0 empty empty AccelZ 0 -9 0 10 -262144 +-1 -1 6948 1; +#X obj 247 777 vsl 45 135 -1 1 0 0 empty empty GyroX 0 -9 0 10 -262144 +-1 -1 6708 1; +#X obj 297 777 vsl 45 135 -1 1 0 0 empty empty GyroY 0 -9 0 10 -262144 +-1 -1 6704 1; +#X obj 347 777 vsl 45 135 -1 1 0 0 empty empty GyroZ 0 -9 0 10 -262144 +-1 -1 6694 1; +#X obj 547 777 vsl 45 135 0 1 0 0 empty empty Pressure 0 -9 0 10 -262144 -1 -1 0 1; -#X obj 597 769 vsl 45 135 0 1 0 0 empty empty Piezo 0 -9 0 10 -262144 +#X obj 597 777 vsl 45 135 0 1 0 0 empty empty Piezo 0 -9 0 10 -262144 -1 -1 13400 1; -#X obj 397 769 vsl 45 135 -1 1 0 0 empty empty MagX 0 -9 0 10 -262144 --1 -1 6837 1; -#X obj 447 769 vsl 45 135 -1 1 0 0 empty empty MagY 0 -9 0 10 -262144 --1 -1 6613 1; -#X obj 497 769 vsl 45 135 -1 1 0 0 empty empty MagZ 0 -9 0 10 -262144 --1 -1 6678 1; -#X floatatom 197 912 7 0 0 0 - - -; -#X floatatom 247 912 7 0 0 0 - - -; -#X floatatom 297 912 7 0 0 0 - - -; -#X floatatom 347 912 7 0 0 0 - - -; -#X floatatom 547 912 7 0 0 0 - - -; -#X floatatom 597 912 7 0 0 0 - - -; -#X floatatom 397 912 7 0 0 0 - - -; -#X floatatom 447 912 7 0 0 0 - - -; -#X floatatom 497 912 7 0 0 0 - - -; -#X floatatom 147 912 7 0 0 0 - - -; -#X floatatom 97 912 7 0 0 0 - - -; -#X obj 218 719 unpack f f f; -#X obj 298 719 unpack f f f; -#X obj 379 719 unpack f f f; -#X obj 194 696 route capsense accl gyro magn fsr piezo, f 62; -#X obj 450 382 s norm; -#X obj 147 680 r norm; -#X text 20 491 Raw (/raw); +#X obj 397 777 vsl 45 135 -1 1 0 0 empty empty MagX 0 -9 0 10 -262144 +-1 -1 6751 1; +#X obj 447 777 vsl 45 135 -1 1 0 0 empty empty MagY 0 -9 0 10 -262144 +-1 -1 6797 1; +#X obj 497 777 vsl 45 135 -1 1 0 0 empty empty MagZ 0 -9 0 10 -262144 +-1 -1 6871 1; +#X floatatom 197 920 7 0 0 0 - - -; +#X floatatom 247 920 7 0 0 0 - - -; +#X floatatom 297 920 7 0 0 0 - - -; +#X floatatom 347 920 7 0 0 0 - - -; +#X floatatom 547 920 7 0 0 0 - - -; +#X floatatom 597 920 7 0 0 0 - - -; +#X floatatom 397 920 7 0 0 0 - - -; +#X floatatom 447 920 7 0 0 0 - - -; +#X floatatom 497 920 7 0 0 0 - - -; +#X floatatom 147 920 7 0 0 0 - - -; +#X floatatom 97 920 7 0 0 0 - - -; +#X obj 218 727 unpack f f f; +#X obj 298 727 unpack f f f; +#X obj 379 727 unpack f f f; +#X obj 194 674 route capsense accl gyro magn fsr piezo, f 62; +#X obj 718 317 s norm; +#X obj 147 658 r norm; +#X text 20 469 Raw (/raw); #N canvas 0 22 450 278 (subpatch) 0; #X array Touch2 16 float 1; #A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; #X coords 0 2 15 -1 60 140 1; -#X restore 721 767 graph; +#X restore 712 486 graph; #N canvas 0 22 450 278 (subpatch) 0; #X array Touch3 16 float 1; #A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; #X coords 0 2 15 -1 60 140 1; -#X restore 783 767 graph; +#X restore 774 486 graph; #N canvas 0 22 450 278 (subpatch) 0; #X array Touch4 16 float 1; #A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; #X coords 0 2 15 -1 60 140 1; -#X restore 845 767 graph; +#X restore 836 486 graph; #N canvas 0 22 450 278 (subpatch) 0; #X array Touch5 16 float 1; #A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; #X coords 0 2 15 -1 60 140 1; -#X restore 907 767 graph; -#X text 20 726 Normalized (/norm); -#X text 124 341 Change T-Stick NAME!; -#X obj 257 341 route TStick_202; -#X obj 510 384 s battery; +#X restore 898 486 graph; +#X text 20 734 Normalized (/norm); +#X text 391 272 Change T-Stick NAME!; +#X obj 524 272 route TStick_202; +#X obj 765 318 s battery; #X obj 843 83 r battery; #X floatatom 761 212 4 0 0 1 % - -; -#X text 1210 438 YPR; -#X obj 116 410 route capsense accl gyro magn fsr piezo button, f 62 +#X text 1073 470 YPR; +#X obj 41 345 route capsense accl gyro magn fsr piezo button, f 62 ; -#X obj 534 416 route short long double; -#X obj 579 438 tgl 15 0 empty empty long -4 23 0 10 -262144 -1 -1 0 +#X obj 534 398 route short long double; +#X obj 579 420 tgl 15 0 empty empty long -4 23 0 10 -262144 -1 -1 0 1; -#X obj 624 438 tgl 15 0 empty empty double -9 23 0 10 -262144 -1 -1 +#X obj 624 420 tgl 15 0 empty empty double -9 23 0 10 -262144 -1 -1 0 1; -#X obj 526 457 bng 15 250 50 0 empty empty short 17 7 0 10 -262144 +#X obj 518 431 bng 15 250 50 0 empty empty short 17 7 0 10 -262144 -1 -1; -#X obj 526 436 sel 1; +#X obj 499 415 sel 1; #X obj 1072 57 list split 3; #X obj 1024 78 unpack f f f; -#X msg 363 210 255 255 255 255 255 255 255 255 255 255; #X msg 1106 102 set \$1 \$2 \$3 \$4 \$5 \$6 \$7 \$8 \$9 \$10; #X text 608 210 Touch mask; -#X text 833 37 Edu Meneses - IDMIL - Mar/2020; -#X text 833 20 T-Stick FW200320; -#X msg 157 81 192.168.21.202 8888; -#X obj 257 362 route raw orientation ypr info norm battery, f 44; #X text 752 192 Battery; +#N canvas 174 432 831 421 sending_messages_to_T-Stick 0; +#X msg 547 353 disconnect; +#X obj 547 376 netsend -u -b; +#X obj 673 320 pack s f; +#X obj 703 300 i; +#X obj 673 280 t b f; +#X obj 298 148 oscformat state touchMask; +#X obj 441 305 list prepend send; +#X obj 441 329 list trim; +#X obj 456 148 oscformat state json; +#X msg 462 120 1; +#X msg 521 119 2; +#X obj 673 360 list trim; +#X obj 673 340 list prepend connect; +#X obj 227 292 oscformat state info; +#X msg 227 273 1; +#X obj 598 122 f; +#X obj 56 80 spigot; +#X obj 142 248 delay 1000; +#X msg 296 216 0; +#X msg 142 269 1; +#X obj 169 210 t b b b; +#X obj 462 93 r write; +#X obj 521 94 r read; +#X obj 673 260 r port; +#X obj 547 331 r todisconect; +#X obj 640 281 r ip; +#X obj 613 99 r fsr-send; +#X obj 598 146 oscformat state FSRoffset; +#X obj 169 182 r getinfo; +#X obj 598 78 r send_FSR_offset; +#X obj 54 41 r touch_list; +#X connect 0 0 1 0; +#X connect 2 0 12 0; +#X connect 3 0 2 1; +#X connect 4 0 2 0; +#X connect 4 1 3 0; +#X connect 5 0 6 0; +#X connect 6 0 7 0; +#X connect 7 0 1 0; +#X connect 8 0 6 0; +#X connect 9 0 8 0; +#X connect 10 0 8 0; +#X connect 11 0 1 0; +#X connect 12 0 11 0; +#X connect 13 0 6 0; +#X connect 14 0 13 0; +#X connect 15 0 27 0; +#X connect 16 0 5 0; +#X connect 17 0 19 0; +#X connect 18 0 16 1; +#X connect 19 0 16 1; +#X connect 20 0 17 0; +#X connect 20 1 14 0; +#X connect 20 2 18 0; +#X connect 21 0 9 0; +#X connect 22 0 10 0; +#X connect 23 0 4 0; +#X connect 24 0 0 0; +#X connect 25 0 2 0; +#X connect 26 0 15 1; +#X connect 27 0 6 0; +#X connect 28 0 20 0; +#X connect 29 0 15 0; +#X connect 30 0 16 0; +#X restore 1142 174 pd sending_messages_to_T-Stick; +#X obj 363 245 s touch_list; +#X text 668 417 button; +#X msg 363 210 255 255 255 255 255 255 255 255 0 0; +#X obj 524 293 route raw orientation ypr info norm battery instrument +; +#X obj 829 319 s instrument; +#X obj 811 687 r instrument; +#X obj 680 733 route all top middle bottom; +#X obj 680 777 vsl 35 135 0 1 0 0 empty empty All 0 -9 0 10 -262144 +-1 -1 2512 1; +#X floatatom 680 920 6 0 0 0 - - -; +#X obj 722 777 vsl 35 135 0 1 0 0 empty empty Top 0 -9 0 10 -262144 +-1 -1 0 1; +#X floatatom 722 920 6 0 0 0 - - -; +#X obj 765 777 vsl 35 135 0 1 0 0 empty empty Middle 0 -9 0 10 -262144 +-1 -1 1675 1; +#X floatatom 765 920 6 0 0 0 - - -; +#X obj 807 777 vsl 35 135 0 1 0 0 empty empty Bottom 0 -9 0 10 -262144 +-1 -1 6700 1; +#X floatatom 807 920 6 0 0 0 - - -; +#X obj 849 777 vsl 35 135 -1 1 0 0 empty empty Brush 0 -9 0 10 -262144 +-1 -1 6700 1; +#X floatatom 849 920 6 0 0 0 - - -; +#X text 677 698 Instrument; +#N canvas 0 22 450 278 (subpatch) 0; +#X array multibrush 4 float 3; +#A 0 0 0 0 0; +#X coords 0 -1 4 1 60 140 1 0 0; +#X restore 891 775 graph; +#X obj 850 733 array set multibrush; +#X obj 958 777 vsl 35 135 0 10 0 0 empty empty Rub 0 -9 0 10 -262144 +-1 -1 0 1; +#X floatatom 958 920 6 0 0 0 - - -; +#N canvas 0 22 450 278 (subpatch) 0; +#X array multirub 4 float 3; +#A 0 0 0 0 0; +#X coords 0 10 4 -0.1 60 140 1 0 0; +#X restore 1000 775 graph; +#X obj 977 733 array set multirub; +#X obj 1067 777 vsl 35 135 0 100 0 0 empty empty ShakeX 0 -9 0 10 -262144 +-1 -1 0 1; +#X floatatom 1067 920 6 0 0 0 - - -; +#X obj 1109 777 vsl 35 135 0 10 0 0 empty empty ShakeY 0 -9 0 10 -262144 +-1 -1 0 1; +#X floatatom 1109 920 6 0 0 0 - - -; +#X obj 1152 777 vsl 35 135 0 10 0 0 empty empty ShakeZ 0 -9 0 10 -262144 +-1 -1 0 1; +#X floatatom 1152 920 6 0 0 0 - - -; +#X obj 1092 733 unpack f f f; +#X obj 811 708 route touch brush multibrush rub multirub shakexyz jabxyz +ypr, f 62; +#X obj 1193 777 vsl 35 135 0 100 0 0 empty empty JabX 0 -9 0 10 -262144 +-1 -1 0 1; +#X floatatom 1193 920 6 0 0 0 - - -; +#X obj 1235 777 vsl 35 135 0 10 0 0 empty empty JabY 0 -9 0 10 -262144 +-1 -1 0 1; +#X floatatom 1235 920 6 0 0 0 - - -; +#X obj 1278 777 vsl 35 135 0 10 0 0 empty empty JabZ 0 -9 0 10 -262144 +-1 -1 0 1; +#X floatatom 1278 920 6 0 0 0 - - -; +#X obj 1172 733 unpack f f f; +#X text 833 20 T-Stick FW200422; +#X text 833 37 Edu Meneses - IDMIL - April/2020; +#X msg 157 81 192.168.1.1 8888; #X connect 1 0 30 0; #X connect 2 0 29 0; #X connect 3 0 20 0; @@ -1521,14 +1617,14 @@ #X connect 14 1 12 1; #X connect 15 0 14 0; #X connect 17 0 18 0; -#X connect 19 0 56 0; +#X connect 19 0 51 0; #X connect 31 0 32 0; #X connect 31 0 41 0; -#X connect 32 0 54 0; +#X connect 32 0 49 0; #X connect 35 0 31 0; #X connect 36 0 35 0; -#X connect 37 0 58 0; -#X connect 37 0 59 0; +#X connect 37 0 53 0; +#X connect 37 0 54 0; #X connect 38 0 1 0; #X connect 38 1 2 0; #X connect 38 2 3 0; @@ -1538,119 +1634,118 @@ #X connect 40 0 9 0; #X connect 40 1 10 0; #X connect 40 2 11 0; -#X connect 42 0 43 0; -#X connect 44 0 83 0; -#X connect 47 0 44 1; -#X connect 48 0 44 0; -#X connect 48 1 47 0; -#X connect 53 0 110 0; -#X connect 53 1 109 0; -#X connect 54 0 151 0; -#X connect 55 0 36 0; +#X connect 48 0 85 0; +#X connect 48 1 84 0; +#X connect 49 0 122 0; +#X connect 50 0 36 0; +#X connect 51 0 52 0; +#X connect 52 0 36 0; +#X connect 52 1 35 0; +#X connect 53 0 82 0; +#X connect 54 0 55 0; +#X connect 54 1 50 0; +#X connect 54 2 180 0; +#X connect 55 0 51 0; #X connect 56 0 57 0; -#X connect 57 0 36 0; -#X connect 57 1 35 0; -#X connect 58 0 103 0; -#X connect 59 0 60 0; -#X connect 59 1 55 0; -#X connect 59 2 169 0; -#X connect 60 0 56 0; -#X connect 61 0 62 0; -#X connect 61 1 63 0; -#X connect 61 2 64 0; -#X connect 61 3 65 0; -#X connect 67 0 68 0; +#X connect 56 1 58 0; +#X connect 56 2 59 0; +#X connect 56 3 60 0; +#X connect 62 0 54 0; +#X connect 65 0 133 0; #X connect 68 0 69 0; -#X connect 69 0 43 0; -#X connect 70 0 59 0; -#X connect 71 0 68 0; -#X connect 72 0 71 0; -#X connect 73 0 71 0; -#X connect 76 0 162 0; -#X connect 79 0 43 0; -#X connect 80 0 81 0; -#X connect 81 0 82 0; -#X connect 81 1 107 0; -#X connect 82 0 109 0; -#X connect 82 1 110 0; -#X connect 83 0 79 0; -#X connect 84 0 68 0; -#X connect 85 0 84 0; -#X connect 89 0 90 0; -#X connect 90 0 113 0; -#X connect 91 0 67 0; -#X connect 92 0 94 0; -#X connect 93 0 91 1; -#X connect 94 0 91 1; -#X connect 95 0 92 0; -#X connect 95 1 85 0; -#X connect 95 2 93 0; -#X connect 97 0 96 0; -#X connect 99 0 96 2; -#X connect 100 0 96 3; -#X connect 101 0 96 4; -#X connect 102 0 99 0; -#X connect 102 1 100 0; -#X connect 102 2 101 0; -#X connect 104 0 72 0; -#X connect 105 0 73 0; -#X connect 106 0 48 0; -#X connect 108 0 42 0; -#X connect 111 0 44 0; -#X connect 112 0 90 1; -#X connect 113 0 68 0; -#X connect 114 0 95 0; -#X connect 116 0 137 0; -#X connect 117 0 136 0; -#X connect 118 0 127 0; -#X connect 119 0 128 0; -#X connect 120 0 129 0; -#X connect 121 0 130 0; -#X connect 122 0 131 0; -#X connect 123 0 132 0; -#X connect 124 0 133 0; -#X connect 125 0 134 0; -#X connect 126 0 135 0; -#X connect 138 0 116 0; -#X connect 138 1 117 0; -#X connect 138 2 118 0; -#X connect 139 0 119 0; -#X connect 139 1 120 0; -#X connect 139 2 121 0; -#X connect 140 0 124 0; -#X connect 140 1 125 0; -#X connect 140 2 126 0; -#X connect 141 1 138 0; -#X connect 141 2 139 0; -#X connect 141 3 140 0; -#X connect 141 4 122 0; -#X connect 141 5 123 0; -#X connect 143 0 141 0; -#X connect 151 0 170 0; -#X connect 153 0 154 0; -#X connect 156 0 33 0; -#X connect 156 1 38 0; -#X connect 156 2 39 0; -#X connect 156 3 40 0; -#X connect 156 4 7 0; -#X connect 156 5 8 0; -#X connect 156 6 157 0; -#X connect 157 0 161 0; -#X connect 157 1 158 0; -#X connect 157 2 159 0; -#X connect 161 0 160 0; -#X connect 162 0 163 0; -#X connect 162 1 165 0; -#X connect 163 0 77 0; -#X connect 163 1 78 0; -#X connect 163 2 115 0; -#X connect 164 0 91 0; -#X connect 165 0 164 0; -#X connect 169 0 53 0; -#X connect 170 0 156 0; -#X connect 170 1 61 0; -#X connect 170 2 102 0; -#X connect 170 3 75 0; -#X connect 170 4 142 0; -#X connect 170 5 152 0; +#X connect 69 0 70 0; +#X connect 69 1 83 0; +#X connect 70 0 84 0; +#X connect 70 1 85 0; +#X connect 76 0 75 0; +#X connect 78 0 75 2; +#X connect 79 0 75 3; +#X connect 80 0 75 4; +#X connect 81 0 78 0; +#X connect 81 1 79 0; +#X connect 81 2 80 0; +#X connect 87 0 108 0; +#X connect 88 0 107 0; +#X connect 89 0 98 0; +#X connect 90 0 99 0; +#X connect 91 0 100 0; +#X connect 92 0 101 0; +#X connect 93 0 102 0; +#X connect 94 0 103 0; +#X connect 95 0 104 0; +#X connect 96 0 105 0; +#X connect 97 0 106 0; +#X connect 109 0 87 0; +#X connect 109 1 88 0; +#X connect 109 2 89 0; +#X connect 110 0 90 0; +#X connect 110 1 91 0; +#X connect 110 2 92 0; +#X connect 111 0 95 0; +#X connect 111 1 96 0; +#X connect 111 2 97 0; +#X connect 112 1 109 0; +#X connect 112 2 110 0; +#X connect 112 3 111 0; +#X connect 112 4 93 0; +#X connect 112 5 94 0; +#X connect 114 0 112 0; +#X connect 122 0 142 0; +#X connect 124 0 125 0; +#X connect 127 0 33 0; +#X connect 127 1 38 0; +#X connect 127 2 39 0; +#X connect 127 3 40 0; +#X connect 127 4 7 0; +#X connect 127 5 8 0; +#X connect 127 6 128 0; +#X connect 128 0 132 0; +#X connect 128 1 129 0; +#X connect 128 2 130 0; +#X connect 132 0 131 0; +#X connect 133 0 134 0; +#X connect 133 1 135 0; +#X connect 134 0 66 0; +#X connect 134 1 67 0; +#X connect 134 2 86 0; +#X connect 135 0 141 0; +#X connect 141 0 139 0; +#X connect 142 0 127 0; +#X connect 142 1 56 0; +#X connect 142 3 64 0; +#X connect 142 4 113 0; +#X connect 142 5 123 0; +#X connect 142 6 143 0; +#X connect 144 0 170 0; +#X connect 145 0 146 0; +#X connect 145 1 148 0; +#X connect 145 2 150 0; +#X connect 145 3 152 0; +#X connect 146 0 147 0; +#X connect 148 0 149 0; +#X connect 150 0 151 0; +#X connect 152 0 153 0; +#X connect 154 0 155 0; +#X connect 159 0 160 0; +#X connect 163 0 164 0; +#X connect 165 0 166 0; +#X connect 167 0 168 0; +#X connect 169 0 163 0; +#X connect 169 1 165 0; +#X connect 169 2 167 0; +#X connect 170 0 145 0; +#X connect 170 1 154 0; +#X connect 170 2 158 0; +#X connect 170 3 159 0; +#X connect 170 4 162 0; +#X connect 170 5 169 0; +#X connect 170 6 177 0; +#X connect 170 7 81 0; +#X connect 171 0 172 0; +#X connect 173 0 174 0; +#X connect 175 0 176 0; +#X connect 177 0 171 0; +#X connect 177 1 173 0; +#X connect 177 2 175 0; +#X connect 180 0 48 0; #X coords 0 -1 1 1 470 216 1 354 22; diff --git a/firmware/README.md b/firmware/README.md index 4be279a..6a8bcd5 100644 --- a/firmware/README.md +++ b/firmware/README.md @@ -1,4 +1,4 @@ -# T-Stick 2GW (Firmware version: 200220) +# T-Stick 2GW (Firmware version: 200422) - [First time firmware upload instructions](#first-time-firmware-upload-instructions) * [Option 1: using .bin files and esptool.py](#option-1-using-bin-files-and-esptoolpy) @@ -9,7 +9,9 @@ ## First time firmware upload instructions: -### Option 1: using .bin files and esptool.py +### Option 1: using .bin files and esptool.py - NOT AVAILABLE AT THE MOMENT + +
This method is easier/faster. It uses [esptool.py](https://github.com/espressif/esptool). @@ -61,7 +63,9 @@ To test if the data is being send correctly: - Open the Pure Data (PD) or Max/MSP patch to receive T-Stick messages (they can be found [here](./Configuration)); - Start receive OSC messages according to the chosen patch. -### Option 2: Using Arduino IDE +
+ +### Option 2: Using Arduino IDE _READ ALL DEPENDENCIES AND OBSERVATIONS BEFORE UPLOAD !_ @@ -94,7 +98,7 @@ Observations: Each T-Stick uses a _config.json_ file to store all configuration paramethers. -- Make the necessary changes to the [_config.json_](./esp32_arduino_19X_19101/data/config.json) file: +- Make the necessary changes to the [_config.json_](./esp32_arduino_FW200422/data/config.json) file: - device: replace _color_ with the shrinking material color, and _19X_ with T-stick's serial number - author: replace _IDMIL_ with the builder's name (or alias) - nickname: replace _color_ with the shrinking material color @@ -103,7 +107,7 @@ Each T-Stick uses a _config.json_ file to store all configuration paramethers. ##### Upload (flash) the firmware and config.json into the T-Stick: -- Open the file `esp32_arduino_FW200207.ino` using Arduino IDE +- Open the file `esp32_arduino_FW200422.ino` using Arduino IDE - Choose the proper _board_: `Tools -> Board: "*******" -> LOLIN D32 PRO` - Choose Upload Speed: `Tools -> Upload Speed: "******" -> 115200` - Choose port: @@ -133,6 +137,10 @@ To test if the data is being send correctly: Updating the firmware does not erase the T-Stick saved configuration and it is a relatively simple process: +:warning: **bin files not available for this firmware version**: Please update using [Arduino IDE](#option-2-using-arduino-ide) + +
+ ##### Download the [bin files](./bin): - Download the .bin files located at the bin [folder](./bin) @@ -162,6 +170,7 @@ Updating the firmware does not erase the T-Stick saved configuration and it is a - Navigate to the _esptool-master_ folder in _Terminal_ or _Command Prompt_ - Run the command (__don't forget to replace the --port (/dev/cu.wchusbserial1410) option for your T-Stick port, and the .bin names for the version you plan to upload__): `esptool.py --chip esp32 --port /dev/cu.wchusbserial1410 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 boot_app0.bin 0x1000 bootloader_dio_80m.bin 0x10000 esp32_arduino_19X_19111.ino.bin 0x8000 esp32_arduino_19X_19111.ino.partitions.bin`. Wait for the process to be complete. Do not unplug or turn off your T-Stick during the process. +
## Other Documentation: @@ -175,7 +184,7 @@ Updating the firmware does not erase the T-Stick saved configuration and it is a Sopranino T-Stick 2GW - LOLIN D32 PRO - USB -WiFi Input Devices and Music Interaction Laboratory (IDMIL) Created: February 2018 by Alex Nieva -October 2019 by Edu Meneses - firmware version 19101 (2019-10.v1) +April 2020 by Edu Meneses - firmware version 200422 Notes: Based on test program for reading CY8C201xx using I2C by Joseph Malloch 2011 Adapted to work with Arduino IDE 1.8.10 and T-Stick Sopranino 2GW diff --git a/firmware/esp32_arduino_FW200320/Capsense.ino b/firmware/esp32_arduino_FW200422/Capsense.ino similarity index 90% rename from firmware/esp32_arduino_FW200320/Capsense.ino rename to firmware/esp32_arduino_FW200422/Capsense.ino index 520cf36..c586ade 100644 --- a/firmware/esp32_arduino_FW200320/Capsense.ino +++ b/firmware/esp32_arduino_FW200422/Capsense.ino @@ -3,13 +3,18 @@ // Capsense Definitions // ////////////////////////// +// This firmware works with up to 4 IDMIL capsenses using I2C. It you want to use more +// capsenses, either change the code to use SPI or change the related array sizes to +// accomodate more readings: +// capsense_addresses, RawData.touch, LastState.brushUp, LastState.brushDown, Tstick.touchMask + // CY8CMBR3116 #define BUTTON_STAT 0xAA // Address to read the status of the sensors (2 bytes) -byte capsense_addresses[5]; +byte capsense_addresses[4]; // max 4 capsenses byte nCapsenses = 0; -byte touch[5][2]; // up to 5 capsenses (2 bytes per capsense) +byte touchStripsSize; Capsense capsenseRequest(uint8_t address,uint8_t request, uint8_t answer_size) { @@ -104,7 +109,7 @@ void capsense_scan() { Serial.println("Scanning for CY8CMBR3116 Capsense boards..."); for(I2C_ADDR = 1; I2C_ADDR < 127; I2C_ADDR++ ) { - // This scanner requests the device falily ID + // This scanner requests the device's ID (I2C address) // The CY8CMBR3116 chip should return 154 Capsense capsense = capsenseRequest(I2C_ADDR, FAMILY_ID, 1); if (capsense.answer1 == 154) { @@ -122,4 +127,5 @@ void capsense_scan() { else { Serial.println("Capsense OK\n"); } + touchStripsSize = nCapsenses*16; } diff --git a/firmware/esp32_arduino_FW200320/IMU.ino b/firmware/esp32_arduino_FW200422/IMU.ino similarity index 53% rename from firmware/esp32_arduino_FW200320/IMU.ino rename to firmware/esp32_arduino_FW200422/IMU.ino index e701467..543076c 100644 --- a/firmware/esp32_arduino_FW200320/IMU.ino +++ b/firmware/esp32_arduino_FW200422/IMU.ino @@ -22,19 +22,19 @@ unsigned long offsetDebounce = 0; byte offsetFlag = 0; void taitBryanAngles(float w, float x, float y, float z) { - RawData.ypr[2] = atan2(2.0f * (x * y + w * z), w * w + x * x - y * y - z * z); - RawData.ypr[1] = -asin(2.0f * (x * z - w * y)); - RawData.ypr[0] = atan2(2.0f * (w * x + y * z), w * w - x * x - y * y + z * z); - RawData.ypr[2] *= 180.0f / PI; - RawData.ypr[2] -= 14.14; // Declination at Montreal on 2020-03-12 - RawData.ypr[1] *= 180.0f / PI; - RawData.ypr[0] *= 180.0f / PI; + InstrumentData.ypr[2] = atan2(2.0f * (x * y + w * z), w * w + x * x - y * y - z * z); + InstrumentData.ypr[1] = -asin(2.0f * (x * z - w * y)); + InstrumentData.ypr[0] = atan2(2.0f * (w * x + y * z), w * w - x * x - y * y + z * z); + InstrumentData.ypr[2] *= 180.0f / PI; + InstrumentData.ypr[2] -= 14.14; // Declination at Montreal on 2020-03-12 + InstrumentData.ypr[1] *= 180.0f / PI; + InstrumentData.ypr[0] *= 180.0f / PI; // Apply temporary offset if (offsetYaw > 0) { - RawData.ypr[0] -= offsetYaw; + InstrumentData.ypr[0] -= offsetYaw; } else { - RawData.ypr[0] += offsetYaw; + InstrumentData.ypr[0] += offsetYaw; } } diff --git a/firmware/esp32_arduino_FW200320/OSC.ino b/firmware/esp32_arduino_FW200422/OSC.ino similarity index 65% rename from firmware/esp32_arduino_FW200320/OSC.ino rename to firmware/esp32_arduino_FW200422/OSC.ino index 849576b..7c82d45 100644 --- a/firmware/esp32_arduino_FW200320/OSC.ino +++ b/firmware/esp32_arduino_FW200422/OSC.ino @@ -8,108 +8,171 @@ void sendOSC(char* ip,int32_t port) { IPAddress oscIP; if (oscIP.fromString(ip) != false) { - char namespaceBuffer[31]; - static OSCBundle bundle; + char namespaceBuffer[40]; + static OSCBundle bundleRaw; + static OSCBundle bundleInstrument; snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/capsense",Tstick.id); OSCMessage msgCapsense(namespaceBuffer); - for (byte i=0; i < nCapsenses; ++i) { - msgCapsense.add(RawData.touch[i][0] & Tstick.touchMask[i][0]); - msgCapsense.add(RawData.touch[i][1] & Tstick.touchMask[i][1]); + for (byte i=0; i < nCapsenses*2; ++i) { + msgCapsense.add(RawData.touch[i] & Tstick.touchMask[i]); } - bundle.add(msgCapsense); + bundleRaw.add(msgCapsense); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/button/short",Tstick.id); OSCMessage msgBtnS(namespaceBuffer); msgBtnS.add(RawData.buttonShort); - bundle.add(msgBtnS); + bundleRaw.add(msgBtnS); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/button/long",Tstick.id); OSCMessage msgBtnL(namespaceBuffer); msgBtnL.add(RawData.buttonLong); - bundle.add(msgBtnL); + bundleRaw.add(msgBtnL); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/button/double",Tstick.id); OSCMessage msgBtnD(namespaceBuffer); msgBtnD.add(RawData.buttonDouble); - bundle.add(msgBtnD); + bundleRaw.add(msgBtnD); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/fsr",Tstick.id); OSCMessage msgFsrR(namespaceBuffer); msgFsrR.add(RawData.fsr); - bundle.add(msgFsrR); + bundleRaw.add(msgFsrR); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/norm/fsr",Tstick.id); OSCMessage msgFsrN(namespaceBuffer); msgFsrN.add(NormData.fsr); - bundle.add(msgFsrN); + bundleRaw.add(msgFsrN); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/piezo",Tstick.id); OSCMessage msgPiezoR(namespaceBuffer); msgPiezoR.add(RawData.piezo); - bundle.add(msgPiezoR); + bundleRaw.add(msgPiezoR); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/norm/piezo",Tstick.id); OSCMessage msgPiezoN(namespaceBuffer); msgPiezoN.add(NormData.piezo); - bundle.add(msgPiezoN); + bundleRaw.add(msgPiezoN); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/accl",Tstick.id); OSCMessage msgAcclR(namespaceBuffer); addFloatArrayToMessage(RawData.accl, sizeof(RawData.accl)/sizeof(RawData.accl[0]), msgAcclR); - bundle.add(msgAcclR); + bundleRaw.add(msgAcclR); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/norm/accl",Tstick.id); OSCMessage msgAcclN(namespaceBuffer); addFloatArrayToMessage(NormData.accl, sizeof(NormData.accl)/sizeof(NormData.accl[0]), msgAcclN); - bundle.add(msgAcclN); + bundleRaw.add(msgAcclN); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/gyro",Tstick.id); OSCMessage msgGyroR(namespaceBuffer); addFloatArrayToMessage(RawData.gyro, sizeof(RawData.gyro)/sizeof(RawData.gyro[0]), msgGyroR); - bundle.add(msgGyroR); + bundleRaw.add(msgGyroR); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/norm/gyro",Tstick.id); OSCMessage msgGyroN(namespaceBuffer); addFloatArrayToMessage(NormData.gyro, sizeof(NormData.gyro)/sizeof(NormData.gyro[0]), msgGyroN); - bundle.add(msgGyroN); + bundleRaw.add(msgGyroN); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/raw/magn",Tstick.id); OSCMessage msgMagnR(namespaceBuffer); addFloatArrayToMessage(RawData.magn, sizeof(RawData.magn)/sizeof(RawData.magn[0]), msgMagnR); - bundle.add(msgMagnR); + bundleRaw.add(msgMagnR); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/norm/magn",Tstick.id); OSCMessage msgMagnN(namespaceBuffer); addFloatArrayToMessage(NormData.magn, sizeof(NormData.magn)/sizeof(NormData.magn[0]), msgMagnN); - bundle.add(msgMagnN); + bundleRaw.add(msgMagnN); OSCMessage msgRaw("/raw"); addFloatArrayToMessage(RawData.raw, sizeof(RawData.raw)/sizeof(RawData.raw[0]), msgRaw); - bundle.add(msgRaw); + bundleRaw.add(msgRaw); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/orientation",Tstick.id); OSCMessage msgQuat(namespaceBuffer); addFloatArrayToMessage(RawData.quat, sizeof(RawData.quat)/sizeof(RawData.quat[0]), msgQuat); - bundle.add(msgQuat); + bundleRaw.add(msgQuat); + + oscEndpoint.beginPacket(oscIP,port); + bundleRaw.send(oscEndpoint); + oscEndpoint.endPacket(); + bundleRaw.empty(); - snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/ypr",Tstick.id); + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/ypr",Tstick.id); OSCMessage msgYpr(namespaceBuffer); - addFloatArrayToMessage(RawData.ypr, sizeof(RawData.ypr)/sizeof(RawData.ypr[0]), msgYpr); - bundle.add(msgYpr); + addFloatArrayToMessage(InstrumentData.ypr, sizeof(InstrumentData.ypr)/sizeof(InstrumentData.ypr[0]), msgYpr); + bundleInstrument.add(msgYpr); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/touch/all",Tstick.id); + OSCMessage msgTouchAll(namespaceBuffer); + msgTouchAll.add(InstrumentData.touchAll); + bundleInstrument.add(msgTouchAll); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/touch/top",Tstick.id); + OSCMessage msgTouchTop(namespaceBuffer); + msgTouchTop.add(InstrumentData.touchTop); + bundleInstrument.add(msgTouchTop); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/touch/middle",Tstick.id); + OSCMessage msgtouchMiddle(namespaceBuffer); + msgtouchMiddle.add(InstrumentData.touchMiddle); + bundleInstrument.add(msgtouchMiddle); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/touch/bottom",Tstick.id); + OSCMessage msgtouchBottom(namespaceBuffer); + msgtouchBottom.add(InstrumentData.touchBottom); + bundleInstrument.add(msgtouchBottom); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/brush",Tstick.id); + OSCMessage msgBrush(namespaceBuffer); + msgBrush.add(InstrumentData.brush); + bundleInstrument.add(msgBrush); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/multibrush",Tstick.id); + OSCMessage msgMultiBrush(namespaceBuffer); + for (byte i=0; i < sizeof(InstrumentData.multiBrush)/sizeof(InstrumentData.multiBrush[0]); ++i) { + msgMultiBrush.add(InstrumentData.multiBrush[i]); + } + bundleInstrument.add(msgMultiBrush); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/rub",Tstick.id); + OSCMessage msgRub(namespaceBuffer); + msgRub.add(InstrumentData.rub); + bundleInstrument.add(msgRub); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/multirub",Tstick.id); + OSCMessage msgMultiRub(namespaceBuffer); + for (byte i=0; i < sizeof(InstrumentData.multiRub)/sizeof(InstrumentData.multiRub[0]); ++i) { + msgMultiRub.add(InstrumentData.multiRub[i]); + } + bundleInstrument.add(msgMultiRub); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/shakexyz",Tstick.id); + OSCMessage msgShakeXYZ(namespaceBuffer); + for (byte i=0; i < sizeof(InstrumentData.shakeXYZ)/sizeof(InstrumentData.shakeXYZ[0]); ++i) { + msgShakeXYZ.add(InstrumentData.shakeXYZ[i]); + } + bundleInstrument.add(msgShakeXYZ); + + snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/instrument/jabxyz",Tstick.id); + OSCMessage msgJabXYZ(namespaceBuffer); + for (byte i=0; i < sizeof(InstrumentData.jabXYZ)/sizeof(InstrumentData.jabXYZ[0]); ++i) { + msgJabXYZ.add(InstrumentData.jabXYZ[i]); + } + bundleInstrument.add(msgJabXYZ); if (millis() - batteryLastSend > batteryInterval) { batteryLastSend = millis(); snprintf(namespaceBuffer,(sizeof(namespaceBuffer)-1),"/TStick_%i/battery",Tstick.id); OSCMessage msgBattery(namespaceBuffer); msgBattery.add(batteryPercentage); - bundle.add(msgBattery); + bundleInstrument.add(msgBattery); } oscEndpoint.beginPacket(oscIP,port); - bundle.send(oscEndpoint); + bundleInstrument.send(oscEndpoint); oscEndpoint.endPacket(); - bundle.empty(); + bundleInstrument.empty(); } } @@ -202,16 +265,12 @@ void saveIMUgMatrix(OSCMessage &msg) { void receiveTouchMask(OSCMessage &msg) { // message order: Tstick.touchMask[0][0], [0][1], [1][0], [1][1], ... for (byte i=0; i < (sizeof(Tstick.touchMask)/sizeof(Tstick.touchMask[0])); ++i ) { - Tstick.touchMask[i][0] = (int)msg.getFloat(2*i); - Tstick.touchMask[i][1] = (int)msg.getFloat((2*i)+1); + Tstick.touchMask[i] = (int)msg.getFloat(2*i); + } + Serial.print("touchMask values received: "); + for (byte i=0; i < sizeof(Tstick.touchMask); ++i) { + Serial.print(Tstick.touchMask[i]); Serial.print(" "); } - Serial.print("touchMask values received: "); - printf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %i", - Tstick.touchMask[0][0],Tstick.touchMask[0][1], - Tstick.touchMask[1][0],Tstick.touchMask[1][1], - Tstick.touchMask[2][0],Tstick.touchMask[2][1], - Tstick.touchMask[3][0],Tstick.touchMask[3][1], - Tstick.touchMask[4][0],Tstick.touchMask[4][1]); Serial.println(); } @@ -236,8 +295,7 @@ void sendInfo(OSCMessage &msg) { msgInfo.add(Tstick.firmware); msgInfo.add(float(Tstick.FSRoffset)/4095); for (byte i=0; i < (sizeof(RawData.touch)/sizeof(RawData.touch[0])); ++i) { - msgInfo.add(Tstick.touchMask[i][0]); - msgInfo.add(Tstick.touchMask[i][1]); + msgInfo.add(Tstick.touchMask[i]); } oscEndpoint.beginPacket(oscIP, Tstick.oscPORT[0]); msgInfo.send(oscEndpoint); @@ -250,15 +308,13 @@ void sendInfo(OSCMessage &msg) { msgInfo.add(Tstick.firmware); msgInfo.add(float(Tstick.FSRoffset)/4095); for (byte i=0; i < (sizeof(RawData.touch)/sizeof(RawData.touch[0])); ++i) { - msgInfo.add(Tstick.touchMask[i][0]); - msgInfo.add(Tstick.touchMask[i][1]); + msgInfo.add(Tstick.touchMask[i]); } oscEndpoint.beginPacket(oscIP, Tstick.oscPORT[1]); msgInfo.send(oscEndpoint); oscEndpoint.endPacket(); msgInfo.empty(); } - } diff --git a/firmware/esp32_arduino_FW200320/WiFi.ino b/firmware/esp32_arduino_FW200422/WiFi.ino similarity index 93% rename from firmware/esp32_arduino_FW200320/WiFi.ino rename to firmware/esp32_arduino_FW200422/WiFi.ino index c7d1fa7..a2cbbeb 100644 --- a/firmware/esp32_arduino_FW200320/WiFi.ino +++ b/firmware/esp32_arduino_FW200422/WiFi.ino @@ -73,12 +73,11 @@ void Wifimanager_portal(char *portal_name, char *portal_password) { fsrbuf = float(Tstick.FSRoffset) / 4095; WiFiManagerParameter wifimanager_FSRoffset("FSRoffset", "FSR offset value (default = 0)", dtostrf(fsrbuf,2,3,wifimanagerbuf), 6); - snprintf(wifimanagerbuf,(sizeof(wifimanagerbuf)-1),"%i,%i,%i,%i,%i,%i,%i,%i,%i,%i", - Tstick.touchMask[0][0],Tstick.touchMask[0][1], - Tstick.touchMask[1][0],Tstick.touchMask[1][1], - Tstick.touchMask[2][0],Tstick.touchMask[2][1], - Tstick.touchMask[3][0],Tstick.touchMask[3][1], - Tstick.touchMask[4][0],Tstick.touchMask[4][1]); + snprintf(wifimanagerbuf,(sizeof(wifimanagerbuf)-1),"%i,%i,%i,%i,%i,%i,%i,%i", + Tstick.touchMask[0],Tstick.touchMask[1], + Tstick.touchMask[2],Tstick.touchMask[3], + Tstick.touchMask[4],Tstick.touchMask[5], + Tstick.touchMask[6],Tstick.touchMask[7]); WiFiManagerParameter wifimanager_touchMask("touchMask", "Touch Mask capacitive sensing values", wifimanagerbuf, 40); @@ -171,18 +170,13 @@ void Wifimanager_portal(char *portal_name, char *portal_password) { strcpy(wifimanagerbuf,wifimanager_touchMask.getValue()); copybuf = strtok(wifimanagerbuf,","); if (copybuf != NULL) { - Tstick.touchMask[0][0] = atoi(copybuf); + Tstick.touchMask[0] = atoi(copybuf); copybuf = strtok(NULL,","); - if (copybuf != NULL) { - Tstick.touchMask[0][1] = atoi(copybuf); - } for (byte i=1; i < (sizeof(Tstick.touchMask)/sizeof(Tstick.touchMask)[0]); ++i) { copybuf = strtok(NULL,","); if (copybuf == NULL) {break;} - Tstick.touchMask[i][0] = atoi(copybuf); + Tstick.touchMask[i] = atoi(copybuf); copybuf = strtok(NULL,","); - if (copybuf == NULL) {break;} - Tstick.touchMask[i][1] = atoi(copybuf); } } diff --git a/firmware/esp32_arduino_FW200320/data.ino b/firmware/esp32_arduino_FW200422/data.ino similarity index 65% rename from firmware/esp32_arduino_FW200320/data.ino rename to firmware/esp32_arduino_FW200422/data.ino index 9441c28..4554a23 100644 --- a/firmware/esp32_arduino_FW200320/data.ino +++ b/firmware/esp32_arduino_FW200422/data.ino @@ -1,12 +1,18 @@ -void readData() { + +void readData() { + // Read capsense touch data for (byte i=0; i < nCapsenses; ++i) { capsense = capsenseRequest(capsense_addresses[i],BUTTON_STAT, 2); - RawData.touch[i][0] = capsense.answer1; - RawData.touch[i][1] = capsense.answer2; + RawData.touch[i*2] = capsense.answer1; + RawData.touch[(i*2)+1] = capsense.answer2; + } + for (byte i=0; i < touchStripsSize; ++i) { + RawData.touchStrips[i] = bitRead(RawData.touch[i/8],7-(i%8)); } + reorderCapsense (RawData.touchStrips, touchStripsSize); // Read button buttonState = !digitalRead(buttonPin); @@ -89,6 +95,16 @@ void readData() { copyFloatArrayToVar(reading.magn.data(), reading.magn.size(), RawData.magn); copyFloatArrayToVar(reading.data, reading.size, RawData.raw); copyFloatArrayToVar(quat.coeffs().data(), quat.coeffs().size(), RawData.quat); + + LastState.gyroXArray[LastState.gyroArrayCounter] = RawData.gyro[0]; + LastState.gyroYArray[LastState.gyroArrayCounter] = RawData.gyro[1]; + LastState.gyroZArray[LastState.gyroArrayCounter] = RawData.gyro[2]; + if (LastState.gyroArrayCounter < 5) { + LastState.gyroArrayCounter++; + } + else { + LastState.gyroArrayCounter = 0; + } for (int i = 0; i < (sizeof(RawData.accl)/sizeof(RawData.accl[0])); ++i) { NormData.accl[i] = mapfloat(RawData.accl[i], -32767, 32767, -1, 1); @@ -113,7 +129,7 @@ void readData() { offsetFlag = 1; } if (offsetFlag == 1 && millis() - 200 > offsetDebounce) { - offsetYaw = RawData.ypr[0]; + offsetYaw = InstrumentData.ypr[0]; offsetFlag = 0; } } @@ -133,18 +149,35 @@ float mapfloat(float x, float in_min, float in_max, float out_min, float out_max } +void reorderCapsense (byte *origArray, byte arraySize) { + byte tempArray[arraySize]; + byte order[64] = { + 8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7, + 24,25,26,27,28,29,30,31,16,17,18,19,20,21,22,23, + 40,41,42,43,44,45,46,47,32,33,34,35,36,37,38,39, + 56,57,58,59,60,61,62,63,48,49,50,51,52,53,54,55 + }; + for (byte i=0; i < sizeof(tempArray)/sizeof(tempArray[0]); ++i) { + tempArray[i] = origArray[order[i]]; + } + memcpy(origArray, tempArray, sizeof(tempArray)); +} + + void printData() { if (millis() - serialLastRead > serialInterval) { serialLastRead = millis(); - Serial.println("\nPrinting sensor data: "); + Serial.println("\nPrinting sensor data: \n"); Serial.print("RawData.touch: "); - printf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %i", - RawData.touch[0][0],RawData.touch[0][1], - RawData.touch[1][0],RawData.touch[1][1], - RawData.touch[2][0],RawData.touch[2][1], - RawData.touch[3][0],RawData.touch[3][1], - RawData.touch[4][0],RawData.touch[4][1]); + for (byte i=0; i < sizeof(RawData.touch); ++i) { //for (byte i=0; i < nCapsenses*2; ++i) { + Serial.print(RawData.touch[i]); Serial.print(" "); + } Serial.println(); + Serial.print("RawData.touch(libmapper): "); + for( int i = 0 ; i < touchStripsSize ; ++i ){ + Serial.print(RawData.touchStrips[i]); + Serial.print(" "); + } Serial.print("\nRawData.fsr: "); Serial.println(RawData.fsr); Serial.print("RawData.piezo: "); Serial.println(RawData.piezo); Serial.print("RawData.accl: "); @@ -172,11 +205,41 @@ void printData() { Serial.print(RawData.quat[i], 10); Serial.print(" "); } - Serial.print("\nRawData.ypr: "); - for( int i = 0 ; i < (sizeof(RawData.ypr)/sizeof(RawData.ypr[0])) ; ++i ){ - Serial.print(RawData.ypr[i], 10); + Serial.print("\nInstrumentData.ypr: "); + for( int i = 0 ; i < (sizeof(InstrumentData.ypr)/sizeof(InstrumentData.ypr[0])) ; ++i ){ + Serial.print(InstrumentData.ypr[i], 10); + Serial.print(" "); + } + Serial.println(); + + Serial.println("\nPrinting Instrument data: "); + Serial.print("\nInstrumentData.touchAll: "); Serial.println(InstrumentData.touchAll); + Serial.print("InstrumentData.touchTop: "); Serial.println(InstrumentData.touchTop); + Serial.print("InstrumentData.touchMiddle: "); Serial.println(InstrumentData.touchMiddle); + Serial.print("InstrumentData.touchBottom: "); Serial.println(InstrumentData.touchBottom); + + Serial.print("\nBlobDetection.blobArray: "); + for( int i = 0 ; i < (sizeof(BlobDetection.blobArray)/sizeof(BlobDetection.blobArray[0])) ; ++i ){ + Serial.print(BlobDetection.blobArray[i]); + Serial.print(" "); + } + Serial.println(); + Serial.print("\nBlobDetection.blobPos: "); + for( int i = 0 ; i < (sizeof(BlobDetection.blobPos)/sizeof(BlobDetection.blobPos[0])) ; ++i ){ + Serial.print(BlobDetection.blobPos[i]); Serial.print(" "); } Serial.println(); + Serial.print("\nBlobDetection.blobSize: "); + for( int i = 0 ; i < (sizeof(BlobDetection.blobSize)/sizeof(BlobDetection.blobSize[0])) ; ++i ){ + Serial.print(BlobDetection.blobSize[i], 4); + Serial.print(" "); + } + Serial.println(); + + Serial.print("InstrumentData.brush: "); Serial.println(InstrumentData.brush); + + + Serial.println(); } } diff --git a/firmware/esp32_arduino_FW200320/data/config.json b/firmware/esp32_arduino_FW200422/data/config.json similarity index 85% rename from firmware/esp32_arduino_FW200320/data/config.json rename to firmware/esp32_arduino_FW200422/data/config.json index c482e1a..3fef7de 100755 --- a/firmware/esp32_arduino_FW200320/data/config.json +++ b/firmware/esp32_arduino_FW200422/data/config.json @@ -1,14 +1,14 @@ { - "id": 100, + "id": 206, "type": "SN", "author": "IDMIL", - "color": "Color", + "color": "Blue", "APpasswd": "mappings", - "lastConnectedNetwork": "tstick_network", - "lastStoredPsk": "mappings", - "firmware": 200320, + "lastConnectedNetwork": "noisebox", + "lastStoredPsk": "noisebox", + "firmware": 200422, "osc": 1, - "oscIP1": "192.168.1.100", + "oscIP1": "192.168.1.112", "oscPORT1": 8000, "oscIP2": "0.0.0.0", "oscPORT2": 8000, @@ -30,10 +30,6 @@ 255, 255 ], - "touchMask4": [ - 255, - 255 - ], "abias": [ -18.7934398651, -6.3266038895, diff --git a/firmware/esp32_arduino_FW200320/esp32_arduino_FW200320.ino b/firmware/esp32_arduino_FW200422/esp32_arduino_FW200422.ino similarity index 84% rename from firmware/esp32_arduino_FW200320/esp32_arduino_FW200320.ino rename to firmware/esp32_arduino_FW200422/esp32_arduino_FW200422.ino index 790665d..adca971 100644 --- a/firmware/esp32_arduino_FW200320/esp32_arduino_FW200320.ino +++ b/firmware/esp32_arduino_FW200422/esp32_arduino_FW200422.ino @@ -2,7 +2,7 @@ // Sopranino T-Stick 2GW - LOLIN D32 PRO - USB -WiFi // // Input Devices and Music Interaction Laboratory (IDMIL) // // Created: February 2018 by Alex Nieva // -// October 2019 by Edu Meneses - firmware version 200214 (2020/Feb/20) // +// March 2020 by Edu Meneses - firmware version 200330 (2020/Mar/30) // // Notes : Based on test program for reading CY8C201xx using I2C // // by Joseph Malloch 2011 // // // @@ -42,6 +42,8 @@ // IMPORTANT: You need to upload a file (data/config.json) into ESP32 filesystem. // Follow the instructions at https://github.com/me-no-dev/arduino-esp32fs-plugin +// Tested on Wemos Lolin D32 Pro + // DEPENDENCIES: // esp32 board library (add url to preferences; install via board manager) // esp8266 board library (add url to preferences; install via board manager) @@ -103,7 +105,7 @@ ////////////////////////////////// ////////////////////////////////// -const int32_t firmware = 200220; +const int32_t firmware = 200330; struct Tstick { int id; @@ -119,7 +121,7 @@ struct Tstick { int32_t oscPORT[2]; byte libmapper; int16_t FSRoffset; - byte touchMask[5][2]; + byte touchMask[8]; float abias[3]; float mbias[3]; float gbias[3]; @@ -129,7 +131,8 @@ struct Tstick { } Tstick; struct RawDataStruct { - byte touch[5][2]; // /raw/capsense, i..., 0--255, ... (1 int per 8 capacitive stripes -- 8 bits) + byte touch[8]; // /raw/capsense, i..., 0--255, ... (1 int per 8 capacitive stripes -- 8 bits) + byte touchStrips[64]; int fsr; // /raw/fsr, i, 0--4095 int piezo; // /raw/piezo, i, 0--1023 float accl[3]; // /raw/accl, iii, +/-32767 (integers) @@ -137,7 +140,6 @@ struct RawDataStruct { float magn[3]; // /raw/magn, fff, +/-32767 (integers) float raw[10]; // /raw (IMU data to be send to callibration app) float quat[4]; // /raw/quat, ffff, ?, ? ,? ,? - float ypr[3]; // /raw/ypr, fff, +/-180, +/-90 ,+/-180 (degrees) float magAccl; float magGyro; float magMagn; @@ -154,10 +156,39 @@ struct NormDataStruct { float magn[3]; // /norm/magn, fff, +/-1, +/-1, +/-1 } NormData; +struct LastStateDataStruct { + int blobPos[4]; + int gyroArrayCounter; + float gyroXArray[5]; + float gyroYArray[5]; + float gyroZArray[5]; +} LastState; + +struct InstrumentDataStruct { + float touchAll; // /instrument/touch/all, f, 0--1 + float touchTop; // /instrument/touch/top, f, 0--1 + float touchMiddle; // /instrument/touch/middle, f, 0--1 + float touchBottom; // /instrument/touch/bottom, f, 0--1 + float brush; // /instrument/touch/brush, f, 0--? (~cm/s) + float multiBrush[4]; // /instrument/touch/brush/multibrush, ffff, 0--? (~cm/s) + float rub; // /instrument/touch/rub, f, 0--? (~cm/s) + float multiRub[4]; // /instrument/touch/rub/multirub, ffff, 0--? (~cm/s) + float ypr[3]; // /instrument/ypr, fff, +/-180, +/-90 ,+/-180 (degrees) + float shakeXYZ[3]; // /instrument/shakexyz, fff, 0--? + float jabXYZ[3]; // /instrument/jabxyz, fff, 0--? +} InstrumentData; + struct Capsense { byte answer1, answer2; } capsense; +struct blob { + byte blobArray[8]; // shows the "center" of each array + int blobPos[4]; // position (index) of each blob + float blobSize[4]; // "size" of each blob +} BlobDetection; + + // IPAddress oscIP; // used to send OSC messages char APpasswdTemp[15]; // used to check before save new T-Stick passwd char APpasswdValidate[15]; // used to check before save new T-Stick passwd @@ -170,6 +201,13 @@ unsigned long batteryLastRead = 0; unsigned long batteryLastSend = 0; byte batteryCount = 0; +/////////////////////////////////// +// Variables for Instrument Data // +/////////////////////////////////// + +byte touchSizeEdge = 4; // amount of T-Stick stripes for top and bottom portions of the T-Stick (arbitrary) + + ////////////////////// // WiFi Definitions // ////////////////////// @@ -181,8 +219,8 @@ const unsigned int portLocal = 8888; // local port to listen for OSC packets (no // defaults // ////////////// -byte piezoPin = 32; -byte fsrPin = 33; +byte piezoPin = 33; +byte fsrPin = 32; byte batteryPin = 35; const int buttonPin = 15; byte buttonState = 0; // variable for reading the pushbutton status @@ -209,6 +247,17 @@ float fsrbuf; const int pwm2Pin = 15; #endif +//////////////////////////////// +// Leaky integrator variables // +//////////////////////////////// + +const int leakyBrushFreq = 100; // leaking frequency (Hz) +unsigned long leakyBrushTimer = 0; +const int leakyRubFreq = 100; +unsigned long leakyRubTimer = 0; +byte brushCounter[4]; +const int leakyShakeFreq = 10; +unsigned long leakyShakeTimer[3]; /////////////// // blink LED // @@ -301,7 +350,7 @@ void setup() { if (Tstick.libmapper == 1) { initLibmapper(); } - + Serial.println("\nT-Stick setup complete.\n"); } @@ -329,6 +378,9 @@ void loop() { // reading sensor data readData(); + // updating high-level gestural descriptors + updateInstrument(); + // send data (OSC) if (Tstick.osc == 1) { sendOSC(Tstick.oscIP[0], Tstick.oscPORT[0]); @@ -342,7 +394,7 @@ void loop() { } } } - + // Update libmapper if (Tstick.libmapper == 1) { updateLibmapper(); diff --git a/firmware/esp32_arduino_FW200320/fs_json.ino b/firmware/esp32_arduino_FW200422/fs_json.ino similarity index 88% rename from firmware/esp32_arduino_FW200320/fs_json.ino rename to firmware/esp32_arduino_FW200422/fs_json.ino index e49e413..d9a99ee 100644 --- a/firmware/esp32_arduino_FW200320/fs_json.ino +++ b/firmware/esp32_arduino_FW200422/fs_json.ino @@ -49,9 +49,7 @@ void printVariables() { Serial.print(" (normalized: "); Serial.print(float(Tstick.FSRoffset)/4095, 4); ; Serial.println(")"); Serial.print("\nTstick.touchMask: "); for( int i = 0 ; i < (sizeof(Tstick.touchMask)/sizeof(Tstick.touchMask[0])) ; ++i ){ - Serial.print(Tstick.touchMask[i][0]); - Serial.print(" "); - Serial.print(Tstick.touchMask[i][1]); + Serial.print(Tstick.touchMask[i], 10); Serial.print(" "); } Serial.print("\nTstick.abias: "); @@ -92,7 +90,7 @@ void parseJSON() { // Allocate a temporary JsonDocument // Don't forget to change the capacity to match your requirements. // Use https://arduinojson.org/v6/assistant/ to compute the capacity. - const size_t capacity = 5*JSON_ARRAY_SIZE(2) + 3*JSON_ARRAY_SIZE(3) + 3*JSON_ARRAY_SIZE(9) + JSON_OBJECT_SIZE(26) + 360; + const size_t capacity = 4*JSON_ARRAY_SIZE(2) + 3*JSON_ARRAY_SIZE(3) + 3*JSON_ARRAY_SIZE(9) + JSON_OBJECT_SIZE(25) + 350; DynamicJsonDocument doc(capacity); if (SPIFFS.exists("/config.json")) { // file exists, reading and loading @@ -121,16 +119,14 @@ void parseJSON() { Tstick.osc = doc["osc"]; Tstick.FSRoffset = doc["FSRoffset"]; - Tstick.touchMask[0][0] = doc["touchMask0"][0]; - Tstick.touchMask[0][1] = doc["touchMask0"][1]; - Tstick.touchMask[1][0] = doc["touchMask1"][0]; - Tstick.touchMask[1][1] = doc["touchMask1"][1]; - Tstick.touchMask[2][0] = doc["touchMask2"][0]; - Tstick.touchMask[2][1] = doc["touchMask2"][1]; - Tstick.touchMask[3][0] = doc["touchMask3"][0]; - Tstick.touchMask[3][1] = doc["touchMask3"][1]; - Tstick.touchMask[4][0] = doc["touchMask4"][0]; - Tstick.touchMask[4][1] = doc["touchMask4"][1]; + Tstick.touchMask[0] = doc["touchMask0"][0]; + Tstick.touchMask[1] = doc["touchMask0"][1]; + Tstick.touchMask[2] = doc["touchMask1"][0]; + Tstick.touchMask[3] = doc["touchMask1"][1]; + Tstick.touchMask[4] = doc["touchMask2"][0]; + Tstick.touchMask[5] = doc["touchMask2"][1]; + Tstick.touchMask[6] = doc["touchMask3"][0]; + Tstick.touchMask[7] = doc["touchMask3"][1]; JsonArray abias = doc["abias"]; Tstick.abias[0] = abias[0]; @@ -201,7 +197,7 @@ void saveJSON() { // Allocate a temporary JsonDocument // Don't forget to change the capacity to match your requirements. // Use https://arduinojson.org/v6/assistant/ to compute the capacity. - const size_t capacity = 5*JSON_ARRAY_SIZE(2) + 3*JSON_ARRAY_SIZE(3) + 3*JSON_ARRAY_SIZE(9) + JSON_OBJECT_SIZE(26) + 360; + const size_t capacity = 4*JSON_ARRAY_SIZE(2) + 3*JSON_ARRAY_SIZE(3) + 3*JSON_ARRAY_SIZE(9) + JSON_OBJECT_SIZE(25); DynamicJsonDocument doc(capacity); // Copy values from Config to the JsonDocument @@ -222,24 +218,20 @@ void saveJSON() { doc["FSRoffset"] = Tstick.FSRoffset; JsonArray touchMask0 = doc.createNestedArray("touchMask0"); - touchMask0.add(Tstick.touchMask[0][0]); - touchMask0.add(Tstick.touchMask[0][1]); + touchMask0.add(Tstick.touchMask[0]); + touchMask0.add(Tstick.touchMask[1]); JsonArray touchMask1 = doc.createNestedArray("touchMask1"); - touchMask1.add(Tstick.touchMask[1][0]); - touchMask1.add(Tstick.touchMask[1][1]); + touchMask1.add(Tstick.touchMask[2]); + touchMask1.add(Tstick.touchMask[3]); JsonArray touchMask2 = doc.createNestedArray("touchMask2"); - touchMask2.add(Tstick.touchMask[2][0]); - touchMask2.add(Tstick.touchMask[2][1]); + touchMask2.add(Tstick.touchMask[4]); + touchMask2.add(Tstick.touchMask[5]); JsonArray touchMask3 = doc.createNestedArray("touchMask3"); - touchMask3.add(Tstick.touchMask[3][0]); - touchMask3.add(Tstick.touchMask[3][1]); - - JsonArray touchMask4 = doc.createNestedArray("touchMask4"); - touchMask4.add(Tstick.touchMask[4][0]); - touchMask4.add(Tstick.touchMask[4][1]); + touchMask3.add(Tstick.touchMask[6]); + touchMask3.add(Tstick.touchMask[7]); JsonArray abias = doc.createNestedArray("abias"); abias.add(Tstick.abias[0]); diff --git a/firmware/esp32_arduino_FW200422/instrument.ino b/firmware/esp32_arduino_FW200422/instrument.ino new file mode 100644 index 0000000..50b6561 --- /dev/null +++ b/firmware/esp32_arduino_FW200422/instrument.ino @@ -0,0 +1,268 @@ + +void updateInstrument() { + + // InstrumentData.touchAll: get the "amount of touch" for the entire capsense + // normalized between 0 and 1 + InstrumentData.touchAll = touchAverage(RawData.touchStrips, 0, touchStripsSize); + + // InstrumentData.touchTop: get the "amount of touch" for the top part of the capsense + // normalized between 0 and 1 + InstrumentData.touchTop = touchAverage(RawData.touchStrips, 0, touchSizeEdge); + + // InstrumentData.touchMiddle: get the "amount of touch" for the central part of the capsense + // normalized between 0 and 1 + InstrumentData.touchMiddle = touchAverage(RawData.touchStrips, (0+touchSizeEdge), (touchStripsSize - touchSizeEdge)); + + // InstrumentData.touchBottom: get the "amount of touch" for the botton part of the capsense + // normalized between 0 and 1 + InstrumentData.touchBottom = touchAverage(RawData.touchStrips, (touchStripsSize-touchSizeEdge), touchStripsSize); + + // Save last blob detection state before reading new data + for (byte i=0; i < (sizeof(BlobDetection.blobPos)/sizeof(BlobDetection.blobPos[0])); ++i) { + LastState.blobPos[i] = BlobDetection.blobPos[i]; + } + + // 1D blob detection: used for brush + BlobDetection = blobDetection1D(RawData.touch,(nCapsenses*2)); + + // InstrumentData.brush: direction and intensity of capsense brush motion + // InstrumentData.rub: intensity of rub motion + // in ~cm/s (distance between stripes = ~1.5cm) + for (byte i=0; i < (sizeof(BlobDetection.blobPos)/sizeof(BlobDetection.blobPos[0])); ++i) { + float movement = BlobDetection.blobPos[i] - LastState.blobPos[i]; + if ( BlobDetection.blobPos[i] == -1 ) { + InstrumentData.multiBrush[i] = 0; + InstrumentData.multiRub[i] = 0; + brushCounter[i] = 0; + } + else if (movement == 0) { + if (brushCounter[i] < 10) { + brushCounter[i]++; + // wait some time before dropping the rub/brush values + } + else if (InstrumentData.multiBrush[i] < 0.001) { + InstrumentData.multiBrush[i] = 0; + InstrumentData.multiRub[i] = 0; + } + else { + InstrumentData.multiBrush[i] = leakyIntegrator(movement*0.15, InstrumentData.multiBrush[i], 0.7, leakyBrushFreq, leakyBrushTimer); + InstrumentData.multiRub[i] = leakyIntegrator(abs(movement*0.15), InstrumentData.multiRub[i], 0.7, leakyRubFreq, leakyRubTimer); + } + } + else if ( abs(movement) > 1 ) { + InstrumentData.multiBrush[i] = leakyIntegrator(0, InstrumentData.multiBrush[i], 0.6, leakyBrushFreq, leakyBrushTimer); + } + else { + InstrumentData.multiBrush[i] = leakyIntegrator(movement*0.15, InstrumentData.multiBrush[i], 0.8, leakyBrushFreq, leakyBrushTimer); + InstrumentData.multiRub[i] = leakyIntegrator(abs(movement*0.15), InstrumentData.multiRub[i], 0.99, leakyRubFreq, leakyRubTimer); + brushCounter[i] = 0; + } + } + InstrumentData.brush = arrayAverageZero(InstrumentData.multiBrush,4); + InstrumentData.rub = arrayAverageZero(InstrumentData.multiRub,4); + + // InstrumentData.shakeXYZ + for (byte i=0; i<(sizeof(RawData.gyro)/sizeof(RawData.gyro[0])); ++i) { + if (abs(RawData.gyro[i]) > 0.1) { + InstrumentData.shakeXYZ[i] = leakyIntegrator(abs(RawData.gyro[i]*0.1), InstrumentData.shakeXYZ[i], 0.6, leakyShakeFreq, leakyShakeTimer[i]); + } + else { + InstrumentData.shakeXYZ[i] = leakyIntegrator(0, InstrumentData.shakeXYZ[i], 0.3, leakyShakeFreq, leakyShakeTimer[i]); + if (InstrumentData.shakeXYZ[i] < 0.01) { + InstrumentData.shakeXYZ[i] = 0; + } + } + } + + // InstrumentData.jabXYZ + if (arrayMax(LastState.gyroXArray,5)-arrayMin(LastState.gyroXArray,5) > 15) { + InstrumentData.jabXYZ[0] = arrayMax(LastState.gyroXArray,5) - arrayMin(LastState.gyroXArray,5) - 10; + } + else { + InstrumentData.jabXYZ[0] = 0; + } + if (arrayMax(LastState.gyroYArray,5)-arrayMin(LastState.gyroYArray,5) > 3) { + InstrumentData.jabXYZ[1] = arrayMax(LastState.gyroYArray,5) - arrayMin(LastState.gyroYArray,5) - 3; + } + else { + InstrumentData.jabXYZ[1] = 0; + } + if (arrayMax(LastState.gyroZArray,5)-arrayMin(LastState.gyroZArray,5) > 10) { + InstrumentData.jabXYZ[2] = arrayMax(LastState.gyroZArray,5) - arrayMin(LastState.gyroZArray,5) - 10; + } + else { + InstrumentData.jabXYZ[2] = 0; + } + + +} + + +float touchAverage (byte * touchArrayStrips, byte firstStrip, byte lastStrip) { + int sum = 0; + for (int i = firstStrip; i < lastStrip; ++i) + sum += touchArrayStrips[i]; + + return ((float) sum) / (lastStrip - firstStrip); +} + + +float arrayAverage (float * Array, byte ArraySize) { + float sum = 0; + for (int i = 0; i < ArraySize; ++i) + sum += Array[i]; + + return (sum / ArraySize); +} + +float arrayAverageZero (float * Array, byte ArraySize) { + float sum = 0; + byte count = 0; + float output = 0; + for (int i = 0; i < ArraySize; ++i) { + if (Array[i] != 0) { + sum += Array[i]; + count++; + } + } + if (count > 0) { + output = sum / count; + } + + return output; +} + + +blob blobDetection1D (byte * touchArray, byte arraySize) { + + // creating local variables + blob blobDecect; + byte tempArray[8]; + int beginBlob = -1; // -1 means it will not count stripes + byte blobCount = 0; + for (byte i=0; i < sizeof(blobDecect.blobPos)/sizeof(blobDecect.blobPos[0]); ++i) { + blobDecect.blobPos[i] = -1; + blobDecect.blobSize[i] = 0; + } + for (byte i=0; i < sizeof(blobDecect.blobArray)/sizeof(blobDecect.blobArray[0]); ++i) { + blobDecect.blobArray[i] = 0; + } + + // fixing capsense byte order + byte order[8] = {1,0,3,2,5,4,7,6}; + for (byte i=0; i < arraySize; ++i) { + tempArray[i] = touchArray[order[i]]; + } + + // shifting and reading... + for (byte i=0; i < arraySize*8; ++i) { + bitShiftArrayL(tempArray, blobDecect.blobArray, arraySize, i); + if ((blobDecect.blobArray[0] & 128) == 128 && beginBlob == -1) { + beginBlob = i; + } + if ( ((blobDecect.blobArray[0] & 128) == 0 || i == (arraySize*8)-1) && beginBlob != -1) { + blobDecect.blobPos[blobCount] = (i + beginBlob) / 2; + blobDecect.blobSize[blobCount] = float(i - beginBlob) / (arraySize * 8); + beginBlob = -1; + blobCount++; + } + } + + for (byte i=0; i < sizeof(blobDecect.blobArray)/sizeof(blobDecect.blobArray[0]); ++i) { + blobDecect.blobArray[i] = 0; + } + for (byte i=0; i < sizeof(blobDecect.blobPos)/sizeof(blobDecect.blobPos[0]); ++i) { + if (blobDecect.blobPos[i] != -1) { + bitWrite(blobDecect.blobArray[blobDecect.blobPos[i]/8], (7-(blobDecect.blobPos[i]%8)), 1); + } + else { + break; + } + } + + return blobDecect; +} + + +void printBinary (byte number) { + byte reading; + for (int i=7; i >= 0; --i) { + reading = number >> i; + Serial.print(reading & 1); + } +} + +void bitShiftArrayL (byte * origArray, byte * shiftedArray, byte arraySize, byte shift) { + + for (byte i=0; i < arraySize; ++i) { + shiftedArray[i] = origArray[i]; + } + + for (byte k=0; k < shift; ++k) { + for (byte i=0; i < arraySize; ++i) { + if ( i == (arraySize-1)) { + shiftedArray[i] = (shiftedArray[i] << 1); + } + else { + shiftedArray[i] = (shiftedArray[i] << 1) | (shiftedArray[i+1] >> 7); + } + } + } +} + + +void bitShiftArrayR (byte * origArray, byte * shiftedArray, byte arraySize, byte shift) { + + for (byte i=0; i < arraySize; ++i) { + shiftedArray[i] = origArray[i]; + } + + for (byte k=0; k < shift; ++k) { + for (int i=arraySize; i >= 0; --i) { + if ( i == 0) { + shiftedArray[i] = (shiftedArray[i] >> 1); + } + else { + shiftedArray[i] = (shiftedArray[i] >> 1) | (shiftedArray[i-1] << 7); + } + } + } +} + +float arrayMin (float *inputArray, byte arraySize) { + float output = inputArray[0]; + for (byte i=1; i= 8) { - if (indexStrip==0){ - indexStrip=1; - } - else { - indexStrip=0; - } - counter = 0; - } - } - - mapper_signal_update(sigRawCapsense, touchtemp, sizeof(touchtemp), MAPPER_NOW); + mapper_signal_update(sigRawCapsense, RawData.touchStrips, sizeof(RawData.touchStrips), MAPPER_NOW); mapper_signal_update_int(sigRawFSR, RawData.fsr); mapper_signal_update_int(sigRawPiezo, RawData.piezo); mapper_signal_update_int(sigRawAcclX, RawData.accl[0]); @@ -116,7 +127,17 @@ void updateLibmapper() { mapper_signal_update_int(sigButton, RawData.buttonShort); mapper_signal_update_int(sigLongButton, RawData.buttonLong); mapper_signal_update_int(sigDoubleButton, RawData.buttonDouble); - mapper_signal_update_float(sigYaw, RawData.ypr[0]); - mapper_signal_update_float(sigPitch, RawData.ypr[1]); - mapper_signal_update_float(sigRoll, RawData.ypr[2]); + mapper_signal_update_float(sigYaw, InstrumentData.ypr[0]); + mapper_signal_update_float(sigPitch, InstrumentData.ypr[1]); + mapper_signal_update_float(sigRoll, InstrumentData.ypr[2]); + mapper_signal_update_float(sigtouchAll, InstrumentData.touchAll); + mapper_signal_update_float(sigtouchTop, InstrumentData.touchTop); + mapper_signal_update_float(sigtouchMiddle, InstrumentData.touchMiddle); + mapper_signal_update_float(sigtouchBottom, InstrumentData.touchBottom); + mapper_signal_update_float(sigBrush, InstrumentData.brush); + mapper_signal_update_float(sigRub, InstrumentData.rub); + mapper_signal_update(sigMultiBrush, RawData.touchStrips, sizeof(InstrumentData.multiBrush)/sizeof(InstrumentData.multiBrush[0]), MAPPER_NOW); + mapper_signal_update(sigMultiRub, RawData.touchStrips, sizeof(InstrumentData.multiRub)/sizeof(InstrumentData.multiRub[0]), MAPPER_NOW); + mapper_signal_update(sigShakeXYZ, RawData.touchStrips, sizeof(InstrumentData.shakeXYZ)/sizeof(InstrumentData.shakeXYZ[0]), MAPPER_NOW); + mapper_signal_update(sigJabXYZ, RawData.touchStrips, sizeof(InstrumentData.jabXYZ)/sizeof(InstrumentData.jabXYZ[0]), MAPPER_NOW); } diff --git a/firmware/esp32_arduino_FW200320/platforms/ESP32.h b/firmware/esp32_arduino_FW200422/platforms/ESP32.h similarity index 100% rename from firmware/esp32_arduino_FW200320/platforms/ESP32.h rename to firmware/esp32_arduino_FW200422/platforms/ESP32.h diff --git a/firmware/esp32_arduino_FW200320/platforms/ESP8266.h b/firmware/esp32_arduino_FW200422/platforms/ESP8266.h similarity index 100% rename from firmware/esp32_arduino_FW200320/platforms/ESP8266.h rename to firmware/esp32_arduino_FW200422/platforms/ESP8266.h