ESP8285 gpio 9 & gpio 10 interrupt question (not directly blynk related)

yes, they all have 10k.
pardon me, but where did you see i say “almost”?
because i didn’t say that. i said the code is similar for all isr.

Ok I would like similar to say identical. Switch the pins around.

yes, identical is better word.
what do you mean by switch the pins around?

Whatever was working for 0 and 14 do identically for 9 and 10, either in software or hardware.

in hardware i didn’t made any changes, it is the original sonoff design.

and in software i have literarly the identical code for all 4 isr, the only difference is the relay pins.

i have a feeling that pins 9 and 10 somehow do not have implemented interrupt function in the mcu. maybe because they didn’t meant to be used in former boards…

i will ask espressif or itead tomorrow, now i think i go to sleep. thanks for the help!

Can’t you swap the relay pins to make everything identical even at the expense of dropping 0 and 14 for now?

ah, ok, i understand what you mean now. i will try that tomorrow. i’m too tired now.

1 Like

@Costas, do you have any info, how can i find out which gpio is which interrupt on the esp8285?

i mean, on the arduino uno board - for example - there are detailed pinout diagrams, and one can know that:

pin pd2 is int0
pin pd3 is int1
etc.

so, if i would like to setup int0 on the uno, i can do it

like this:
attachInterrupt(digitalPinToInterrupt(2), myISR, FALLING);

or, like this:
attachInterrupt(0, myISR, FALLING);

but how can i know on the esp8285 what gpio corresponds to what interrupt numbers?

for example, on the esp8285:
gpio9 is int ??
gpio10 is int ??

i need this info, because i would like to try to place the interrupt number directly in to the function, without calling digitalPinToInterrupt(), maybe it will work this way.

i’ve already tried to use the same number for interrupt as the gpio number, but it didn’t works. and i couldn’t find any pinout diagrams for esp8285 where interrupt numbers are specified :frowning:

also, in one of your posts you mention:

how can i do that?

thanks!

@wanek this is where ESP’s are different to Arduino’s. They don’t have different interrupts so for ESP’s it’s simply:
attachInterrupt(digitalPinToInterrupt, myISR, FALLING);

I think for the ESP8285 it’s not required and GPIO 9 and 10 should just work. Not sure if the core you are using has 9 and 10 enabled though.

1 Like

than this could be something to look into! because there is no dedicated core for 8285, the same 8266 is used, and would be reasonable to have disabled int 9 and 10.

i will try to find and edit the respective file in the core… however, i’m not sure where to start searching. but thanks for the idea!

i found this file:
C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc1\cores\esp8266\core_esp8266_wiring_digital.c

i do not really understand everything what is happening in this file, but maybe should have to edit something here… ?

at line 166 there is this function:

void initPins() {
  //Disable UART interrupts
  system_set_os_print(0);
  U0IE = 0;
  U1IE = 0;

  for (int i = 0; i <= 5; ++i) {
    pinMode(i, INPUT);
  }
  // pins 6-11 are used for the SPI flash interface
  for (int i = 12; i <= 16; ++i) {
    pinMode(i, INPUT);
  }

  ETS_GPIO_INTR_ATTACH(interrupt_handler, &interrupt_reg);
  ETS_GPIO_INTR_ENABLE();
}

i have added these lines, and its working!!! :slight_smile:

void initPins() {
  //Disable UART interrupts
  system_set_os_print(0);
  U0IE = 0;
  U1IE = 0;

  for (int i = 0; i <= 5; ++i) {
    pinMode(i, INPUT);
  }
  
  // pins 6-11 are used for the SPI flash interface (actually pins 9 and 10 are usable as gpio on esp8285)
  
#ifdef MCU_ESP8285
  pinMode( 9, INPUT);
  pinMode(10, INPUT);
#endif

  for (int i = 12; i <= 16; ++i) {
    pinMode(i, INPUT);
  }

  ETS_GPIO_INTR_ATTACH(interrupt_handler, &interrupt_reg);
  ETS_GPIO_INTR_ENABLE();
}

thanks again for the useful tip!
i wonder should this feature be integrated to the official core?

1 Like

@wanek I have previously seen the section of core_esp8266_wiring_digital.c that your refer to.

I notice you originally wrote that your mod wasn’t working but now it is. Just in case I start using the 8285 what suddenly made it work?

And yes it’s worth sending a PUSH for the mod.

Which version of the core are you using 2.30, 2.40-rc1 or master? It might be that the mod is in the new cores.

  • based on the other topic, regarding the setproperty function, per your reccomendation now i’m using the 2.40-rc1 core.

  • first time it did not worked because of the #ifdef MCU_ESP8285 line. i’ve tried to define this in my sketch, and it seems that’s not working. but just for a test, i have deleted the
    #ifdef MCU_ESP8285
    and
    #endif
    lines, so now it works.

but i have to find a way how to control the mcu type from sketch, because in this way it will crash if i will use an esp8266 board…

Just off out but I think your define is wrong.

i’ve thought that if i define something in my sketch, the core can find it during compile time, but it seems that doesn’t

i just put this in my sketch:
#define MCU_ESP8285

should i do another way?

I’ll show you a way that we use that should be OK for you.

Find “esp8285.build.board=ESP8266_ESP01” definition in boards.txt file. Change the generic end of line from “ESP8266_ESP01” to something unique like “ESP8285rev1”. Save the file.

Then in core_esp8266_wiring_digital.c modify your code to:

#ifdef ARDUINO_ESP8285rev1
  pinMode( 9, INPUT);
  pinMode(10, INPUT);
#endif

Note the Arduino_ prefix before your new “ESP8285rev1”. All boards are prefixed with Arduino_.
Nothing required in your sketch as it should only make pins 9 and 10 available when you compile for the ESP8285 board.

To test it, without an ESP8285, we did this:

  for (int i = 0; i <= 4; ++i) {  // Costas 4 was 5
    pinMode(i, INPUT);
  }
  // pins 6-11 are used for the SPI flash interface
  #ifdef ARDUINO_ESP8266_WEMOS_D1MINI
    //pinMode( 9, INPUT);
    //pinMode(10, INPUT);
    pinMode(5, INPUT);
  #else
	pinMode(5, OUTPUT);
  #endif

Then in the sketch in setup()

attachInterrupt(5, checkPinMode, CHANGE); // Wemos D1

and the function:

void checkPinMode(){
  detachInterrupt(5);  
  Serial.println("Input on GPIO 5");
  attachInterrupt(5, checkPinMode, CHANGE);  
}

Compiled as a WeMos D1 Mini the interrupt works but doesn’t work if you compile as an Generic ESP8266 because it now only as input pins 1 to 4 and 12 to 16 with pin 5 defined as an output pin.

1 Like

very cool method, thank you. this is EXACTLY what i needed!

i already know how to handle the boards.txt, because i used to create some “custom” boards for some of my projects (for example, right now i’ve finished to design a board with attiny85).

i suspected that i have to tamper with boards.txt, but i didn’t know what i have to edit to make this interrupt hack applicable for only the esp8285 mcu. but based on what you described, i’m sure this will work :wink:

thanks again!

1 Like

@Costas, i moved this topic to public forum, hope it is not a problem! and because i think it could definitely help other users too.

@wanek no problem, I have allocated it to a category as I don’t like to see uncategorised posts.