Description
Sorry,
Not sure if this is best asked here or up on forum, Also lost first pass of typing this in, so will probably be more brief
which may not be a bad thing.
As @mjs513 and myself have been experimenting with CircuitPython and MicroPython, I am trying to understand the relationship between the code bases. From Github, my impression is that this is a fork of MicroPython so would expect a lot of basic stuff to be common.
Also I am mostly mentioning Teensy here as that is what I am working on and more familiar with, but a lot of this would mostly likely apply to other boards as well.
Things like:
Creating of UART Objects
Example wish to create two uart objects for what in Arduino are Serial1 and Serial4 on T4.1.
With MicroPython would do something like:
from machine import UART
uart1 = UART(1, 1000000)
uart4 = UART(4, 1000000)
With CircuitPython something like:
import busio, boardio
uart1 = busio.UART(board.TX, board.RX, baudrate=500000)
uart4 = busio.UART(board.D17, board.D16, baudrate=500000)
Or with current stuff pulled in the last one can be done like:
uart4 = busio.UART(board.TX4, board.RX4, baudrate=500000)
Why complete different? Both have pluses and minus.
Asynchronous UART output
More fundimental issue. As I mentioned in the issues: #6263 and #6254
Some code like:
uart1 = busio.UART(board.TX, board.RX, baudrate=1000000)
uart2 = busio.UART(board.IO17, board.IO16, baudrate=1000000)
uart1.write(b'uart1')
uart1.write(b'second part')
toggle_pin.value = True
uart2.write(b'uart2')
toggle_pin.value = False
The code waited for each write to complete before it continued, which was totally unexpected by me as I would hope
that the code could continue to do other things. Also there was a pretty large gap between each operation
But from 6254:
busio.UART()
is synchronous. It waits for the sending to complete before returning.
When try something similar on MicroPython:
import machine
from machine import UART
import select
import sys
import time
loop_count = 0
uart1 = UART(1, 1000000)
uart4 = UART(4, 1000000)
led = machine.Pin(13, machine.Pin.OUT)
mp = machine.Pin(2, machine.Pin.OUT)
while True:
mp.high()
uart1.write("Uart1:")
uart1.write("More data")
uart4.write("Uart4!")
mp.low()
led.high()
time.sleep(0.2)
led.low()
time.sleep(0.2)
led.high()
time.sleep(0.2)
led.low()
time.sleep(0.8)
loop_count += 1
if (loop_count & 0xf) == 0:
print(str(loop_count))
avail = select.select([sys.stdin], [], [], 0)
if avail != ([], [], []):
input_line = sys.stdin.readline().rstrip("\n")
print("in:", input_line)
I see output that is more what I expected:
Teensy SDIO Support
Currently there is no code support within the ports for Teensy boards to support an SDIO, where as there is support within
MicroPython.
For example I have a Teensy 4.1 plugged in with an SDCard inserted within the built in SD slot.
For example with REPL I have:
>>> import os
['flash', 'sdcard']
>>> os.listdir('/flash')
[]
>>> os.listdir('/sdcard')
['System Volume Information', 'mtpindex.dat', 'odd1.wav', 'zarathustra.mp3', '2001', 'Audacity', 'FLAC', 'Candyman.aac', 'Dont Rain on My Parade.mp3', 'annie1.bmp', '111', '222', 'Small-Drake.jpg', 'Test', 'testImage.png', 'annie2.bmp', 'annie3.bmp', 'DSC00040.JPG', 'DSC00445.jpg', 'DSC01511.JPG', 'DSC03201.JPG', 'house.gif', 'Laiik-is-Tired.bmp', 'P3090005.JPG', 'Sharon Barn.bmp']
Looking to try to add SDIO support, but hard to know good starting point, a couple of options include:
a) try to copy and rewrite the code for STM to be IMXRT1062 based.
b) Try to start from the MicroPython code base, but your HAL/SDK code is significantly different.
c) Try to bypass most of it and start with Teensy SDFat like code.
DigitalIO
Sorry minor comment.
Turning an IO pin on and off is different.
MicroPython:
led.on()
led.off()
CircuitPython:
led.value = True
led.value = False
I can work with either, I do find the on() and off() to be more readable... But.
Again sorry, I am not sure if this is the appropriate place to ask and probably some/all of this
has been answered before.
Kurt