CASP supports exchanging data between micro-controller and host computer with very low latency communication. Data received from the micro-controller can then be analyzed with the help of CASP GUI widgets such as plotters, dials, 2D/3D graphs.
This example project demonstrates a model that establishes serial communication between the target board and the host (native) PC. Analog data is acquired from the target board and sent to the host PC for plotting through USB cable. The on-board LED present on the target board is controlled from the host PC.
We will also try to access the data from the micro-controller using a Python script on host computer.
Pre-Requisites
- Arduino Uno R3 board is used for this example. However, any CASP supported micro-controller board can be used.
- Compatible USB cable.
- CASP software is installed along with CASP Python Libraries.
- Arduino BSP is installed.
- The project files are located at CASP installed directory ‘CASP/support/examples/communication/1_serial’. These are also available for download at this link.
Description
Analog data is acquired from the target board and sent to the host PC for plotting and control through USB cable. The on-board LED present on the target board is controlled from the host PC.

CASP Model for Arduino

Procedure
- Connect any sensor to the ADC pin A0 of Arduino Uno for sensing. The on-board LED at pin-13 is used for controlling. Communication is established between Arduino Uno and the host PC through USB serial. Following are the steps to properly program Arduino and native target to achieve above objective.
- Connect Arduino Uno to the host PC via a USB cable.
- Note the serial port number to which the board is connected to the host PC, from the host operating system.
- Open Home->Simulation->Setup Simulation Parameters menu item. Under TargetHW->General tabs set ‘Target Programmer Port’ parameter to the serial port to which the board is connected.
- Run CASP and open the project ‘CASP/support/examples/communication/1_serial/target_model/target_model.prj’ from CASP installed directory.
- Click Run button to build the model and program the board.
CASP Model that runs on Host Computer

Procedure
- Run CASP and open the project ‘CASP/support/examples/communication/1_serial/native_model/native_model.prj’ from CASP installed directory.
- Open the ‘native.wsp’ workspace file. Double click on the ‘Serial SimPanel’ block and set ‘Serial Port Settings->Serial Port’ parameter to the serial port to which the board is connected as shown in below figure.

- Click Run button to build the model and start simulation. A simulation panel window should open and communicate with the board. A screen shot is shown below.

Python Script
The Python script that plots the data from the Arduino board is shown below. The script file is available in the project directory. Within the script, change the serial port in the method ‘udio.ConnectSerial()’ to which the board is connected and run the script from Python terminal.
#import CASP UDIO module.
import casp_udio as udio
#initialize CASP GPIO client process on host computer.
udio.Init()
#display available serial ports (used to identify the serial port to which the board is connected).
udio.SerialPorts()
#starts communicating with the target board using GPIO protocol on COM35. Change the serial port as per your setup. The last two arguments (4, 4) represent UDI and UDO sizes respectively.
udio.ConnectSerial("COM35", 115200, True, 1, 4, 4)
#reads UDI 32-bit integer value at index-0. This value represents ADC value in the above target model.
udio.ReadI(0)
#writes UDO 32-bit float value at index-0. This value represents LED control in the above target model.
udio.WriteI(0, 1)
