Strange one here.
I have a Photon with a reed switch on D2 & GND - when I digitalRead it’s perfectly fine. I open and close the switch no problems at the digitalRead changed from HIGH to LOW and back again as expected on each time I press the reed switch.
When I place my Photon on the Shield Shield, it does a digitalRead fine, but on the FIRST closing of the switch the digitalRead change from HIGH to LOW, but when I release the reed switch it does not return to HIGH - i.e. it sticks!
int REEDSWITCH = D2;
Is there something odd about the Shield Shield that makes the Photon behave in this manner?
The shield shield is a bidirectional level shifter and it has to guess which way the data is flowing to do its thing. I believe you have to use an external pull-up resistor, located on the reed switch side of the shield shield, for this to work properly.
Hmm. I think I have tried this. Now using a conventional push button (in case my reedswitch was faulty).
D2 > resistor (one that I used with an LED) > PushButtonSwitch > GND
Still the same! Unsure if need a certain value of resistor.
As you can tell, I am a newbie on this - but loving it!
Normally you’d use a 4.7K or 10K resistor, hooked up like this. The switch connects to ground, and the resistor connects to 3V3. Actually, since you’re using the shield shield, 5V not 3V3.
FWIW, the documentation does state that if you’re using the pin in 5 VDC fault tolerant mode, which I believe is the case with the shield shield due to Arduino compatibility, you need to disable the internal pull-up resistors. So, use INPUT instead of INPUT_PULLUP. I guess if I were ever using an external pull-up or pull-down, I would disable the internal resistor.
That’s a good advice in general
Only in this case with the Shield Shield the pins should only see 3.3V as the shield does the level shifting in both directions.
But the point being here might be that the internal pull-up does make the level shifter see HIGH in turn telling him to push 5V which might actually pose a problem when you close the switch to GND.
So in the end
INPUT is still the way to go, just due to different reason.
Thanks all - this is all quite moot now as I tried to do the wiring as described, obviously done something wrong and now I seem to have a little paper weight!
Constantly flashing cyan quickly, then a cycle of VERY quick colours, then cyan flashing quickly. Rinse, Repeat.
dtu-util will latest firmware and still nothing.
Have I fried me little Photon?!
Back online after resetting the certs (after 4 hours!)
Using INPUT not INPUT_PULLUP any more. Using a 4.7K resistor.
So, every time I press the switch, the photon resets/trips… I am unsure if I am doing your diagram correct…
Does the pin to D2 simple comes in the shape of a T off the “circuit” of the 3V3 > resistor > GND ?
The circuit as drawn by @rickkas7 shows 3v3>resistor>switch>GND. You then tie in between the resistor and the switch with your wire to your input (D2 in your case). When the switch is open, there’s no current through the resistor (hence, no voltage drop) and your input will see 3V3 volts (“ON”). When the switch closes, the input is effectively connected to ground (“OFF”). The resistor merely limits current in the “OFF” state while providing a path to 3V3 volts in the “ON” state.
I tend to prefer using pull down resistors, but I believe this is merely dealer’s choice.
SOLVED! I have taken @rikkas7 drawing and took a look on google and found something similar in an image that a simpleton newbie like me could follow!
I really do need to get to know the basics before playing with these Photons!
THANK YOU ALL!
Thanks @brixo and @rickkas7 that’s what I’m doing now for my switches. I just have 1 simple question. With this set up for the
pinMode do you need to specify
INPUT_PULLDOWN still? Or is simply just
INPUT all you need as you have the external resistor?
If you have an external pull-resistor you can/should use INPUT without internal resistors.