Skip to content

Interrupt use wrong pin on Arduino Nano ESP32 #10209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
andreock opened this issue Aug 20, 2024 · 3 comments
Closed
1 task done

Interrupt use wrong pin on Arduino Nano ESP32 #10209

andreock opened this issue Aug 20, 2024 · 3 comments
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@andreock
Copy link
Contributor

andreock commented Aug 20, 2024

Board

Arduino Nano ESP32

Device Description

Arduino Nano ESP32

Hardware Configuration

Pin D5 is set in INPUT_PULLUP mode and connected to a push button to GND.

Version

v3.0.4

IDE Name

PlatformIO

Operating System

Arch Linux

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

460800

Description

When i use the function attachInterrupt(digitalPinToGPIONumber(D5), change_state, CHANGE); the pin that handle interrupt is the D8 pin despite I use digitalPinToGPIONumber(D5). On the same board interrupt worked until about begin of August then stopped to work, I also rollback to 2.0.16 version of arduino-esp32 but still no works. Can be a problem of the board?

EDIT: 2.0.14 works

Sketch

#include <Arduino.h>

bool test = false;

void ARDUINO_ISR_ATTR change_state() {
  test = true;
}

void setup() {
  Serial.begin(9600);
  pinMode(D5, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(D5), change_state, CHANGE);
}

void loop() {
  if(test)
    Serial.println("Hello");
  Serial.println("World");
  delay(1000);
}

Debug Message

No guru meditation error happened

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@andreock andreock added the Status: Awaiting triage Issue is waiting for triage label Aug 20, 2024
@me-no-dev
Copy link
Member

@pillo79 would this be the best way to attach the interrupt?

@pillo79
Copy link
Contributor

pillo79 commented Aug 21, 2024

Hello @andreock, I suspect the problem is your use of the digitalPinToGPIONumber function. These should really be used only when directly writing to a CPU register or something like that; for Arduino APIs, this detail should be handled by the core for you, transparently, regardless of the Pin Mapping setting in the IDE.

Can you simply try with attachInterrupt(D5, ...)?

@andreock
Copy link
Contributor Author

Sorry, I made a typo in the previous question, I use digitalPinToInterrupt not digitalPinToGPIONumber. By the way if I use attachInterrupt(D5, ...) with the current SDK(3.0.4) works. I was sure I had tried yesterday attachInterrupt(D5,...) without digitalPinToInterrupt(), Sorry for the useless issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

3 participants