CASP supports building and running CASP models with Python scripts on any CASP supported target. This feature allows developing models programmatically in Python and deploying them on the target with highly efficient and production ready code. This example project shows a simple Python script to blink an on-board LED of the target micro-controller board.
Pre-Requisites
- Target Board (see below section for list of supported boards in the example Python code)
- CASP software is properly installed and functional.
- CASP Python libraries are installed.
- Target BSPs are installed.
Model Details
The Python code implements the logic similar to this example. It supports multiple target boards such as Arduino Uno R3/R4,/R4 WiFi, Raspberry Pi Pico, Raspberry Pi PicoW, Raspberry Pi Pico2, Raspberry Pi Pico2W, Vega Aries-V2, Vega Aries-V3, Vega Aries Eco.
Procedure
- Ensure the micro-controller board is connected to the computer through USB serial.
- Start CASP and open the project from ‘examples/test_examples’ directory. It is also available for download at this link.
- Before running the Python script file, serial port to which to board is connected has to be known. CASP provides a Python command to list out serial ports. Open terminal and type ‘python’ to launch Python interpreter. Type following commands to know available serial ports.
import casp
casp.Init()
casp.SerialPorts()
exit()

In the above image the target board is connected to COM35.
- Now, close the existing terminal and open a new terminal in the folder where the python script file is located.
- Type python (or python3) followed by the <python file name> and <arguments>
- Arguments list:
- target board name (choose one of these board names): uno3, uno4, uno4w, pico, picow, pico2, pico2w, aries2, aries3, arieseco
- serial port to which the board is connected: eg. COM3, ttyUSB0 etc.
- variable blink frequency: True or False
- Example:
> python led_blink_arduino_pico_aries.py uno3 COM3 False #programs Arduino Uno R3 board connected to COM3 (Windows PC) with a constant frequency LED blink model
OR
> python led_blink_arduino_pico_aries.py pico COM4 True #programs Raspberry Pi Pico board connected to COM4 (of Windows PC) with a variable frequency (based on ADC value) LED blink model
OR
> python led_blink_arduino_pico_aries.py arieseco COM5 True #programs Vega Aries Eco board connected to COM5 (of Windows computer) with a variable frequency (based on ADC value) LED blink model
- The above command creates the blink model as per the script and programs the target board. Below is the screen short of the above command. Please go through the script file to know how the model is created.

