Skip to content

attachInterrupt cause to crash immediately #2961

@soheils2

Description

@soheils2

Basic Infos

Hardware

Hardware: ESP-07-- ESP-01
Core Version: 2.3.0

Description

Problem description

Settings in IDE

Module: Generic ESP8266 Module
Flash Size: 1MB
CPU Frequency: 80Mhz
Flash Mode: ?qio?
Flash Frequency: 40Mhz
Upload Using: ? SERIAL?
Reset Method: ?ck / nodemcu?

Sketch

int encoderPinA = 13; // right
int encoderPinB = 14; // left

volatile unsigned int encoderPos = 0; // a counter for the dial
unsigned int lastReportedPos = 1; // change management
static boolean rotating=false; // debounce management

// interrupt service routine vars
boolean A_set = false;
boolean B_set = false;

void setup() {

pinMode(encoderPinA, INPUT);
pinMode(encoderPinB, INPUT);

// encoder pin on interrupt 14 (pin 14)
attachInterrupt(13, doEncoderA, CHANGE);
// encoder pin on interrupt 13 (pin 13)
attachInterrupt(14, doEncoderB, CHANGE);

Serial.begin(9600); // output
Serial.println("START");
}

void loop() {
rotating = true; // reset the debouncer

if (lastReportedPos != encoderPos) {
Serial.print("Index:");
Serial.println(encoderPos, DEC);
lastReportedPos = encoderPos;
}

}

// Interrupt on A changing state
void doEncoderA(){
// debounce
if ( rotating ) delay (1); // wait a little until the bouncing is done

// Test transition, did things really change?
if( digitalRead(encoderPinA) != A_set ) { // debounce once more
A_set = !A_set;

// adjust counter + if A leads B
if ( A_set && !B_set ) 
  encoderPos += 1;

rotating = false;  // no more debouncing until loop() hits again

}
}

// Interrupt on B changing state, same as A above
void doEncoderB(){
if ( rotating ) delay (1);
if( digitalRead(encoderPinB) != B_set ) {
B_set = !B_set;
// adjust counter - 1 if B leads A
if( B_set && !A_set )
encoderPos -= 1;

rotating = false;

}
}

messages here

hey there

im working on a project that needs a rotary encoder

when i upload this code in my esp-8266
the program works fine until i rotate the encoder
that cause to crash moudule

P.S:
code works fine with arduino boards or microcontrollers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions