I’m trying to find out what pins on the Argon I can use as Interrupt pins?
The attachInterrupt() documentation lists the pins for Electron, Photon and Spark Core, but no mesh hardware is listed yet.
I’m sure it’s listed somewhere, but I just can’t seem to find it.
1 Like
All pins on the mesh devices can be used for interrupts. I’ll update that page on Monday.
Just to be sure I wrote this test program. You connect a pair of pins and it tests INPUT, INPUT_PULLUP, and INPUT_PULLDOWN. Then for interrupt handlers, it tests RISING, FALLING, and CHANGE. And also those using INPUT_PULLUP with the pin only driven low or let float.
All of the tests passed on an Argon with 0.8.0-rc.25.
#include "Particle.h"
//SerialLogHandler logHandler;
SYSTEM_THREAD(ENABLED);
enum State {
START_WAIT,
START_TEST,
WAIT_CONNECTED,
RUN_TEST
};
State state = START_WAIT;
unsigned long stateTime = 0;
int testNum = 0;
int fromPin;
int toPin;
bool interruptCalled;
int interruptValue;
String pinToName(int pin) {
String result;
if (pin >= D14) {
// #define A0 D19
// #define A1 D18
// #define A2 D17
// #define A3 D16
// #define A4 D15
// #define A5 D14
result = String::format("A%d", 5 - (pin - 14));
}
else {
result = String::format("D%d", pin);
}
return result;
}
void startTest(int _fromPin, int _toPin) {
fromPin = _fromPin;
toPin = _toPin;
Serial.printlnf("running test %d: connect %s to %s", testNum, pinToName(fromPin).c_str(), pinToName(toPin).c_str());
pinMode(fromPin, OUTPUT);
pinMode(toPin, INPUT_PULLUP);
digitalWrite(fromPin, LOW);
}
void interruptHandler() {
interruptCalled = true;
interruptValue = pinReadFast(toPin);
}
void setup() {
Serial.begin();
}
void loop() {
switch(state) {
case START_WAIT:
if (millis() - stateTime >= 6000) {
testNum = 1;
state = START_TEST;
}
break;
case START_TEST:
if (testNum > 20) {
Serial.println("tests completed!");
testNum = 0;
state = START_WAIT;
stateTime = millis();
break;
}
if (testNum <= 19) {
startTest(D0, testNum);
}
else {
startTest(D19, D0);
}
state = WAIT_CONNECTED;
break;
case WAIT_CONNECTED:
if (digitalRead(toPin) == LOW) {
state = RUN_TEST;
delay(1000);
}
break;
case RUN_TEST:
digitalWrite(fromPin, HIGH);
if (digitalRead(toPin) != HIGH) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=1", testNum, pinToName(toPin).c_str());
}
pinMode(fromPin, INPUT);
if (digitalRead(toPin) != HIGH) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=2", testNum, pinToName(toPin).c_str());
}
pinMode(toPin, INPUT_PULLDOWN);
if (digitalRead(toPin) != LOW) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=3", testNum, pinToName(toPin).c_str());
}
pinMode(toPin, INPUT);
interruptCalled = false;
attachInterrupt(toPin, interruptHandler, FALLING);
delay(2);
if (interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=4", testNum, pinToName(toPin).c_str());
}
pinMode(fromPin, OUTPUT);
digitalWrite(fromPin, LOW);
delay(2);
if (!interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=5", testNum, pinToName(toPin).c_str());
}
if (interruptValue != LOW) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=6", testNum, pinToName(toPin).c_str());
}
digitalWrite(fromPin, HIGH);
interruptCalled = false;
attachInterrupt(toPin, interruptHandler, RISING);
delay(2);
if (interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=7", testNum, pinToName(toPin).c_str());
}
digitalWrite(fromPin, LOW);
delay(2);
if (interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=8", testNum, pinToName(toPin).c_str());
}
pinMode(fromPin, OUTPUT);
digitalWrite(fromPin, HIGH);
delay(2);
if (!interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=9", testNum, pinToName(toPin).c_str());
}
if (interruptValue != HIGH) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=10", testNum, pinToName(toPin).c_str());
}
interruptCalled = false;
attachInterrupt(toPin, interruptHandler, CHANGE);
delay(2);
if (interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=11", testNum, pinToName(toPin).c_str());
}
digitalWrite(fromPin, LOW);
delay(2);
if (!interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=12", testNum, pinToName(toPin).c_str());
}
if (interruptValue != LOW) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=13", testNum, pinToName(toPin).c_str());
}
digitalWrite(fromPin, HIGH);
delay(2);
if (!interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=14", testNum, pinToName(toPin).c_str());
}
if (interruptValue != HIGH) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=15", testNum, pinToName(toPin).c_str());
}
pinMode(toPin, INPUT_PULLUP);
interruptCalled = false;
attachInterrupt(toPin, interruptHandler, FALLING);
delay(2);
if (interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=16", testNum, pinToName(toPin).c_str());
}
pinMode(fromPin, OUTPUT);
digitalWrite(fromPin, LOW);
delay(2);
if (!interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=17", testNum, pinToName(toPin).c_str());
}
if (interruptValue != LOW) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=18", testNum, pinToName(toPin).c_str());
}
// High-Z uses the input pull-up
pinMode(fromPin, INPUT);
interruptCalled = false;
delay(2);
if (interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=19", testNum, pinToName(toPin).c_str());
}
interruptCalled = false;
attachInterrupt(toPin, interruptHandler, RISING);
delay(2);
if (interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=20", testNum, pinToName(toPin).c_str());
}
pinMode(fromPin, OUTPUT);
digitalWrite(fromPin, LOW);
delay(2);
if (interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=21", testNum, pinToName(toPin).c_str());
}
interruptCalled = false;
pinMode(fromPin, INPUT);
delay(2);
if (!interruptCalled) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=22", testNum, pinToName(toPin).c_str());
}
if (interruptValue != HIGH) {
Serial.printlnf("FAILED! testNum=%d toPin=%s subTest=23", testNum, pinToName(toPin).c_str());
}
detachInterrupt(toPin);
pinMode(fromPin, INPUT);
pinMode(toPin, INPUT);
Serial.printlnf("test %d completed!", testNum);
testNum++;
state = START_TEST;
break;
}
}
The output should look like this:
running test 1: connect D0 to D1
test 1 completed!
running test 2: connect D0 to D2
test 2 completed!
running test 3: connect D0 to D3
test 3 completed!
running test 4: connect D0 to D4
test 4 completed!
running test 5: connect D0 to D5
test 5 completed!
running test 6: connect D0 to D6
test 6 completed!
running test 7: connect D0 to D7
test 7 completed!
running test 8: connect D0 to D8
test 8 completed!
running test 9: connect D0 to D9
test 9 completed!
running test 10: connect D0 to D10
test 10 completed!
running test 11: connect D0 to D11
test 11 completed!
running test 12: connect D0 to D12
test 12 completed!
running test 13: connect D0 to D13
test 13 completed!
running test 14: connect D0 to A5
test 14 completed!
running test 15: connect D0 to A4
test 15 completed!
running test 16: connect D0 to A3
test 16 completed!
running test 17: connect D0 to A2
test 17 completed!
running test 18: connect D0 to A1
test 18 completed!
running test 19: connect D0 to A0
test 19 completed!
running test 20: connect A0 to D0
test 20 completed!
tests completed!
7 Likes
Thanks for all that @rickkas7