Here is my sketch…
#define BUTTON 10
void buttonISR () {
isr_fired = true;
}
void setup () {
::pinMode(LED_BUILTIN, OUTPUT);
::pinMode(BUTTON, INPUT_PULLUP);
::attachInterrupt(digitalPinToInterrupt(BUTTON), buttonISR, RISING);
}
void loop () {
if (isr_fired) {
isr_fired = false;
::digitalWrite(LED_BUILTIN, HIGH);
::delay(250);
}
::digitalWrite(LED_BUILTIN, LOW);
}
The LED flashes when I check the button with my multimeter (leg closest to the battery JST connector), however it doesn’t work when I simply press the user button (10).
FTR, I can even touch the button leg with the leg of a resistor while the other leg is in my hand to get the same effect… :o
The schematic shows the button is a short to GND when pressed, so I assume D10 should have a builtin pull-up to Vcc.
D10 ___ \____ GND
USER
FWIW, I can reproduce this behavior while the board is powered from USB, a battery via the JST, or both at the same time.
Is this a board defect, or am I doing something wrong?
Assuming you’re using Arduino UNO, I think it’s better to follow this schematic and code thoroughly.
https://www.arduino.cc/en/Tutorial/Buil … les/Button
tepalia02:
Assuming you’re using Arduino UNO…
https://www.arduino.cc/en/Tutorial/Buil … les/Button
No, I’m using the Sparkfun Artemis Plus.
Try to define the button as D10 (NOT 10) …
#define BUTTON D10
According to the schematics D10 is connected to 14. So you also try to define the button as 14:
#define BUTTON 14
Just in case, I have confirmed neither 14
nor D14
work.
I have also confirmed both 10
and D10
do work (as I originally stated).
Unless I have poorly configured the board or missed a step along the way, then the problem has to do with hardware. I’m curious if it’s MY hardware (manufacturing defect), or if it has to do with THE hardware (board layout).
For some reason the button itself does not fire the interrupt, but if I use a resistor (only in my hand, connected to nothing) to touch the leg of the button (closest to the battery JST connector) the interrupt on 10
or D10
will fire.
This is one of the few boards of which I only have one, so I don’t have a way to test it on a separate piece of hardware.
Thanks.
So it seems there is an error in the schematics where pin D10 is connected to pad 10 and not to pad 14 on the processor. (I already found it wierd).
Maybe the switch is just not pulling to GND.