https://github.com/KurtE/circuitPython/ ... python_dev
One interesting side effect, is Adafruit's code checks run on this branch as well, even though this branch will not be PR'd into CircuitPython...
In this branch I have a version of the Micromod that appears to build and run. For example this blinks the LED
Code: Select all
>>> import machine
>>> from machine import Pin
>>> led = Pin('LED', Pin.OUT)
>>> led.on()
>>> led.off()
>>> import time
>>> for i in range(10):
... time.sleep_ms(250)
... led.on()
... time.sleep_ms(250)
... led.off()
...
>>>
Also the command line for teensy_loader_cli was wrong for T4.1. Also experimenting with adding the TX1-7(8) RX1-7(8) pin names like @mjs513 and myself added to the CircuitPython code.
One of the next things I may try to figure out, is. Is there a dictionary or the like, that I can enumerate to know which pins may be defined for a particular board? Is there a way to deduce if multiple logical names map to the same physical name.
For example: I have check_pins sketch for CircuitPython, that loops through the logical names and comes up with list of unique pins, and then allows me to Pull up all of the pins high and then check to see if any of the pins register low (jumper from GND to pin), and if so then print out which pins have changed state...
Code: Select all
import board, busio, digitalio, time, supervisor
from microcontroller import Pin
from digitalio import DigitalInOut, Direction, Pull
#led = digitalio.DigitalInOut(board.LED)
#led.direction = digitalio.Direction.OUTPUT
# lets first get a list of the boards pins
# temporary exclude led
exclude = ['USB_HOST_DM', 'USB_HOST_DP', 'USB_HOST_POWER', 'LED']
all_pins = {}
print_progress_dots = False
pull_up_or_down = Pull.UP #default first pass to do Pullup
class pinNamesRecord(object):
def __init__(self, pin, pin_name):
self.pin = pin
self.pin_names = pin_name
self.last_check = True
def print_pin_table():
print("\nEnum pin list")
print("Physical Pins\tLogical Names")
for pin_entry in all_pins:
pny = all_pins[pin_entry]
print(pin_entry, "\t", pny.pin_names)
def UpdatePullUpDown():
print()
if pull_up_or_down == Pull.UP:
print("Setting all pins to PULL up - so test by jumpering pins to GND")
last_check = True
else:
print("Setting all pins to PULL down - so test by jumpering pins to +3.3v")
last_check = False
for pin_entry in all_pins:
pny = all_pins[pin_entry]
pny.pin.pull = pull_up_or_down
pny.last_check = last_check
time.sleep(0.25)
for board_item in dir(board):
if board_item not in exclude:
item_attr = getattr(board, board_item)
if isinstance(item_attr, Pin):
#print("Check pin: ", board_item, "(",item_attr, ")")
pin_str = str(item_attr)
#has names like: board.D33
pin_str = pin_str[6:] #remove board.
if pin_str in all_pins:
if pin_str != board_item:
pnr = all_pins[pin_str]
pnr.pin_names = pnr.pin_names + ' ' + board_item
all_pins[pin_str] = pnr
#print("\tDup: ", pnr.pin_names)
else:
# new one
iopin = DigitalInOut(item_attr)
iopin.direction = Direction.INPUT
iopin.pull = Pull.UP
if board_item == pin_str:
add_str = board_item
else:
add_str = pin_str + ' ' + board_item
pnr = pinNamesRecord(iopin, add_str)
all_pins[pin_str] = pnr
#print("\tnew: ", pnr.pin_names)
UpdatePullUpDown()
#print_pin_table()
print("A Python version of the Pin High/Low test")
print("Simple keyboard interface")
print("\tEmpty line, will toggle between IO pins Pulled UP and Pulled Down")
print("\tp - print pin table out showing all pin names for pin")
print("\t. - will toggle printing progress dots on or off")
loop_count_no_changes = 0
while True:
#check for User Input
if supervisor.runtime.serial_bytes_available:
text = input()
print("*** Serial input ***", text)
if text == 'p' or text == 'P':
print_pin_table()
elif text == '.':
if print_progress_dots:
print_progress_dots = False
print("** Turned off progress dots ***")
else:
print_progress_dots = True
print("** Turned off progress dots ***")
else:
if pull_up_or_down == Pull.UP:
pull_up_or_down = Pull.DOWN
else:
pull_up_or_down = Pull.UP
UpdatePullUpDown()
# scan the pins
pin_changed = False
for pin_entry in all_pins:
pny = all_pins[pin_entry]
new_pin_value = pny.pin.value
if new_pin_value != pny.last_check:
if loop_count_no_changes:
loop_count_no_changes = 0
if print_progress_dots:
print()
pny.last_check = new_pin_value
if pny.last_check:
print("HIGH: ", end='')
else:
print("LOW: ", end='')
print(pny.pin_names)
pin_changed = True
if pin_changed == False:
loop_count_no_changes += 1
if loop_count_no_changes < 320:
if (loop_count_no_changes & 7) == 0:
if print_progress_dots:
print('.', end='')
else:
if print_progress_dots:
print('.')
loop_count_no_changes = 0
time.sleep(0.25)
Thanks again.
Edit: progress in my understanding
Code: Select all
>>> import machine
>>> for bi in dir(machine.Pin.board):
... print(bi, "->", getattr(machine.Pin.board, bi))
...
Code: Select all
A0 -> Pin(GPIO_AD_B1_02)
A1 -> Pin(GPIO_AD_B1_03)
A10 -> Pin(GPIO_AD_B0_12)
A11 -> Pin(GPIO_AD_B0_13)
A12 -> Pin(GPIO_AD_B1_14)
A13 -> Pin(GPIO_AD_B1_15)
A2 -> Pin(GPIO_AD_B1_07)
A3 -> Pin(GPIO_AD_B1_06)
A4 -> Pin(GPIO_AD_B1_01)
A5 -> Pin(GPIO_AD_B1_00)
A6 -> Pin(GPIO_AD_B1_10)
A7 -> Pin(GPIO_AD_B1_11)
A8 -> Pin(GPIO_AD_B1_08)
A9 -> Pin(GPIO_AD_B1_09)
CLK -> Pin(GPIO_SD_B0_01)
CMD -> Pin(GPIO_SD_B0_00)
D0 -> Pin(GPIO_AD_B0_03)
D1 -> Pin(GPIO_AD_B0_02)