From 118b8c4a226afa48dee7a689798066d3ab8ee724 Mon Sep 17 00:00:00 2001 From: TheDIYGuy999 Date: Sun, 19 Feb 2023 20:23:29 +0100 Subject: [PATCH] v0.10.0: Encoder acceleration makes servo movements easy! --- README.md | 6 +++++- platformio.ini | 10 +++++++--- src/src.ino | 43 +++++++++++++++++++++++++++++-------------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d9d4f8c..83ac689 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,14 @@ forked from his GitHub: https://github.com/Ziege-One/Servotester_Deluxe PCB, schematic and more details: https://www.pcbway.com/project/shareproject/Servotester_Deluxe_62a3f47c.html +## New in v0.10.0: +- Added encoder acceleration in servo tester mode. Makes the operation very handy. If you want to make bigger servo movements, just rotate the encoder faster! +- Unstable Multiswitch issues because of incompatible espressif 32 board solved, see comments in src.ino + ## New in v0.9.0: - Servo is able to oscillate way faster in automatic mode, speed adjustability improved - Made sure, there is no language string array pointer overflow, if EEPROM was deleted before -- There are still issues with unstable Multiswitch readings. Solution for now: use the pre compiled bin files or use Arduino IDE 2.0.3 with espressif board 2.0.5 (which is unfortunately incompatible with VS Code) +- There are still issues with unstable Multiswitch readings. Solution for now: use the pre compiled bin files or use Arduino IDE 2.0.3 with espressif 32 board 2.0.5 (which is unfortunately incompatible with VS Code) ## New in v0.8.0: - Support for calibrated analogRead, using the ESP32AnalogRead library is improving battery monitoring diff --git a/platformio.ini b/platformio.ini index 72769aa..81f545a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,14 +9,19 @@ ; https://docs.platformio.org/page/projectconf.html [env:esp32dev] -;platform = espressif32@3.2.0 ;force to use v3.1.0 with framework-arduinoespressif32 3.10006.210326 (1.0.6) -platform = espressif32 ;use latest version +platform = espressif32@6.0.1 ;force to use v6.0.1 with framework-arduinoespressif32 @ 2.0.6+sha.23f653a +;platform = espressif32 ;use latest version (make sure to update your Espressif Platform from time to time) board = esp32dev board_build.mcu = esp32 board_build.f_cpu = 240000000L board_build.f_flash = 40000000L ;board_build.partitions = huge_app.csv ; this setting enables more flash memory for the app. No OTA! framework = arduino + +;platform package source to make sure, it is always up to date +platform_packages = + platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git + monitor_speed = 115200 ;monitor_port = COM4 ;your port may vary! upload_protocol = esptool @@ -25,7 +30,6 @@ upload_protocol = esptool monitor_filters = esp32_exception_decoder ; This option will show more informations in case of a backtrace! build_flags = - ;-Os ;-DCORE_DEBUG_LEVEL=0 ; 0= none, 1= error, 2= warn, 3= info, 4= debug, 5= verbose diff --git a/src/src.ino b/src/src.ino index 1104b00..9f6f594 100644 --- a/src/src.ino +++ b/src/src.ino @@ -10,8 +10,9 @@ Requirements: - git is installed (allows to download libraries and boards automatically): https://git-scm.com/downloads - PlatformIO plugin is installed in VS Code - Drawback for now: - - Unstable Multiswitch readings, see comment below. << ---------------------------- ! ! ! ! + - Espressif32 platform is up to date in Platformio > Platforms > Updates + + If you are using Arduino IDE: Select the following board: "ESP32 Dev Module" ESP32 + Encoder + OLED @@ -29,7 +30,7 @@ GPIO 22: SDL OLED */ -char codeVersion[] = "0.9.0"; // Software revision. +char codeVersion[] = "0.10.0"; // Software revision. // // ======================================================================================================= @@ -52,7 +53,7 @@ char codeVersion[] = "0.9.0"; // Software revision. // No manual library download is required in Visual Studio Code IDE (see platformio.ini) /* Boardversion -ESP32 2.0.5 <<----- NOTE! this is the only version, which is not causing unstable Multiswitch readings! +ESP32 2.0.5 or 2.0.6 <<--- (make sure your Espressif32 piatform is up to date in Platformio > Platforms > Updates) unfortunately it is not compatible with VS Code, so you have to use Arduino for now. The pre compiled .bin images were made with Arduino. */ @@ -129,6 +130,7 @@ int Duration_double = 200; // Zeit für Doppelklick int bouncing = 50; // Zeit für Taster Entprellung int encoder_last; // Speicher letzer Wert Encoder int encoder_read; // Speicher aktueller Wert Encoder +int encoderSpeed; // Speicher aktuelle Encoder Geschwindigkeit für Beschleunigung // Servo volatile unsigned char servopin[5] = {13, 14, 27, 33, 32}; // Pins Servoausgang @@ -429,14 +431,28 @@ void ButtonRead() Serial.println(buttonState); } - encoder_read = encoder.getCount(); + // Encoder ------------------------------------------------------------------------------------------------- + encoder_read = encoder.getCount(); // Read encoder -------------- - if (previousDebouncTime + 20 > millis()) + if (previousDebouncTime + 10 > millis()) // Debouncing 10ms ------------- { encoder_last = encoder_read; } - if (encoder_last > encoder_read) + static unsigned long encoderSpeedMillis; + static int lastEncoderSpeed; + + if (millis() - encoderSpeedMillis > 100) // Encoder speed detection ----------------- + { + encoderSpeedMillis = millis(); + encoderSpeed = abs(encoder_read - lastEncoderSpeed); + encoderSpeed = constrain(encoderSpeed, 1, 4); + // Serial.println(encoderSpeed); // For encoder speed debuggging + + lastEncoderSpeed = encoder_read; + } + + if (encoder_last > encoder_read) // Left turn detected -------------- { if (encoder_last > encoder_read + 1) { @@ -452,7 +468,7 @@ void ButtonRead() previousDebouncTime = millis(); } } - else if (encoder_last < encoder_read) + else if (encoder_last < encoder_read) // Right turn detected -------------- { if (encoder_last < encoder_read - 1) { @@ -471,8 +487,6 @@ void ButtonRead() else { encoderState = 0; - encoder.setCount(1500); // set starting count value after attaching - encoder_last = 1500; } } @@ -736,13 +750,13 @@ void MenuUpdate() servo[3].writeMicroseconds(servo_pos[3]); servo[4].writeMicroseconds(servo_pos[4]); - if (encoderState == 1) + if (encoderState == 1) // Left turn { - servo_pos[selectedServo] = servo_pos[selectedServo] - SERVO_STEPS; + servo_pos[selectedServo] = servo_pos[selectedServo] - (SERVO_STEPS * encoderSpeed); // Variable encoder speed } - if (encoderState == 2) + if (encoderState == 2) // Right turn { - servo_pos[selectedServo] = servo_pos[selectedServo] + SERVO_STEPS; + servo_pos[selectedServo] = servo_pos[selectedServo] + (SERVO_STEPS * encoderSpeed); } if (servo_pos[selectedServo] > SERVO_MAX) // Servo MAX @@ -1004,6 +1018,7 @@ void MenuUpdate() display.drawString(64, 15, String(value1[2]) + " " + String(value1[3])); display.drawString(64, 30, String(value1[4]) + " " + String(value1[5])); display.drawString(64, 45, String(value1[6]) + " " + String(value1[7])); + display.drawString(5, 30, "Multiswitch"); display.display(); }