ExtInt with D6/PA8 pin on Portenta

Hi,

I’m aware that I should be using D0/PH15 pin for external interrupts but that pin is already taken by one of the other peripheral sensors so I am looking at other options. Looking at the pinout, D6/PA8 is an option (also, ideally, I’d like to use this because I have a PCB that connects a PIR sensor to this pin).

Here’s my test code:

import pyb, machine, time
from pyb import Pin, ExtInt


def callback(line):
    print("In callback")
    pyb.LED(1).on()
    pass


pir = Pin("D6", Pin.IN, Pin.PULL_DOWN)
ext = ExtInt(pir, ExtInt.IRQ_RISING, Pin.PULL_DOWN, callback)

# Enter Stop Mode. Note the IDE will disconnect.
machine.sleep()

while True:
    pyb.LED(3).on()
    time.sleep_ms(100)
    pyb.LED(3).off()
    time.sleep_ms(100)

The code should be sending Portenta to sleep and wake up when motion is detected, but straight-up wakes up as soon as the code is executed (works fine with D0 pin).

Am I understanding something wrong here?

PC

Works for me with the latest firmware. You are missing:

import time

In your script.

I see. Let me get back to you after a few more tests, I guess.

Thanks for telling about time; copy-paste mistake.

EDIT

  1. I’ve been using the latest firmware (4.5.9 as of today); Arduino Portenta (STM32H747) board.
  2. When D0 is used, the Portenta goes to sleep until PIR sensor detects motion. Upon motion, both blue and red LEDs are lit.
  3. When D6 is used, the Portenta immediately starts blinking blue. IDE disconnects, implying the device did go to sleep for at least a moment. Upon waving my hand in front of the PIR sensor, blue+red starts off (callback is called at this stage)

PC

Latest firmware is v4.6.22. The IDE should have installed new resources and prompted you in the status bar to update.

  1. When D0 is used, the Portenta goes to sleep until PIR sensor detects motion. Upon motion, both blue and red LEDs are lit.

I see this behavior when using D6. However, I just applied 3.3V to the pin to cause the wakeup.

Ah, that’s really odd. Maybe I should update the IDE.

But doesn’t this mean the Portenta did not actually sleep for more than that one moment? I just double checked with a USB powermeter.

When using D0:
No LED (Sleep): 0.025 A
R+B blinking (Awake): 0.112 A

When using D6:
B blinking: 0.11 A
R+B blinking: 0.11 A

PC

Uh, I mean, when I run your code with my Portenta the LEDs never turn on and it disconnects from USB. Then when I apply 3.3V to D6 it wakes up and the LED starts flashing both colors.

I had my camera sensor facing into a table BTW so it was seeing black. Not sure if an interrupt line toggling from it could wake the system.

Okay, I just changed to a different Portenta and am now getting what you have been all along on D6. So weird. Any guesses why this could have happened?

Thanks for your help!

PC

Could be damaged or something. I don’t know.

Yeah, you’re right about the camera and the damage.

I tried running without the camera and with a new one, both worked! Surprisingly the “damaged” camera still works otherwise.

PC