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


some non-blynk related stuff again…
on a sonoff 4ch, pcb v2.0 board i have replaced the stock firmware, using the arduino ide.

i would like to set up interrupts for each button gpio. with the above setup, button 1 and button 4 works perfectly, however, button 2 and button 3 does not work. it seems that the interrupt is never executed, although i’ve checked with my multimeter that gpio9 and gpio10 are high, and is going low when i press the respective button.

what could be the reason for this? unfortunately i can not find a good pinout diagram for this esp8285, all the sites i’ve read says that all pins have interrupt function, except gpio16.

or something is not fully implemented in the arduino core, regarding digitalPinToInterrupt() function?
but than why works the same function for gpio0 and gpio14? i’m a bit confused regarding this.

Hardware: ESP8285 (sonoff 4ch v2.0)
Core Version: 2.3.0
Arduino IDE: 1.8.4

Settings in IDE:
Module: Generic ESP8285 Module
Flash Size: 1MB
CPU Frequency: 80Mhz
Upload Using: SERIAL

void setup()
      attachInterrupt(digitalPinToInterrupt( 0), button1ISR, FALLING);  // button 1
      attachInterrupt(digitalPinToInterrupt( 9), button2ISR, FALLING);  // button 2
      attachInterrupt(digitalPinToInterrupt(10), button3ISR, FALLING);  // button 3
      attachInterrupt(digitalPinToInterrupt(14), button4ISR, FALLING);  // button 4

Can you post the whole sketch? By all means it should work, though there are some really weird things going on with delay and ISR’s from what I can read here:

It could be something to do with too much stuff going on. What happens if you scratch Button 1 and 4 and just use 2 and 3? E.g. comment those ISR’s out in setup()?


I’ve used ISR on the model railroad for moving and stopping a hot air balloon on a curtain rod (which works wonderfull) with some end-stop switches. But that’s only two ISR’s because I use I Nano there.

@wanek some pins are special and some are very, very special. 9 & 10 fall into the latter category.
I don’t have any ESP’s with pins 9 & 10 broken out but don’t you have to disable the very, very special feature of the pins to revert to a regular pin?

Think they are part of the flashing process but I could be wrong.

1 Like

i see your point, but i did tried that already. even if i use only button 2 or button 3, it does never enters the isr. i’ve tried all combinations. only button 1 and button 4 works.

i did some further research, and maybe it has something to do with this:

it seems these are some “magic” pins, hooked up maybe to the flash?

i observed that on the wemos mini lite board they not even broke out…

@Costas, yes, see my above post.
theoretically they are / or not used by the flash memory chip. but igr says they should be usable on some models. i’m quite lost…

on the sonoff ch4, the are officially hooked up to button 2 and button 3, so they should be usable. maybe the interrupt does not work on them, only as normal i/o pins?

because it’s a sure fire way to destroy your ESP.

this is the factory pinout of the sonoff 4ch:

   GPIO      function                        schematic
   GPIO  0   Button 1                        E-FW
   GPIO  9   Button 2                        IO  9
   GPIO 10   Button 3                        IO 10
   GPIO 14   Button 4                        IO 14

   GPIO 12   Relay 1                         IO 12
   GPIO  5   Relay 2                         IO  5
   GPIO  4   Relay 3                         IO  4
   GPIO 15   Relay 4                         IO 15

   GPIO  2   Pin 1 Prog Header               SDA
   GPIO 13   Blue LED, Active Low            PWM 1

   GPIO  7   Not connected, jack (see TH16)  GPIO 07
   GPIO  8   Not connected, jack (see TH16)  GPIO 08

   3v3 - jack sleeve
   gnd - jack ring2

@Costas, do not forget, i’m talking about the esp8285, not8266 (i know on 8266 they are not usable, but 8285 is a bit different because of the built in flash)

Stupid question, did you try to use any other pins with an ISR and do they work?

actually only gpio 0 and gpio 14.
there are not too much left, only gpio 2 is accessible, because of the schematic.

@Lichtsignaal, i’m sure my isr is not causing this, it is really simple stuff:

void button1ISR()                                     // ISR function, do not use delays here !!!
  if (millis() > buttonIsrTimestamp + 200) {          // debounce button
    digitalWrite(RELAY_1, !digitalRead(RELAY_1));
    buttonIsrTimestamp = millis();

it is the similar isr for all 4 buttons

Yeah that looks pretty much OK to me too.

You’d need an ESP8285 without the Sonoff stuff too test it properly I guess. Maybe they did something to it (must a conspiracy, lol).

1 Like

on my board, there is a different version mcu, not like on the above photo. mine is covered with metal shield, so i can not see the “schematic” under it…

i also opened an issue on github, maybe some esp wizard will know the secret behind this…

@wanek Espressif’s datasheet for the 8285 has 7 or 8 options for pins 9 and 10.

SDIO, SPI, GPIO, I2C (pin 9 only), I2S, PWM, IR (pin 9 only) and LED (pin 10 only).

Can you see if Itead have used pin 10 for an LED? Not sure what they might have used pin 9 for.

From the pinout you have it indicates 9 and 10 should be available but you state it’s not the same version MCU. Which version is yours?

this is how it looks like.
the paper tag was on the metal shield.
no useful info there :frowning:

im not sure, should i try to pry open the metal cover? maybe i will damage the board…

@Costas, ok here we go (i pulled out my old dmc-fz30, this is the best photo i can get now):

it says:
P13461 (this line is barely visible, so maybe it is not correct)

based on the official schematic, gpio 9 and gpio 10 are hooked up to the button 2 and 3, and are pulled high via 10k resistors. nothing special.

I wouldn’t do that unless you have lots of them to do destructive testing on.
Does yours not have an external antenna socket?
Itead have ceramic aerial modules as PSF-B85 and external aerial modules as PSF-A85.

I would post on Itead’s site. They are fairly responsive.

as you can see on the above photo, i already removed :slight_smile: not brute force actually i desoldered it, so no harm done!

Ah ok, from the schematics can you trace pins 9 and 10 to see if Itead have used them for LED’s etc?

AFAIK Espressif only have one version of the ESP8285 but Itead may have used them in different ways on different break out boards.

@Costas, this is what i said before:

so, again, gpio 9 and 10 are hooked up to pushbutton 2 and 3. also they are pulled up by 10k resistors. double checked the schematic and also measured with my dmm.

no leds, whatsoever.

Are 0 and 14 exactly the same i.e. with 10K PU?

If they are the same it’s your bad code :slight_smile:

You said the code is “almost” the same for the 4 pins. I would like to see the words almost removed and see your results.