"""
CircuitPython exercise run on STM32F411CE,
get system info.
"""
import os
import microcontroller
import sys
print("- sys.implementation -")
for i in sys.implementation:
print(i)
print()
print("- os.uname() -")
for u in os.uname():
print(u)
print()
print("microcontroller.cpu.frequency:\t\t" + str(microcontroller.cpu.frequency))
print("microcontroller.cpu.temperature:\t" + str(microcontroller.cpu.temperature))
print("microcontroller.cpu.voltage:\t\t" + str(microcontroller.cpu.voltage))
cpyF411_listdir.pya
"""
CircuitPython List Files:
The original example list files in SDCard,
now modified to list files in current working directory.
ref:
https://learn.adafruit.com/micropython-hardware-sd-cards/tdicola-circuitpython
scroll down to "List Files"
"""
import os
def print_directory(path, tabs=0):
for file in os.listdir(path):
stats = os.stat(path + "/" + file)
filesize = stats[6]
isdir = stats[0] & 0x4000
if filesize < 1000:
sizestr = str(filesize) + " by"
elif filesize < 1000000:
sizestr = "%0.1f KB" % (filesize / 1000)
else:
sizestr = "%0.1f MB" % (filesize / 1000000)
prettyprintname = ""
for _ in range(tabs):
prettyprintname += " "
prettyprintname += file
if isdir:
prettyprintname += "/"
print('{0:<40} Size: {1:>10}'.format(prettyprintname, sizestr))
# recursively print directory contents
if isdir:
print_directory(path + "/" + file, tabs + 1)
currentDirectory = os.getcwd()
print("Files on filesystem: ", currentDirectory)
print("====================")
print_directory(currentDirectory)
cpyF411_readfile.py
"""
CircuitPython exercise run on STM32F411CE,
get system info.
"""
import os
textfile = "/boot_out.txt"
print("text file:", textfile)
print("========================")
with open(textfile, "r") as f:
print("Read line from file:")
print(f.readline())
"""
CircuitPython exercise run on STM32F411CE,
toggle onboard LED.
"""
import board
import digitalio
import time
print("\ndir(board):")
print(dir(board))
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True #LED Off
time.sleep(0.3)
led.value = False #LED On
time.sleep(0.3)
led.value = True #LED Off
time.sleep(0.3)
led.value = False #LED On
time.sleep(0.3)
led.value = True #LED Off
time.sleep(0.3)
led.value = False #LED On
time.sleep(1.5)
Next exercise of STM32F411/CircuitPython 7"
No comments:
Post a Comment