Create one API with CircuitPython and Wukong 2040 Breakout Board

Create one API with CircuitPython and Wukong 2040 Breakout Board

1. Install CircuitPython

1.1 Download CircuitPython of the stable version, suitable for Raspberry Pi Pico.

CircuitPython link: https://circuitpython.org/board/raspberry_pi_pico/

 

You can choose the pinyin version of Circuitpython to download. It is recommended that students with good English can default to the English version.

 

Downloaded Firmware File

 

1.2 Install firmware

Step 1: Insert USB into the computer, without connection with Pico.

Step 2: Push the button of BOOTSEL of Pico tightly and insert Pico into USB.

 

Step 3: Continue pushing the button of BOOTSEL until the driver RPI-RP2 is shown.

 

Step 4: Copy the firmware of CircuitPython into the driver RPI-RP2.

 

Step 5: After installation, the driver RPI-RP2 disappeared. Then a new driver of CIRCUITRY arises.

 

2. Install the Thonny editor

Install Thonny editor: https://thonny.org/, then click on the version of windows and install it.

 

Install Thonny to the specified location of your computer.

 

3. Make a program of CircuitPython for Pi Pico with Thonny.

Choose the button of the file of view on the platform Thonny.

 

Click on the option of running interpreter of running.

 

Choose CircuitPython (Normal) and port, and click on the button confirmation.

 

After being finished, shown below.

 

Terminal input(‘Hello Pi pico’)

 

Edit print(‘Hello Pi pico’) in the editor of the file and serve this to the computer or the device of CircuitPython.

 

Click on the running button and check out the running result.

 

 

4. Start editing the interface of API.

4.1 Prepare editing

Tool: Use Wukong 2040 Breakout Board and the sensor of Octopus.

 

Target: Drive the GP27 pin to a high level to light up the led light.

 

4.2 Programming content

Build one setled.py file and put it in the catalog of \lib.

CircuitPython
import time
import board
import pwmio
import digitalio
import neopixel_write
import asyncio
from micropython import const

class WuKong2040_octpus_Led:
    def __init__(self):
        self.led = digitalio.DigitalInOut(board.GP26)
        self.led.direction = digitalio.Direction.OUTPUT
    def _set_led(self,status,pin):
        self._pin = pin
        self.led = digitalio.DigitalInOut(self._pin)
        self.led.direction = digitalio.Direction.OUTPUT
        self.status = status
        self.led.value = self.status
    def __deinit__(self):
        self.led.deinit()
        
def set_led(status,pin):
    WuKong2040_octpus_led.__deinit__()
    WuKong2040_octpus_led._set_led(status,pin)

    
WuKong2040_octpus_led = WuKong2040_octpus_Led()

Call the corresponding interface in the code.py file.

CircuitPython
from setled import *

while True:
    set_led(1,board.GP26)
    time.sleep(0.1)
    set_led(0,board.GP26)
    time.sleep(0.5)