Skip to content
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

ESP32C3 - Any PWM output creates serial port interference. #977

Open
andrewpriddis opened this issue Feb 25, 2024 · 5 comments
Open

ESP32C3 - Any PWM output creates serial port interference. #977

andrewpriddis opened this issue Feb 25, 2024 · 5 comments
Labels
Tech Support The product issues that need help

Comments

@andrewpriddis
Copy link

andrewpriddis commented Feb 25, 2024

I have a simple piece of code that reads a pin and writes the state to a serial port (USB) every 500 milliseconds. If the pin is HIGH then a pwm signal is wrttien to the tonePin with a duty cycle of 128. Either 00 or FF should be written out the port. This works great unless I add the analogWirte function to the code. If I do then that serial data becomes garbage. See code below and then serial output examples below that.

    if ((millis() - writePauseTimer) > 500)
    {
        if (digitalRead(inputPin))
        {
            pauseState = 0xff;
            analogWrite(tonePin, 128);
        }
        else
        {
            pauseState = 0;
        }
        Serial.write(pauseState);
        writePauseTimer = millis();
    }

This is the garbage written out the serial port when the button is pushed. It appears that the PWM timer is messing with the serial port.
image

@MatthewJeffson
Copy link
Collaborator

Thanks for the information here! I really appreciated!

@MatthewJeffson MatthewJeffson added the Tech Support The product issues that need help label Feb 25, 2024
@andrewpriddis
Copy link
Author

@MatthewJeffson - Any ideas on how I can handle this?

@andrewpriddis
Copy link
Author

@MatthewJeffson - Any help on this?

@grilliiiii
Copy link
Collaborator

Hi andrewpriddis
I've tried adding the serial print code to our PWM demo, and the serial monitor is outputting the print information correctly. Perhaps you could double-check the rest of your code to see if something is causing the confusion?

image

image

@andrewpriddis
Copy link
Author

Ok, I put the serial monitor into text mode and now I see what all the garbage is.... all the extra text coming over the port. How do I shut that off? I was viewing as Hex expecting to only see 1s and 0s like your example...
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tech Support The product issues that need help
Projects
None yet
Development

No branches or pull requests

3 participants