digitalRead direct from 3.3V

Possibly a silly question:

I feel like I should have a resistor between 3.3V, a swtich and digitalRead(D0) but it works fine without the resistor. Am I making a mistake? Why is it OK?

Is it true for all the Photon GPIO pins that direct 3.3V can be read as an input or do some have circuit protection and some don’t?

I think it’s more accurate to say that some are 5V tolerant and some are not.

Having a resistor between the input signal and the GPIO pin would limit the current source/sink if you accidentally the wrong signal. Eg. 12v.

1 Like

@rocksetta, the Photon GPIO can read 3.3v directly, yes. However, what @kennethlimcp says is also very true.


One thing not mentioned yet (directly) is that the GPIOs when set as INPUT are Hi-Z terminals, which will virtually not draw any current, so no risk to damage the GPIO by exceeding the max current limit.
BUT, exactly that near-zero current is also the reason why a resistor in series with a voltage source exceeding the max. voltage limit will not protect you against damaging the GPIO since you won’t see “any” voltage drop across the resistor which in turn means that you will have the same (too high) voltage on both sides of your “protective” resistor still frying the GPIO.

In case of INPUT_PULLUP/INPUT_PULLDOWN you’ll see some current across the 40k pull-resistors tho’

1 Like

Thank you, makes more sense now. On the vane of silly questions: What about pin 8 and 9?

A little background:
D0-D7 maps to pins 0-7 and
A0-A7 maps to pins 10-17
RX,TX maps to pins 18-19

There is no variable D8 and D9 that map to pins 8 and 9 but you can compile

pinMode(8, OUTPUT);

Do pins 8 and 9 have a physical mapping ?

P.S. I am just trying to make a for loop that cycles through all pins. I will simply have to exclude pins 8 and 9 unless I know what they connect to.

Nope, these don’t exit in the Particle universe :wink:

The most flexible way to loop through a arbitrary set of pins is by use of a dedicated array

const int myPins[] = { A0, B2, C5, WKP, DAC, D0, BTN };
const int cntPins = sizeof(myPins) / sizeof(myPins[0]);

  for (int p = 0; p < cntPins; p++)
    pinMode(myPins[0], INPUT_PULLUP);

B2 and C5 are they just examples or actual pin numbers? The rest in your example make sense except I have never heard of BTN but it does compile and is pin number 20. What is it and is that the last one or are there a few more?

B2 and C5 are actual pins on the Electron, and BTN refers to the Reset button.

Thanks, have not yet moved to the electron universe.

Just clued in to BTN about 5 minutes before you posted as I kept on losing my wifi credentials.:slight_smile:

Actually BTN refers to the SETUP/MODE button :wink:

I usually use it as wake button for

  System.sleep(BTN, FALLING, wakeTime);
1 Like

Oops, I knew it was the Setup button, must be time for some sleep. Thanks for the correction.

Looks interesting

Any idea why doing a digitalWrite(BTN, HIGH) or was it a LOW, caused loss of Wifi Credentials and LED Blue flashing mode?

I’d assume because it triggers the same thing as holding down SETUP/MODE button (LOW) for 3+ (enter Listening Mode) or 10+ (reset WiFi creds) seconds :wink:

1 Like

This begs the question: Why does the RST pin not have a pin number?

Also, if we wanted to push the Mode and Reset buttons at the same time would we have to physically connect the reset pin to a digital write and set it high while activating SETUP/MODE button?

Because it’s not a GPIO but only a hardwired reset pin.

If you want to achieve what the reset pin does, just call System.reset(), why use a GPIO to set a signal outside of the device to loop it back into the device?
That would be like sending yourself a mail to check your inbox :wink:

1 Like

@ScruffR, the only value of external hard reset is that it also hard resets all other devices (wifi/GSM). Software reset doesn’t quite have the same effect.

Hmm, while the actual use for the RESET pin is clear to me and doesn’t exactly apply to the asked question of how to “simulate” a RESET/SETUP combo, I’m not convinced the reset actually also affects the GSM module (keep alive and network connection survive a button reset too).

1 Like

With reference to the electron schematic design, reset line of Ublox module is wired to the STM32 via GPIO pin PC4.

1 Like