I have interrupts attached to pins 4 and 5 which correspond to the left and right inbuilt buttons on the circuit playground express (https://learn.adafruit.com/adafruit-circuit-playground-express/pinouts). For some reason the right button interrupt works perfectly however the left interrupt doesn't even trigger. Here's the code:

#include <Adafruit_Circuit_Playground.h>
#include <Adafruit_CircuitPlayground.h>

volatile bool leftState = false, rightState = false;

void left()
    if (CircuitPlayground.leftButton())
        leftState = !leftState;

void right()
    if (CircuitPlayground.rightButton())
        rightState = !rightState;

void setup()

    attachInterrupt(digitalPinToInterrupt(4), left, CHANGE);
    attachInterrupt(digitalPinToInterrupt(5), right, CHANGE);

void loop()

Pin 4 on Zero can't be used with attachInterrupt. It is pin PA08 of the SAMD21 and this has NMI as interrupt control function in EIC and can't be used as EXTINT.

Adafruit Circuit Playground maps PA28 to pin 4, but the description of the pin is left as for Zero and doesn't declare interrupt capability.

In file arduino/hardware/samd/1.6.21/variants/circuitplay/variant.cpp change the line for pin 4 to

  { PORTA, 28, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_8  },                           // GPIO D4 / Left Button

Packages are located in ~/.arduino15/packages/ on Linux and %userprofile%\AppData\Local\Arduino15\packages\ on Windows (AppData is a hidden folder).

Warning: In variant.cpp the overview comment's table describes Zero, not Circuit Playground.

Note: It is not beneficial to read a button with interrupt. You can only set some flag in interrupt and then handle it in the loop(). But then you can directlly check in loop the state of the pin, because it will be active many loops even if the user pushes it for a short time.

| improve this answer | |
  • I have a lot of delays in my main loop (the code I posted is simplified to isolate the issue), so the button inputs wouldn't register. To be clear, what value should I put as the first parameter when I attach the interrupt for the left button? – James A May 25 '19 at 7:06
  • wait, so the pinout for the playground express states that button a is an interrupt pin but you can't actually use it as an interrupt pin? – James A May 25 '19 at 7:16
  • pinout where? I checked the variant.cpp for this board in Arduino SAMD boards package – Juraj May 25 '19 at 7:21
  • cdn-learn.adafruit.com/assets/assets/000/049/780/original/… Button A is labelled as an interrupt – James A May 25 '19 at 7:23
  • the description in variant.cpp doesn't match the true mapping used. I rewrite the answer. you will need to patch variant.cpp – Juraj May 25 '19 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.