CircuitPython was developed by Adafruit based on MicroPython, which is a Python environment for microcontrollers. Compared to Arduino's C language, it can realize high functionality with less description, and it can be written easily without the need for compilation.
CircuitPython compatible microcomputer https://circuitpython.org/downloads
In addition to Adafruit's own microcomputer, it also supports Seeeduino XIAO.
Detailed explanation of this microcomputer https://qiita.com/nanase/items/0fed598975c49b1d707e
micro: bit can also be programmed in MicroPython https://microbit.org/
Seeeduino XIAO is cheaper and has a higher clock frequency than the micro: bit.
microbit(MCU:ARM Cortex M0 + 32bit 16 MHz(Nordic nRF51822 )) https://www.switch-science.com/catalog/5263/
Seeduino XIAO(CPU:ARM Cortex-M0 + 32bit 48 MHz(SAMD21G18)) https://www.switch-science.com/catalog/6335/ Amazon sells a set of 3 https://www.amazon.co.jp/dp/B086KXY929
Seeed's HP has detailed instructions on how to install CircuitPython. https://wiki.seeedstudio.com/Seeeduino-XIAO/ https://wiki.seeedstudio.com/Seeeduino-XIAO-CircuitPython/
Download CircuitPython for Seeeduino XIAO. https://circuitpython.org/board/seeeduino_xiao/
If you short-circuit the RST terminal of XIAO twice, the orange LED will light up and the Arduino drive will appear under the PC. Reset video borrowed from Seeed HP and pasted
Then drop the downloaded file onto this drive and make a copy.
When the copy is complete, the drive name will change to CIRCUITPY.
If you write a Python program in the Mu editor and save it as main.py on this drive, the program will run automatically.
L Chika Program
main.py
import time
import board
from digitalio import DigitalInOut, Direction
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
I tried embedding the video with gif
Qiita for reference https://qiita.com/bohebohechan/items/f8bf6d4bbe0f14497a7b
The Mu editor is explained in detail below. https://qiita.com/inachi/items/8f61586cd2482987b8d0
Press the "Mode" icon to switch to "Adafruit CircuitPython" mode
I get an error message when I press the "serial" icon
In Defalt, Adafruit's microcontroller board seems to connect when you press the serial icon, but Seeeduino XIAO cannot connect serially!
Seeeduino XIAO USB VID: 0x2886 and PID: 0x002f to connect C:/Users/%username%/AppData/Local/Mu/pkgs/mu/modes/adafruit.py You have to register it in the file. https://www.seeedstudio.com/blog/2020/03/30/update-for-seeeduino-xiao-from-the-community/
In the case of Windows, check the hidden file display in the file manager, Windows freezes when you try to open adafruit.py with an editor, so change the file extension from py to txt, open it with an editor and edit it, Change the extension back to py.
When I wrote it like line 67, when I pressed the "serial" icon in the Mu editor, it connected to Seeeduino XIAO safely, and the "plotter" also worked.
Code displayed on the plotter
main.py
# CircuitPython AnalogIn Demo
import time
import board
from analogio import AnalogIn
analog_in = AnalogIn(board.A1)
def get_voltage(pin):
return (pin.value * 3.3) / 65536
while True:
print((get_voltage(analog_in),))
time.sleep(0.1)
The article I did on Arduino is here Qiita https://qiita.com/hiRina/items/b8756988210f7d2455e8
The following code succeeded in doing this with Ciurcuit Python
main.py
#-------------------------------------
# Import
#-------------------------------------
import board
import busio
import digitalio
from digitalio import DigitalInOut, Direction, Pull
import time
#-------------------------------------
# VAL
#-------------------------------------
t=0.01
#-------------------------------------
# PIN
#-------------------------------------
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
#-------------------------------------
ADC = DigitalInOut(board.D0)
ADC.direction = Direction.OUTPUT
#-------------------------------------
cs=digitalio.DigitalInOut(board.D7)
cs.direction=digitalio.Direction.OUTPUT
cs.value=True
#-------------------------------------
# SPI
#-------------------------------------
spi = busio.SPI(board.SCK, MOSI=board.MOSI)
while not spi.try_lock():
pass
spi.configure(baudrate=10000000, phase=0, polarity=0)
#-------------------------------------
# loop
#-------------------------------------
while True:
#--------------------------
led.value = False
ADC.value = True
cs.value = False
spi.write(bytes([0x3F,0xFF]))
cs.value = True
ADC.value = False
time.sleep(t)
#--------------------------
ADC.value = True
cs.value = False
spi.write(bytes([0x30,0x00]))
cs.value = True
ADC.value = False
time.sleep(t)
#--------------------------
led.value = True
ADC.value = True
cs.value = False
spi.write(bytes([0xBF,0xFF]))
cs.value = True
ADC.value = False
time.sleep(t)
#--------------------------
ADC.value = True
cs.value = False
spi.write(bytes([0xB0,0x00]))
cs.value = True
ADC.value = False
time.sleep(t)
HP that adafruit describes about CircuitPython https://learn.adafruit.com/welcome-to-circuitpython
Explanation of CircuitPython https://learn.adafruit.com/circuitpython-essentials
CircuitPython example https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/CircuitPython_Essentials
Recommended Posts