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.
Input pin has no irq attribute
Re: Input pin has no irq attribute
There are typing mistakes in the code. In the code the method name irg is used, it should be irq.
-
- Posts: 7
- Joined: Wed Nov 11, 2020 5:40 pm
Re: Input pin has no irq attribute
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.
Re: Input pin has no irq attribute
I have often similar problems, caused by degrading eyes, as I prefer to consider, not by degrading brain.
Re: Input pin has no irq attribute
You're welcome and take your time closing your careerGilbertGagne wrote: ↑Mon Feb 07, 2022 1:28 pmI 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.