wiki-documents
wiki-documents copied to clipboard
ESP32C3 - Any PWM output creates serial port interference.
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.
Thanks for the information here! I really appreciated!
@MatthewJeffson - Any ideas on how I can handle this?
@MatthewJeffson - Any help on this?
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?
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...