On my ESP32V2, I'd like to count pulses using the countio module. For that I need to pass in the pin as the first argument to countio.Counter().
How I figure out what to use if my wire is connected to pin I37 ? (as per https://learn.adafruit.com/adafruit-esp ... v2/pinouts)
dir(board) lists the attributes. How do I find out which one is pin I37 ? Is it board.D37 or something else ?
how to determine board attribute for specific PIN ?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- vladak
- Posts: 95
- Joined: Thu Jan 06, 2022 7:05 pm
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: how to determine board attribute for specific PIN ?
IO37 would look like:
To see all the available pins from a circuitpython REPL prompt or script:
Code: Select all
pin_counter = countio.Counter(board.D37, edge=countio.Edge.RISE)
Code: Select all
import board
dir(board)
- vladak
- Posts: 95
- Joined: Thu Jan 06, 2022 7:05 pm
Re: how to determine board attribute for specific PIN ?
Thanks ! I also figured out the way to confirm is to look inside CircuitPython source itself, i.e. https://github.com/adafruit/circuitpyth ... _v2/pins.c
Due to the fact that Dan laid out the pins in the source code according to the silkscreen makes the code also documentation of sorts.
Due to the fact that Dan laid out the pins in the source code according to the silkscreen makes the code also documentation of sorts.
- vladak
- Posts: 95
- Joined: Thu Jan 06, 2022 7:05 pm
Re: how to determine board attribute for specific PIN ?
Also, for testing purpoes, I wonder if there is a way to generate the pulses via bit banging from CircuitPython. I have a RPi 3, QtPy and Feather ESP32-S2 lying around to try against the ESP32 V2, just need some examples.
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: how to determine board attribute for specific PIN ?
Viadak,
I have several different types of Microcontrollers running device specific versions of Circuit Python. To help, I run the script below while in REPL. I then copy-&-paste that information into a *.txt file on the Microcontroller. That gives me a ready reference as to what-is-what on that board.This what I get for a Raspberry Pi Nano W.HTH,
Bruce
I have several different types of Microcontrollers running device specific versions of Circuit Python. To help, I run the script below while in REPL. I then copy-&-paste that information into a *.txt file on the Microcontroller. That gives me a ready reference as to what-is-what on that board.
Code: Select all
import board
dir(board)
import supervisor
dir(supervisor)
import microcontroller
dir(microcontroller)
help("modules")
Code: Select all
>>> import board
>>> dir(board)
['__class__', '__name__', 'A0', 'A1', 'A2', 'A3', 'GP0', 'GP1', 'GP10', 'GP11', 'GP12', 'GP13', 'GP14', 'GP15', 'GP16', 'GP17', 'GP18', 'GP19', 'GP2', 'GP20', 'GP21', 'GP22', 'GP26', 'GP26_A0', 'GP27', 'GP27_A1', 'GP28', 'GP28_A2', 'GP3', 'GP4', 'GP5', 'GP6', 'GP7', 'GP8', 'GP9', 'LED', 'SMPS_MODE', 'STEMMA_I2C', 'VBUS_SENSE', 'VOLTAGE_MONITOR', 'board_id']
>>> import supervisor
>>> dir(supervisor)
['__class__', '__name__', 'RunReason', 'get_previous_traceback', 'reload', 'reset_terminal', 'runtime', 'set_next_code_file', 'set_usb_identification', 'status_bar', 'ticks_ms']
>>> import microcontroller
>>> dir(microcontroller)
['__class__', '__name__', 'Pin', 'Processor', 'ResetReason', 'RunMode', 'cpu', 'cpus', 'delay_us', 'disable_interrupts', 'enable_interrupts', 'nvm', 'on_next_reset', 'pin', 'reset', 'watchdog']
>>> help("modules")
__future__ builtins msgpack terminalio
__main__ busio neopixel_write time
_asyncio collections nvm touchio
_bleio countio onewireio traceback
_eve cyw43 os ulab
_pixelmap digitalio paralleldisplay ulab
adafruit_bus_device displayio pulseio ulab.numpy
adafruit_bus_device.i2c_device dotenv pwmio ulab.numpy.fft
adafruit_bus_device.spi_device errno qrio ulab.numpy.linalg
adafruit_pixelbuf floppyio rainbowio ulab.scipy
aesio fontio random ulab.scipy.linalg
alarm framebufferio re ulab.scipy.optimize
analogbufio gc rgbmatrix ulab.scipy.signal
analogio getpass rotaryio ulab.scipy.special
array hashlib rp2pio ulab.utils
atexit i2cperipheral rtc usb_cdc
audiobusio i2ctarget sdcardio usb_hid
audiocore imagecapture select usb_midi
audiomixer io sharpdisplay uselect
audiomp3 ipaddress socketpool vectorio
audiopwmio json ssl watchdog
binascii keypad storage wifi
bitbangio math struct zlib
bitmaptools mdns supervisor
bitops microcontroller synthio
board micropython sys
Plus any modules on the filesystem
>>>
Bruce
- vladak
- Posts: 95
- Joined: Thu Jan 06, 2022 7:05 pm
Re: how to determine board attribute for specific PIN ?
That's a nice tip with the saved txt output on the microcontroller, thanks !
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: how to determine board attribute for specific PIN ?
Viadak,
There is this bit of CircuitPython code too.Bruce
There is this bit of CircuitPython code too.
Code: Select all
import board
import microcontroller
if not False: # if True show Pin Assignments
print("\t\tMicrocontroller Pin Assignments:")
board_pins = []
for pin in dir(microcontroller.pin):
if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin):
pins = []
for alias in dir(board):
if getattr(board, alias) is getattr(microcontroller.pin, pin):
pins.append("board.{}".format(alias))
if len(pins) > 0:
board_pins.append(", ".join(pins))
for pins in sorted(board_pins):
print(pins)
time.sleep(1)
- blakebr
- Posts: 957
- Joined: Tue Apr 17, 2012 6:23 pm
Re: how to determine board attribute for specific PIN ?
Ignore previous chunk of code:Bad indent, sorry.
Bruce
Code: Select all
def PinAssign(): # if True show Pin Assignments
import board
import microcontroller
print("\t\tMicrocontroller Pin Assignments:")
board_pins = []
for pin in dir(microcontroller.pin):
if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin):
pins = []
for alias in dir(board):
if getattr(board, alias) is getattr(microcontroller.pin, pin):
pins.append("board.{}".format(alias))
if len(pins) > 0:
board_pins.append(" ".join(pins))
for pins in sorted(board_pins):
print(pins)
Bruce
Please be positive and constructive with your questions and comments.