Skip to content

[Bug]: Attenuator (esp32) vibration stops working #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
Shoop64 opened this issue Sep 17, 2024 · 18 comments · Fixed by #381
Closed
1 task done

[Bug]: Attenuator (esp32) vibration stops working #387

Shoop64 opened this issue Sep 17, 2024 · 18 comments · Fixed by #381
Assignees
Labels
bug Something isn't working

Comments

@Shoop64
Copy link

Shoop64 commented Sep 17, 2024

What actions were attempted?

Once a tone is played on the buzzer, the vibration seems to stop working.

I made several changes to the code and finally got to the point where I can get both the buzzer to work and vibration to work, although I'm not sure it matches the intended functionality.

The changes I made were using ledcAttach for the buzzer pin and a simple pinmode output for the vibration pin. Then you can use ledcWriteTone(BUZZER_PIN, i_freq) to play a tone(or a freq to 0 to stop it) and then vibration I just use digitalWrite with HIGH and LOW.

What actually happened?

I've been trying to build the circuit on a breadboard and was confused about why I couldn't seem to get the vibration to work. Eventually I worked out that it will no longer work after a tone has been played. I'm not sure why.

What was expected?

The vibration should continue to function independent of the buzzer function.

Firmware Version

20240823180629 build date

Mode in Use

Any / Both Modes

Notable Hardware

I think I'm mainly using what it in the BOM for the diy attenuator.

Homework Completed

  • I did my part!
@Shoop64 Shoop64 added the bug Something isn't working label Sep 17, 2024
@nomakewan
Copy link
Collaborator

Are you on an ESP32 or Arduino Nano?

@Shoop64
Copy link
Author

Shoop64 commented Sep 17, 2024

ESP32

@nomakewan
Copy link
Collaborator

Well what a coincidence, I'm neck-deep in ESP32 code right now trying to beef up the serial data sync. I'll go ahead and add this to my plate and see if I can pinpoint the cause so we can add it to the list of fixes for 5.3.4.

@nomakewan nomakewan self-assigned this Sep 17, 2024
@nomakewan
Copy link
Collaborator

nomakewan commented Sep 17, 2024

Okay, found the problem. The problem is that the tone library actually uses ledc internally, and so its internal declarations were un-setting the ledc definition for the vibration motor that had been initialized in setup.

Now that I know how tone works I'll go ahead and get this fixed so that both the buzzer and vibration motor will work as intended. :) Thank you for the report!

EDIT: Additionally, there appears to be a bug in the Tone library which could also be related, since it has to do with defining which channel the specified tone should be using: espressif/arduino-esp32#10305

The fix was merged, but a new release hasn't been spun yet.

nomakewan added a commit that referenced this issue Sep 18, 2024
Improved Attenuator pack sync speed and reliability, reduced variable count on Nano, fixed incorrect PWM port on wand vibration motor, added new serial com definitions, and specified channel for ESP32 vibration motor so buzzer does not overlap which resolves #387
@nomakewan
Copy link
Collaborator

nomakewan commented Sep 18, 2024

Okay, we have a push that should resolve it for 5.3.4. The correct way to resolve this issue would be to wait for the next stable release of ESP32 (should be 3.1.0), then use the proper channel setting for Tone. However, considering we have no clue when that will be, I've included a workaround that should work in the meantime.

You can actually test it yourself; grab the Attenuator code from the main branch (5.3.3, which is build date 20240823180629), then change ledcAttach(VIBRATION_PIN, 5000, 8); on line 158 of Attenuator.ino to ledcAttachChannel(VIBRATION_PIN, 5000, 8, 5);. Then replace pinMode(BUZZER_PIN, OUTPUT); on line 155 with ledcAttachChannel(BUZZER_PIN, 440, 10, 0);.

That should allow both the buzzer and vibration motor to work normally (since we are now initializing ledc on the buzzer using channel 0, and ledc on the vibration motor using channel 5).

@Shoop64
Copy link
Author

Shoop64 commented Sep 18, 2024

Excellent, that makes sense to me. Thanks!

@Shoop64
Copy link
Author

Shoop64 commented Sep 18, 2024

I tested out the change and I lose the buzzer doing the change on line 155. Leaving it as pinMode(BUZZER_PIN, OUTPUT); but changing the vibration pin to ledcAttachChannel got both working.

@nomakewan
Copy link
Collaborator

nomakewan commented Sep 18, 2024

Interesting; I wonder why enforcing channel 0 on the buzzer caused a failure. Perhaps some undocumented feature of the auto-channel? Argh.

Either way, will go ahead and put the pinMode back where it was (with a note that once ESP32 3.1.0 is out we can fix this one far more reliably). Thank you for testing!

EDIT: ESP32 3.0.5 was released and included the fix for the Tone library. That said, the shift to the PlatformIO development environment for the Attenuator has regressed ESP32 to 2.0.17 (for now), so hopefully this problem will remain resolved.

@nomakewan nomakewan linked a pull request Sep 24, 2024 that will close this issue
@DustinGrau DustinGrau mentioned this issue Oct 7, 2024
DustinGrau added a commit that referenced this issue Oct 8, 2024
* Code cleanup

This cleans up a lot of unused variables from the codebase, corrects the documentation on the inner cyclotron LED ring, and fixes a bug where the wand would not play the correct voice clip when changing between static and dynamic inner cyclotron LED panel modes.

* Implement Halloween holiday mode

When wand is in Holiday firing mode, user can now press the barrel wing button to switch between Halloween and Christmas modes, which are fully supported on the wand, pack, and attenuator. Resolves #368

* Fix barrel tip fade effect

This fixes the speed of the barrel tip colour transition in Holiday mode, and fixes the speed of the barrel tip colour transition in Spectral mode with the Frutto barrel

* Fix TVG idle sounds on standalone wand

TVG idle sounds are perfect for the pack, but when played on the wand they were overpowered by the wand's idle hum.

* Update inner cyclotron LED panel

This updates the inner cyclotron LED panel so that the mode indicators for vibration and year remain off if the brass pack effect is running and updates the documentation and web UI to make it clearer how the three available modes for the inner cyclotron LED panel work which resolves #370

* Add barrel retract sound, fix FE sounds

Resolves #373 by adding a barrel retraction sound effect, adds a new unique pack idle loop for Frozen Empire mode, and fixes several FE-related audio calls.

* Fix loops, fix variable warning

This reduces the filesize for the large looped sounds by 95.7%, saving over 600 MB while maintaining or improving sound quality. It also corrects the idle slime and stasis loops not fading in correctly on a standalone wand, and fixes an unused variable warning on the Attenuator.

* Minor cleanup/alignment

* removed gpstar audio serial library

* Fix compilation for blaster/pack/wand

Adds git link for the GPStar Audio library to the build tests.

* Reduce RAM footprint for serial on pack/blaster

Reduces RAM footprint of serial print commands by using flash instead of RAM, and sets the debug-only serial data plotter for the pack to a constant so it will not be compiled by default as this option cannot be dynamically enabled anyway.

* remove hardwareserial library reference

* Adjust power meter calls, update audio code

This updates some of the calls for the power meter's initialization, cleans up a variable declaration in the power meter code, and updates the binaries to use the new GPStar Audio code.

* Sound loop fadein fixes

This corrects some awkward fades which were due to the difference between linear and logarithmic fades between tracks.

* Adjust firing start/loop/end

Now that we know that the WAV Trigger is using logarithmic fades between tracks, we can actually make all of the firing sounds sound good. Now all year modes, all power levels, both Intensify and Alt have proper start/loop/end with proper fades.

* 30 segment bargraph mapping

* 30 segment bargraph

* spelling fix

* Refactor single-shot to prepare for VSCode

* Fix bargraph check, pack VG sound mix

Fixes the correction factor for the 28-segment bargraph to be 2 (30 - 2) when checking less than in a conditional, and updates the sound fade values for switching between video game modes on the pack to match the values tested on the standalone wand.

* neturona wand led status indicator

* Fix MODE ORIGINAL menu, fire tail mix, pack docs

Fixed the switch check in wandExitMenu() to both resolve #375 and fix an error where wands without a Frutto bargraph were not playing the bootup sound, fixed stereo separation of the mid fire tail effects for 1984 and Afterlife as they were only playing in the right channel which was not coming through on the wand speaker properly, and fixes the DIY Pack documentation to both include a higher resolution PCB photo and correct the mode switch functionality description.

* Static barrel LED support for blaster

This change allows the BARREL LED pin to be pulsed when firing the single shot blaster, which resolves #372

* Fix 28-segment bargraph overheat, add holiday sfx

This fixes the top two segments of the Frutto 28-segment bargraph becoming stuck if the "blink bargraph while overheating" setting is disabled which resolves #376 and both adds some sound effects for switching between holiday stream modes and updates colour transitions for those modes to improve perceptibility which finally resolves #368

* Add POST for inner cyclotron panel

This adds a POST effect for the inner cyclotron switch panel LEDs, fixes an oversight with non-addressable switch panel LEDs not being turned fully off if cyclotron lid is on in certain edge cases, and simplifies an "off" call for the inner cyclotron cake.

* Remove button mash logic from single-shot

* invert powercell animation option

* haslab 1984 power cell holder

* Refactor pack ramps

This changes the fade ramps for the Afterlife outer cyclotron effect to use uint8_t which saves 240 bytes, and updates the names of variables so that they make more sense in context. It also removes some unused references to old stock wand check code.

* Update POST sequencing

This change allows the pack to tell a wand attempting to synchronize during the power on self test sequence that it is performing a POST and so should not allow the user to access normal wand functions until it is complete. This prevents, for example, someone entering the EEPROM menu before the POST sequence has been completed. It also prevents switches on the pack from having an effect until the POST sequence completes for the same reason.

* FastLED 3.7.6 Update

Updates the compile test to use latest instead of forcing FastLED 3.7.4, updates all binaries to use FastLED 3.7.6.

* Implement POST for inner cyclotron

Implements a POST animation for the inner cyclotron ring.

* Power Cell invert menu option. Updated documentation.

* 1984 power cell frame for spirit packs

* Update single-shot to use GPStar LED jewels

* Update SINGLESHOT.md

* Change product link/photo

* Add power cell invert to web interface

This adds the ability to invert the power cell animation to the wifi/attenuator web interface.

* barrel 49, use all leds in EEPROM lighting menu.

* Update 49 barrel fix for EEPROM LED menu

Updates menu to not overrun when using a Hasbro barrel but still turn on/off the tip of the Frutto 48-LED barrel.

* Update SINGLESHOT.md

* Change slime blower Powercell to match GB2

Changes the RGB powercell's default colour so that rather than match the cyclotron, it instead matches the yellow powercell of the GB2 slime blower.

* updated power cell holder

* Implement new EEPROM save for attenuator web UI

* Update blaster barrel to use all 7 LEDs

* Update flashing docs

* Update POWER.md

* Update POWER.md

* Add new ring sim

This adds new outer cyclotron ring simulation code that is based on actual distance between lenses rather than a delay, which both improves the visuals of the ring when at low speed and greatly simplifies the pack code.

* SFX, web interface updates

Adds new sound effects from ProtonCharging for meson mode switch, wand mash error, and boson dart with impact sound; fixes bug in web interface where shutting off pack while venting will cause vent button to stop working; makes it so it is not even possible to click the "Update Settings" buttons in the web interface if the pack and/or wand are on.

* bargraph installation documentation update

* bargraph documentation update

* bargraph documentation update

* Adjust UI button disabling

* Update models for Spirit pack

* motorised cyclotron sound selection

* Vibration refactor, cyclotron motor

This completely refactors how vibration works in all devices by switching from discrete bools to enums, and adds the ability to use a motorized inner or outer cyclotron relay in place of the vibration motor on the pack which resolves #380

* Make cyclotron motor obey switch state

Updates the calls that enable the motorized cyclotron to obey the state of the vibration switch.

* Audio-related updates

This updates the web interface to replace "0%" volume with "Min" since you cannot actually achieve 0% volume, fixes an issue where pause/resume did not work correctly, fixes an issue where incorrect magic values were being used on the wand to set several sound effect volume levels, adjusts the powercell loop sound to be quieter, updates the volume of the GB2 and Frozen Empire pack idle sounds to better match their respective startups, and fixes an issue where adjusting sound effect volume on the fly was not taking effect due to missing or incorrect definitions which resolves #382

* Fix missing battery voltage in web UI

This fixes the missing battery voltage in the text-based web UI.

* Fix pack TVG loop volume

Fixes invalid magic numbers being used for the TVG idle loops' volume on the pack.

* Fixing attenuator issues

* Correct ESP32 NVS key error

This corrects ESP32 non-volatile storage key names that were over the 15 character limit, which resolves #385

* Add GBFE long startup

Adds an ion arm switch long startup for Frozen Empire mode.

* Adding more API's

Attempting to add some more API's into the Attenuator: loop music track, manual start/cancel of lockout (button mash) sequence. All needs testing!

* Hiding UI elements until we can work through some additional fixes for APIs

* Fix ring sim, fix web UI

Fixes ring sim code for LED arrays smaller than 36 and situations where ring simulation is disabled, fixes issue with web UI that was causing the UI to fail to update on certain browsers

* Fix JS checks

* Prevent manual vent while firing, update SFX

Prevents use of the manual vent button on the web UI if the wand is currently firing to get around an edge case where proton stream impact sounds will continue playing, and updates 84 low power short tail and Afterlife startup/idle sounds to improve audio quality.

* Fix FE button mash freeze effect

Corrects the freeze effect so that it runs a little bit better, and adds a few missing sound calls for 1984 mode.

* Move Attenuator sync to single packet

This significantly improves initial data sync speed between the pack and attenuator by condensing all the individual serial data messages into a single serial data packet, just like on the wand.

* Remove unused struct

* Attenuator, serial data fixes

Improved Attenuator pack sync speed and reliability, reduced variable count on Nano, fixed incorrect PWM port on wand vibration motor, added new serial com definitions, and specified channel for ESP32 vibration motor so buzzer does not overlap which resolves #387

* Fix ESP32 buzzer, current song call

Fixes ESP32 buzzer failing to initialize, cleans up some unnecessary serial calls when playing or stopping music, and fixes a bug where the current music track was not being transmitted to the attenuator if music was not being played

* Streamline firing calls

This condenses the two serial data calls for firing into a single call.

* Minor formatting changes, part of splitting code to Nano vs. ESP

Restored a delay which was needed to the wifi disconnect. These are blocking but required for the action required.

* Add pack voltage to sync packet

This adds the current pack voltage to the synchronization packet for the Attenuator, which allows the full web UI to be updated right when the initial synchronization happens.

* 28 and 30 segment bargraph voice prompts

* Enable 30-segment bargraph support

This adds the ability to switch between 28-segment and 30-segment optional bargraphs to both the wand menu and the web UI.

* Adjust doc spacing

Adjusts spacing rules in EEPROM LED menu descriptions.

* Update overheat defaults, startup fix

Updates the default values for the smoke and overheat variables related to the pack config packet to match the actual defaults found in the codebase, and fixes a missing ms_idle_fire_fade call for the brass pack that in certain edge cases could have resulted in an incorrect LED startup ramp value.

* Resolve unused vars for Attenuator w/ Nano

* Rebuild binaries with latest libraries

* Split attenuator code by MCU type

* Update compile-test.yml

* Wand vibration, bargraph fixes

Fixes wand vibration PWM prescaler value, fixes 30-segment bargraph animations, adjusts code for settings menu animations.

* documentation update

* Update AttenuatorNano.ino

* Remove items not applicable to Nano

* Add LED to Nano, lower RAM use

Adds sync feedback for the built-in LED on the Arduino Nano, and shifts the bargraph arrays into PROGMEM to lower RAM use as much as possible.

* Clean up Nano code, sync changes to ESP where needed

* Nano updates, revert AL sounds

Adds LED pin output definition back into Nano, removes unused Debug function from Nano, and reverts the Afterlife Startup/Idle sounds back to the 5.3.3 version.

* Refactor the Attenuator code to use VSCode with PlatformIO

This was an inevitable change based on the future work, but was forced to be done soon as we can use distinct versions of libraries for builds using this approach. The older Nano build may need to stay locked to the FastLED v3.6.0 library in order to run correctly, so this move allows for that to be accomplished.

* Adjust build parameters file

* Update platformio.ini

* Revert button press detection for Attenuator

* Ion arm switch, rotary switch fixes

Simplifies ion arm switch serial data message names, simplifies ion arm switch code on the pack which also fixes a bug where ion arm switch status was incorrectly defined when new pack configuration was received via serial, moves all ion-arm-switch-related code on the wand into a dedicated function, and fixes the simplified rotary encoder switch code for the Attenuator.

* Fix Mode Original wand vibration

Fixes the wand vibration so that in Mode Original, vibration can only start once the pack has started.

* Fix broken vibration/tone on ESP32

VIBRATION_PIN was defined as 19 on ESP32, which is greater than the maximum number of LEDC channels on the ESP32 (8). This moves the vibration motor to channel 5. Additionally, it forces Tone onto Channel 0 to prevent overlapping with the vibration channel, which is supported on both ESP32 2.0.17 and 3.0.5.

* Adjust the PlatformIO libraries

* Revert a change for ESP32

* Correct libraries for ESP32, rebuild binaries

* Increase single shot upload speed

* Revert Nano to only use 2 LEDs

* Restore encoder button behavior

* Add 84 fade to web UI, audio overhaul

This adds the ability to enable/disable the fade effect for the 1984/1989 cyclotron sequence via the web UI, and fixes several issues with the internal audio headers including improper volume control, lack of volume sync when receiving sync packets from the ESP32, and insufficient range in EEPROM values.

* Update Cyclotron/Powercell defaults

This updates the default powercell and outer cyclotron LEDs to be the Frutto update parts if there is not already a specific setting in the EEPROM and a stock wand is not being used.

* Rebuild binaries

* Fix EEPROM volume calculation

Fixes order-of-operations error when calculating the EEPROM master volume percentage which was causing the result to always be 0. Also corrects the default value for default system volume on the ESP32 to be 100 as intended.

* Ion arm, misc fixes

Fixes ion arm operation so that turning it off will not run the shutdown sequence if the pack is not on, changes Attenuator left toggle switch to be a secondary ion arm switch which fixes a bug in Mode Original where the Attenuator could turn the pack on while the ion arm switch was off, cleans up some variables between the Attenuator and pack, and fixes issue where web UI was not displaying two significant figures for pack voltage if the digits were 0.

* Fix Lite pack startup bug

Fixes issue where a GPStar Lite kit will not be able to start up from the ion arm switch or wifi module if the wand is not on.

* Remove RIFF tag

Removes stray RIFF metadata tag in one of the new sound files.

* Fixes for ESP32, freeze libraries for builds, fix power meter

* Audio subsystem overhaul

This updates the audio subsystem in all devices to properly calculate track volume (which should always be -70 to 0) and master volume (which changes depending on device and which sound board is in use). It also cleans up some of the audio-related code making it more concise and readable. It also unifies the wand mute request into a single function.

* Typo fix

* Fix Lite wand shutdown

This fixes the GPStar Lite code so that if the pack is started from the ion arm switch then a Hasbro wand is connected, the Hasbro wand can still then power down the pack.

* Audio updates

WAV Trigger only has digital amplification, so capping it at 0dB. GPStar Audio has distortion above about +12dB using Visaton speaker so capping at +12dB for now. Also cleaned up some legacy unnecessary code.

* Update web UI to offer a restart confirmation for certain actions

* Add expected firmware change for GPStar Audio

* Fix AL/FE wand ramp sound mix

Fixes issue that was causing the second ramp sound to always fade in rather than mix smoothly.

* Merge changes for web UI

* Fix AL/FE short startup, fix typos

Fixes the outer cyclotron ramp up speed for the Afterlife/Frozen Empire short startup to better match the audio, and corrects the spelling of "WAV Trigger" in SOUND.md.

* Update ATTENUATOR_FLASHING.md

* Move loose wav files into new pack-wand folder

* New readme files for subdirs

* Update to use new Arduino library for audio serial

* Audio call updates

Updates audio calls to match the new 1.1.x call structure and move away from deprecated functions.

* Align for later changes to singleshot

* Change blaster vibration default

* Add default to inner panel check

Shouldn't technically be necessary, but good practice to have a default case in a switch.

* updated 1984 power cell holder

* Adjust debug msgs, add terminal time output, add timers for ESP32

* GPStar Audio flasher for Windows x64

Adds a utility to flash firmware to the GPStar Audio boards from 64-bit Windows hosts, and updates the documentation.

* cyclotron fading voice prompts

* Add cyclotron fade to EEPROM menu

Adds the ability to toggle the fade effect for the 84/89 outer cyclotron to the wand EEPROM LED menu, renames Mac version of GPStar Audio flasher to match pattern used for main flasher.

* Update debug messages, turn off websocket debugs

* Update docs

This updates the Advanced Configuration document and troubleshooting document to match latest firmware changes. It also fixes an unnecessarily large datatype on the pack, unifies horizontal resolution for web UI screenshots, and adds in the missing LICENSE file to correct the boilerplate License on the repo.

* Remove redundant license

* Add motorised cyclotron docs

* Update install, bargraph docs

Updates installation guide video URL, FAQ page, as well as several references to bargraphs to add reference to the new 30-segment bargraph coming soon.

* Update README.md

* More docs updates

Updates more bits of documentation to clean up errors and include proper references for new options.

* Utilize bool return from Preferences.begin for ESP32

Ensures the namespace can be opened before attempting to assign preference values from name-value pairs contained within.

* Fix datatype in ESP32 debug messages

ESPAsyncWebServer defines the client ID as uint32_t (see AsyncWebSocket.h) so the correct typedef in serial.printf would be %lu for unsigned long int.

* Add new JS page, rebuild binaries

* Implement task scheduler pattern for ESP32

* Implement common JS functions for UI

* Delete GPStarAudio_V102.hex

* Reduce SVG size, add performance stats for debugging

* Fix power meter glitch, restore slime colors

---------

Co-authored-by: nomakewan <[email protected]>
Co-authored-by: Michael Rajotte <[email protected]>
@Shoop64
Copy link
Author

Shoop64 commented Nov 1, 2024

This bug appears to be back in the latest code. It took me a while to get vscode/platformio set up so I could build and test against my attenuator, but it appears back. Changing to code to use digitalWrite to set high or low and declaring it with pinmode output instead got it working.

@DustinGrau
Copy link
Collaborator

So was this on the 5.4 or 6.0 code? I saw the note about the ESP library change so I'm curious/confused as to whether that's the culprit, and to which release this fix belongs?

@Shoop64
Copy link
Author

Shoop64 commented Nov 1, 2024

I'm working off the 5.4.2 source.

@nomakewan
Copy link
Collaborator

Try the 6.0.Preview source instead and see if that resolves the issue. It uses a different ESP32 core and a newer LEDC command.

@Shoop64
Copy link
Author

Shoop64 commented Nov 1, 2024

I'll give that a shot and get back to you.

@Shoop64
Copy link
Author

Shoop64 commented Nov 1, 2024

Yeah, appears fixed in the 6.0 preview.

@nomakewan
Copy link
Collaborator

Excellent. Then for 5.4.3 we'll make sure to backport those changes. Guess it was a bug in the 2.0.17 core, where despite having an explicit command to override the LEDC channel, it does it anyway.

Thanks for testing!

@Shoop64
Copy link
Author

Shoop64 commented Nov 1, 2024

Yeah, glad to help.

@DustinGrau
Copy link
Collaborator

Just to catch up, are we saying the latest ESP library provides a fix automatically, but we need a more explicit change for the 5.4 code?

@nomakewan
Copy link
Collaborator

The fix for this is to use the 3.0 core with the single ledcAttachChannel(VIBRATION_PIN, 5000, 8, 5); command to setup ledc for the vibration pin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants