Input pin has no irq attribute

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
GilbertGagne
Posts: 7
Joined: Wed Nov 11, 2020 5:40 pm

Input pin has no irq attribute

Post by GilbertGagne » Sun Feb 06, 2022 5:11 pm

I'm using an SPDT switch as Pi Pico inputs GP4 and GP5 to control motor direction via interrupts. The motor is connected to an H-Bridge with control inputs motor1 and motor2. Either GP4 or GP5 input generates an interrupt which toggles the onboard LED and toggles motor1.value() and motor2.value() thereby reversing the motor direction. Following is my program:

import machine
led = machine.Pin(25, machine.Pin.OUT) # onboard LED shows motor direction
sw1 = machine.Pin(4,machine.Pin.IN,machine.Pin.PULL_DOWN) # 1 pole of SPDT switch
sw2 = machine.Pin(5,machine.Pin.IN,machine.Pin.PULL_DOWN) # other pole
motor1 = machine.Pin(3, machine.Pin.OUT) # H-bridge control inputs
motor2 = machine.Pin(2, machine.Pin.OUT)
motor1.value(1) # start motor running CW
motor2.value(0)
def motor_handler(pin):
led.toggle()
motor1.toggle()
motor2.toggle()
sw1.irg(trigger=machine.Pin(4).IRQ_RISING, handler=motor_handler)
sw2.irg(trigger=machine.Pin(5).IRQ_RISING, handler=motor_handler)

The problem is with the last two lines which result in: AttributeError: 'Pin' object has no attribute 'irg'

I've consulted the Micropython Library for "pin" but can't find how to assign irq attribute.

fivdi
Posts: 16
Joined: Thu Feb 03, 2022 10:28 pm
Contact:

Re: Input pin has no irq attribute

Post by fivdi » Sun Feb 06, 2022 9:02 pm

There are typing mistakes in the code. In the code the method name irg is used, it should be irq.

GilbertGagne
Posts: 7
Joined: Wed Nov 11, 2020 5:40 pm

Re: Input pin has no irq attribute

Post by GilbertGagne » Mon Feb 07, 2022 1:28 pm

I am most thankful for the solution to my problem but also very embarrassed at being guilty of a spelling mistake. In over 40 years of computer coding I have never used other than visual inspection to debug my code. This hopefully will not happen again. Of course, at 84, my career is quickly closing but I am enjoying learning a new computer language.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Input pin has no irq attribute

Post by Roberthh » Mon Feb 07, 2022 1:55 pm

I have often similar problems, caused by degrading eyes, as I prefer to consider, not by degrading brain.

fivdi
Posts: 16
Joined: Thu Feb 03, 2022 10:28 pm
Contact:

Re: Input pin has no irq attribute

Post by fivdi » Mon Feb 07, 2022 7:02 pm

GilbertGagne wrote:
Mon Feb 07, 2022 1:28 pm
I am most thankful for the solution to my problem but also very embarrassed at being guilty of a spelling mistake. In over 40 years of computer coding I have never used other than visual inspection to debug my code. This hopefully will not happen again. Of course, at 84, my career is quickly closing but I am enjoying learning a new computer language.
You're welcome and take your time closing your career :)

Post Reply