Run CircuitPython on Seeeduino XIAO

Introduction

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

Seeeduino XIAO setup

Seeed's HP has detailed instructions on how to install CircuitPython. https://wiki.seeedstudio.com/Seeeduino-XIAO/ https://wiki.seeedstudio.com/Seeeduino-XIAO-CircuitPython/

seeeduino_xiao.jpg

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 XIAO-reset.gif

Arduino_holder.png

Arduino2.png

Then drop the downloaded file onto this drive and make a copy. Drop.png

When the copy is complete, the drive name will change to CIRCUITPY. CIRCUITPY2.png

If you write a Python program in the Mu editor and save it as main.py on this drive, the program will run automatically. Mu.png

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 ezgif.com-crop.gif

Qiita for reference https://qiita.com/bohebohechan/items/f8bf6d4bbe0f14497a7b

About Mu

The Mu editor is explained in detail below. https://qiita.com/inachi/items/8f61586cd2482987b8d0

Press the "Mode" icon to switch to "Adafruit CircuitPython" mode Mu4.png

Settings to make Mu recognize USB

I get an error message when I press the "serial" icon Mu5.png

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.

Mu3.png

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.

Mu2.png

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)

Output voltage by SPI communication using MCP4922

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)

IMGP4684.JPG

Reference material

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

Run CircuitPython on Seeeduino XIAO
Run Django on PythonAnywhere
Run mysqlclient on Lambda
Run OpenMVG on Mac
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Run Python CGI on CORESERVER
Run unix command on python
Run IPython Notebook on Docker
Run YOLO v3 on AWS v2
Run Jupyter Notebook on windows
Run FreeBSD on Linux + qemu
Run OpenVino on macOS Catalina
Run YOLO v3 on AWS
Run MuJoCo on WSL (2) (also GUI)
Install and run dropbox on Ubuntu 20.04
Preparing to run Flask on EC2
Run Tensorflow natively supported on windows
Run a Linux server on GCP
Run Python on Schedule on AWS Lambda
How to run matplotlib on heroku
Run SwitchBot on Windows 10 with Bleak
Run Matplotlib on a Docker container
Run azure ML on jupyter notebook
Run headless-chrome on a Debian-based image
Run XGBoost on Bash on Ubuntu on Windows
Run TensorFlow2 on a VPS server
Run vmware horizon client on Debian
[Note] Run Django on Amazon Linux 2
Run PartiQL on Dynamodb via boto3
Run Keras on Google Colaboratory TPU
Run docker-compose on Amazon Linux2 on ARM64
Run Yocto on Ubuntu using QEMU.
Run Sesame on Sony's PaSoRi (RCS370)
Periodically run Python on Heroku Scheduler
Run cron on Amazon Linux (set on Linux)