Can anybody explain why the scope trace is apparently not correct?
Assuming the sample code you provided in a reply is correct, you're using an ESP-01 ESP8266 board. And if so, did you actually read the comments in the Blink sketch?
The blue LED on the ESP-01 module is connected to GPIO1
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
In your code, you do this:
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
}
If you were to dig down to what the
Serial.begin() function does, it ultimately includes this function:
if (tx_pin == 2)
{
uart->tx_pin = 2;
pinMode(uart->tx_pin, FUNCTION_4);
}
else
{
uart->tx_pin = 1;
pinMode(uart->tx_pin, FUNCTION_0);
}
That means that the pin mode of the UART TX pin is not supposed to be
OUTPUT, but something else.
Then in the next line of your code, you take the
same pin and and do
pinMode(LED_BUILTIN, OUTPUT) to it, thus overriding its
FUNCTION_n mode and setting it back to ordinary
OUTPUT.
I'm not intimately familiar with the ESP8266, so I don't know what happens when you subsequently perform a UART write to a TX pin that's set to the wrong mode. But it wouldn't surprise me if it ended up coming out wrong.
So if in fact you're running an ESP-01 module whose LED is on the TX pin, then this might be the issue. A simple fix would be to run a
true "Hello World" that does NOTHING except the serial output.
If you must keep using the same pin for both LED output and UART, perhaps try adding
Serial.begin(115200); immediately before the
Serial.println() call, to ensure the TX pin is in the correct mode to work as UART, and then following it with
pinMode(LED_BUILTIN, OUTPUT); to set it back so the LED can blink.