ElectronicsIoT HardwaresMicrocontrollersProgrammingTutorials/DIY

CircuitPython on Wio Terminal

Introduction

CircuitPython is a lightweight programming language based on Python, designed for microcontrollers. The Wio Terminal by Seeed Studio is a versatile embedded device that supports CircuitPython, making it an excellent choice for IoT, ML, and sensor-based applications. This guide provides an in-depth look at installing, configuring, and using CircuitPython on the Wio Terminal.

Overview of Wio Terminal

1. Hardware Specifications

Wio Terminal is powered by the ATSAMD51P19 microcontroller, a powerful ARM Cortex-M4F chip running at 120MHz, with the following features:

  • Memory & Storage:
    • 4MB External Flash
    • 192KB RAM
    • MicroSD card slot for external storage
  • Display:
    • 2.4” LCD screen (320×240 resolution, IPS)
  • Connectivity:
    • Built-in Wi-Fi and Bluetooth (via Realtek RTL8720DN)
    • USB-C connection
    • UART, SPI, I2C for external communication
  • Built-in Sensors & Modules:
    • Accelerometer (LIS3DHTR)
    • Microphone
    • Light sensor
    • Buzzer
    • IR Emitter
    • Real-Time Clock (RTC)
  • Expandable Features:
    • Grove connectors for easy sensor and peripheral integration
    • Compatible with Raspberry Pi HATs via a 40-pin GPIO expansion

2. Why Use CircuitPython on Wio Terminal?

CircuitPython is an ideal programming language for Wio Terminal due to the following benefits:

  • Ease of Use: Simply copy your Python code to the device and run it.
  • No Compilation Required: Write code in Python and execute it directly.
  • Extensive Library Support: Adafruit’s CircuitPython libraries support a vast range of sensors and peripherals.
  • Interactive Development: Supports REPL (Read-Eval-Print Loop) for real-time debugging.
  • Low Power Consumption: Optimized for embedded and battery-powered applications.

Installing CircuitPython on Wio Terminal

1. Download CircuitPython Firmware

To install CircuitPython, follow these steps:

  1. Visit the CircuitPython downloads page and search for Wio Terminal.
  2. Download the latest UF2 firmware for Wio Terminal.

2. Flash CircuitPython to Wio Terminal

  1. Connect Wio Terminal to your computer using a USB-C cable.
  2. Enter bootloader mode by holding the BOOT button while pressing RESET once.
  3. The device will appear as a USB drive named WIO-BOOT.
  4. Drag and drop the UF2 firmware file onto the WIO-BOOT drive.
  5. The device will reboot, and a new drive named CIRCUITPY will appear.

Setting Up the Development Environment

1. Install a Code Editor

Use any text editor, but Mu Editor is recommended:

  • Download and install Mu Editor (supports CircuitPython by default).

2. Installing CircuitPython Libraries

  • Download the Adafruit CircuitPython Bundle from Adafruit.
  • Extract the ZIP file and copy necessary libraries into the lib folder on the CIRCUITPY drive.

3. Running Your First CircuitPython Script

Create a file named code.py in the CIRCUITPY drive and enter:

import board
import time
import digitalio

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = not led.value  # Toggle LED
    time.sleep(0.5)

This script blinks the onboard LED every 0.5 seconds.

Using Wio Terminal’s Features with CircuitPython

1. Display (LCD Screen)

import board
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_st7789 import ST7789

display = board.DISPLAY

text_area = label.Label(terminalio.FONT, text="Hello, Wio!", color=0xFFFFFF, x=50, y=60)
display.show(text_area)

while True:
    pass  # Keep the display on

2. Reading Sensor Data

Accelerometer (LIS3DHTR)

import board
import busio
import adafruit_lis3dh

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lis3dh.LIS3DH_I2C(i2c)

while True:
    x, y, z = sensor.acceleration
    print(f"X={x}, Y={y}, Z={z}")
    time.sleep(1)

3. Using the Microphone

import board
import audiobusio
import array

i2s = audiobusio.I2SIn(board.GP0, board.GP1, board.GP2)

while True:
    data = bytearray(100)
    i2s.readinto(data)
    print("Audio Data:", data)

4. Using the Buzzer

import board
import pwmio
import time

buzzer = pwmio.PWMOut(board.GP18, duty_cycle=0, frequency=440, variable_frequency=True)

for freq in [440, 880, 1760]:
    buzzer.frequency = freq
    buzzer.duty_cycle = 32768  # 50% duty cycle
    time.sleep(0.5)
    buzzer.duty_cycle = 0

5. Using Wi-Fi with CircuitPython

Wio Terminal’s RTL8720DN Wi-Fi module is not natively supported by CircuitPython. Instead, you can:

  • Use Arduino firmware to establish Wi-Fi connections.
  • Communicate via UART between Arduino firmware and CircuitPython.

Conclusion

CircuitPython on Wio Terminal is a powerful way to develop embedded applications with ease. With its user-friendly interface, wide library support, and real-time debugging capabilities, CircuitPython unlocks endless possibilities for IoT, ML, and automation projects. Whether you’re a beginner or an experienced developer, Wio Terminal with CircuitPython is a game-changer for embedded development.

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *