This tutorial will guide you to get started with running MicroPython on the PSoC6™ microcontrollers. Only a few steps keep you away from enjoying the Python programming experience and the possibilities of PSoC6™ microcontrollers.
Let’s get started!
Hardware SetupConnect the USB cable to your computer and the micro USB to the board debugger. All the PSoC6™ boards come with an on-board debugger required for flashing/debugging operations during development
Install MicroPythonIn your computer terminal, type the following commands and follow the instructions. It's always recommended to create a folder mpy-psoc6
to store all installation assets and execute the commands from that folder location.
Download the mpy-psoc6 utility script:
curl -s -L https://raw.githubusercontent.com/infineon/micropython/ports-psoc6-main/tools/psoc6/mpy-psoc6.py > mpy-psoc6.py
Make sure you have a recent version on Python3.x installed and the pip package installer. Then install the following packages:
pip install requests
Finally run the script:
python mpy-psoc6.py quick-start
These commands will download and run the quick-start command of the mpy-psoc6 utility and take care of all the necessary installation steps. Just go through the process by pressing any key when you are asked to do so.
If everything went fine, your PSoC6™ board is now running MicroPython and Arduino IDE for Micropython is now started. If you run into any trouble, please let us know here :)
Select your serial port of your PSoC6™ board by clicking on the connect icon on the menu bar:
As in python, you can use the prompt mode. Simply start typing some python commands:
Let’s try now to run a MicroPython script. As a first example, you will turn on the board LED.
Copy the following code in the editor and click on run.
from machine import Pin
p1 = Pin("P13_7") # LED pin for CY8CPROTO-062-4343W
p1.init(Pin.OUT)
p1.on()
The red LED in the board should be now on
And take this example code to blink your LED:
from machine import Pin
import time
p1 = Pin("P13_7") # LED pin for CY8CPROTO-062-4343W
p1.init(Pin.OUT)
p1.on()
while True:
time.sleep_ms(1000)
p1.toggle()
Using third-party IDEs for filesystem operationsThonnyThonny is a beginner friendly Python IDE. The MicroPython port for PSoC6™ can be detected by the Thonny IDE when the MicroPython(generic)
option is selected at the bottom right corner, as shown. Additionally, the filesystem is detected by the IDE, as shown in the lower left column. Using the GUI, file operations can be carried out, such as creating a new file, adding contents to it and then saving it to the filesystem on the MicroPython device, with a given name.
Find additional information related to the PSoC MicroPython enablement here!
Comments