0
\$\begingroup\$

I've written a very simple program for my ESP32:

void setup(void) 
{
  pinMode(21, OUTPUT);
}

void loop(void) 
{
  digitalWrite(21, HIGH);
  delayMicroseconds(500);
  digitalWrite(21, LOW);
  delayMicroseconds(10e6 - 500);
}

So pin 21 should be high for 500 microseconds, every second.

I wanted to measure the signal of pin 21, and this was my setup:

Image of simple circuit where ESP32 pin 21 is connected to oscilloscope

I added the 220 Ω resistor to be sure the pin can not "float", causing noise or false measurement. I tested it with and without resistor, but I don't measure anything. (Only the standard noise of a few mV of course)

My "oscilloscope" is a Fnirsi DSO-510. It's a cheap hobby toy, but actually quite good for the price. I tested the oscilloscope on a function generator that outputted block pulses with a length of 250 microseconds at various frequencies (1 Hz - 150Hz) and voltage levels. I just used the Auto function to get the signal nicely in view and everything worked fine.

There must be something stipid I'm missing. Why don't I see the signal on pin 21 of my ESP32 board?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Suggest you try delayMicroseconds(500); rather than delayMicroseconds(10e6 - 500); to create a 1kHz square wave output and see if that works. \$\endgroup\$ Commented Nov 16, 2024 at 21:20
  • 2
    \$\begingroup\$ This produces not one pulse every second but one pulse every 10 seconds. 10e6 is 10 million. \$\endgroup\$ Commented Nov 16, 2024 at 21:41
  • 1
    \$\begingroup\$ Also the Arduino docs (assuming that's the platform) have this comment: Currently, the largest value that will produce an accurate delay is 16383; larger values can produce an extremely short delay. This could change in future Arduino releases. For delays longer than a few thousand microseconds, you should use delay() instead. \$\endgroup\$ Commented Nov 16, 2024 at 22:15
  • 1
    \$\begingroup\$ ESP GPIO numbers do not match part pin numbers. be sure you are connecting to the correct pin. \$\endgroup\$ Commented Nov 16, 2024 at 22:16

2 Answers 2

2
\$\begingroup\$

Given limited information, and any number of possibilities, I'd guess that you don't see a signal there because there is no signal there! But let's break the problem down into simpler parts so that we don't have to troubleshoot the whole thing at once.

First of all, touch your 'scope lead to the VIN pin. You should see that on the scope. That gets us past dodgy scope, improper settings, broken probe wires, and even the ESP32 not getting power. In fact, touch the GND pin as well, because if you see 3 volts there you are missing a ground. It sounds far-fetched, but a lot of people use those prototype plug boards and they mess up on the power wiring.

Once we're past all that, work on the software. Change your program to just set the pin high. Do whatever it takes. Put the digitalWrite in the setup section and leave the loop empty. Make it as simple as possible. Also check other code examples to make sure your syntax is correct. Sometimes there is confusion between pin 21, GPIO 21, and the number you put in the output statement. In some programming environments, you have to use a constant like "GPIO_21" and its value may not even be 21.

Keep at it. I have made or seen every one of the mistakes covered here.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ What I noticed was that the pulse is very short 500 usec every second; as well as everything you've said, bad triggering will easily miss the 1 in 2000 little spike. To your debugging list I'd add: make the periods very long so you can see it with a voltmeter, then make sure you see it on your scope. Then make it the timing you actually want. Most importantly: change only one thing at a time. \$\endgroup\$ Commented Nov 16, 2024 at 21:17
  • \$\begingroup\$ Yes, troubleshooting for those of us who have done this for a long time, it comes naturally. If it isn't natural for you; buy David Agans book, Debugging. \$\endgroup\$ Commented Nov 17, 2024 at 1:53
1
\$\begingroup\$

I figured out what's the problem. When I keep my ESP32 board connected via USB after uploading the program, and measure with the oscilloscope, it works and I see the signal on the pin.

I was using a breadboard power supply (the one you just click into the power rails of the breadboard). When I unplug the USB and power the ESP32 board with 3.3V on VIN, there's no signal on the pin. Even while the power LED on the board is on, and I measure 3.4V between the VIN and GND pin (coming from the breadboard power supply).

The supply has the option to provide 3.3V or 5V to the breadboard. When I set the power supply to give 5V and thus get 5V on the VIN pin of the ESP32 board, it works and I measure the signal. I checked the internet to be sure 5V on VIN would't damage the board/chip. I actually don't understand why it doesn't work on 3.3V, since the ESP is specifically designed for this voltage, and as far as I know when it gets 5V on the VIN it makes 3.3V internally.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.