Test Example: Python LED Blink

Introduction

CASP supports building and running CASP models using 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.

Model Details

This example is a Python version of Test Example-04 except that the same script can be used for multiple targets based on target name passed as an argument along with Python script file name in the terminal.

Prerequisites

·       CASP Python libraries are installed.

·       Target BSPs are installed.

Procedure

·        Connect the target board to the computer

·        Before running the Python script file it is better to know the serial port to which to board is connected. CASP provides a Python command to list out serial ports. Open a terminal and type following commands to know available serial ports

      > python

      >>> import casp

      >>> casp.Init()

      >>> casp.SerialPorts()

      >>> exit()

    

      In the above image Arduino Uno 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

       - the above command programs Arduino Uno R3 board connected to COM3 (of Windows PC) with a constant frequency LED blink model

     >python led_blink_arduino_pico_aries.py pico COM4 True

       - the above command programs Raspberry Pi Pico board connected to COM4 (of Windows PC) with a variable frequency (based on ADC value) LED blink model

     >python led_blink_arduino_pico_aries.py arieseco COM5 True

       - the above command 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 code and programs the board. Below is the screen short of the above command:

·       Please go through the script file to know how the model is created.