I am building robots with the MicroPython board and wrote a quadrature encoder class.
It is initialized as follows:
Code: Select all
def __init__(self, pinA, pinB, pullups=True):
#configure the two pins and set the callback function
if pullups == True:
self.encoderACB = pyb.ExtInt(pinA, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_UP, self.encoderCallback)
self.encoderBCB = pyb.ExtInt(pinB, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_UP, self.encoderCallback)
else:
self.encoderACB = pyb.ExtInt(pinA, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_NONE, callback=self.encoderCallback)
self.encoderBCB = pyb.ExtInt(pinB, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_NONE, callback=self.encoderCallback)
Code: Select all
#Setup our encoder
encAPin = pyb.Pin(pyb.Pin.board.Y11)
encBPin = pyb.Pin(pyb.Pin.board.Y10)
encoder = encoders.QuadEncoder(encAPin, encBPin, pullups=False)
Code: Select all
#setup our leaf switch and start our ISR
leafPin = pyb.Pin(pyb.Pin.board.X19)
leafInt = pyb.ExtInt(leafPin, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_DOWN, leafCallback)
Code: Select all
Traceback (most recent call last):
File "main.py", line 152, in <module>
ValueError: ExtInt vector 0 is already in use
MicroPython v1.8.2-11-gbe313ea on 2016-07-13; PYBv1.1 with STM32F405RG
Type "help()" for more information.
In looking at the pinout here: http://micropython.org/resources/pybv10-pinout.jpg I noticed a few things:
1. The encoder was using Y10 and Y 11 which correspond to B0 and B11. Printing the "lines" variable inside the encoder ISR yields 0 and 11.
2. The leaf switch was using X19 which coresponds to C0 and happens to also be int vector 0.
3. Changing the leaf switch to X20 (C1) makes everything work perfectly.
So, does the number in the CPU name of each pin also correspond to the vector interrupt number it is assigned to?