Wio Terminal - Get CircuitPython Working

Wio Terminal - Get CircuitPython Working

Here we show you how to get CircuitPython onto your Wio Terminal. We will also test the code out with some CircuitPython code that we have used in the past to play our theme tune. We also have a tutorial on how to get MicroPython working on the Wio Terminal and Getting started with Arduino IDE on the Wio Terminal

We found out that there was a built in speaker on the Wio Terminal so we decided we will use some circuitPython code we wrote in another video, where we challenged ourselves to play our theme tune using a Raspberry Pi Pico, and run it on the Wio Terminal.

We will be doing all this on a Raspberry Pi but of course if you don't have a Raspberry Pi we have got you covered! You can use any other Linux Distribution, Windows or Mac etc... If you are using a different setup to us then the process will be similar but you may need to tweak a few of the steps a little to fit with your setup. We only use a Raspberry Pi because we know it is very cheap and accessible.

Firstly we will plug the wio terminal in and put it into bootloader mode. To do that we simply flick the switch on the side to the middle to turn the device on, then if we flick that switch to the left two times quickly you will put it in bootloader mode. This process is shown at 1:37 in the video.

As we are using a Raspberry Pi when we have done this a message pops up on our desktop telling use a removable medium has been inserted. We also did the same thing on a Mac and after flicking the switch two times a disk appeared on the desktop - a mass storage device - named Arduino and in finder the same thing appeared on the side menu bar. This is where we will drag or put our UF2 file once we have gotten hold of it.

The next step in our process is to get the CircuitPython UF2 firmware and put it onto the Wio Terminal. To do this you would need to open the Wio Terminal that has been mounted onto your computer as a mass storage device. You will need to go to https://circuitpython.org then to downloads and search for Wio Terminal, when it appears select the device and press DOWNLOAD .UF2 NOW. At the time of writing it can be found here https://circuitpython.org/board/seeeduino_wio_terminal.

Navigate to the file you have just downloaded - most likely to be found in downloads - then drag or put the .UF2 file onto your mass storage device (the Wio terminal).

Once you have done this the mass storage device will most likely rename itself to CIRCUITPY. It may not rename it's self and you may need to reset the device.

If you look on your Wio Terminal there should be the little CircuitPy snake in the corner and some text.

You can get hold of the circuitPython code we are going to use original here at our github repo or use the code below which has the GP2 switched out for BUZZER.

import time
import board
import pwmio

note_freq = {
  "A4": 440,
  "C5": 523,
  "D5": 587,
  "E5": 659,
  "R": 100
}

speaker = pwmio.PWMOut(board.BUZZER, frequency=440, duty_cycle=int(35565/2), variable_frequency=True)

tune = [["D5", 0.5], ["C5", 0.5], ["D5", 0.5], ["R", 0.5], ["D5", 0.5], ["C5", 0.5], ["D5", 0.5],
         ["R", 0.5], ["D5", 0.5], ["C5", 0.5], ["A4", 0.5], ["C5", 0.5], ["E5", 0.5], ["C5", 0.5], ["D5", 2]]

def play_note(note_name, duration):
    frequency = note_freq[note_name]
    if note_name == "R":
        speaker.duty_cycle=int(0)
    else:
        speaker.duty_cycle=int(35565/2)
    speaker.frequency=frequency
    time.sleep(duration)
    speaker.duty_cycle=0

for note in tune:
    play_note(note[0], note[1])

You can either save this code to your device, git clone it or just copy and paste the code. Choose any text editor of your choice, and paste in your code, then save your code directly onto the device now named CIRCUITPY and name it code.py. This means the code will run straight away after you turn on you circuitPython device.

When we first ran the code there was an error displayed on the Wio Terminal. The error here is that we don't know which pin the speaker is connected to inside the device so we needed to fix this.

We used Thonny on the Raspberry Pi because it has a REPL section at the bottom - where we can directly access and talk to the device. We are going to find out which GPIO pin relates to the speaker or Buzzer. To find out what pin the buzzer is we imported board typed board. then hit the tab key which brought up a list of properties.

import board
board.

This is really handy and we use it a lot to find out about properties and methods when developing. Sometimes we find things we didn't expect and have a little experiment. We found the names of all the onboard components so we knew how to address our buzzer.

board.BUZZER

We then went into the CircuitPython code and changed board.GP2 to board.BUZZER and this made our CircuitPython code run seamlessly and played our theme tune.

We have used many MicroControllers. Before the Raspberry Pi Picos came out we would code on a MicroController in Arduino. After the Raspberry Pi Pico came out we started programming in MicroPython and CircuitPython and C occasionally.

We have tried both MicroPython and CircuitPython and have found it took a lot of effort to get the Wio Terminal to work using MicroPython but with CircuitPython and using random code it was a lot easier and straight forward. Moving forward we would use CircuitPython on the Wio Terminal.

We loved the CircuitPython output on the screen and it's encouraging our randomly picked code worked right away. This wasn't the case with MicroPython on the Wio Terminal as you can find out in our how to get MicroPython working on the Wio Terminal article.